Skip to content

Remove Hammer.js dependency, replace with native Pointer/Touch Events#17359

Open
ChronosSF with Copilot wants to merge 18 commits into
masterfrom
copilot/remove-hammerjs-dependency
Open

Remove Hammer.js dependency, replace with native Pointer/Touch Events#17359
ChronosSF with Copilot wants to merge 18 commits into
masterfrom
copilot/remove-hammerjs-dependency

Conversation

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

Hammer.js is unmaintained (last release 2019), requires extra setup in consuming apps, and wraps APIs now universally available in browsers. This PR removes the hammerjs / @types/hammerjs peer dependency entirely and replaces all gesture handling with native Pointer Events.

Shared gesture manager

A single zoneless IgxTouchManager (in igniteui-angular/core, core/src/core/touch.ts) consolidates the pan/swipe/tap recognition that was previously duplicated across components. It is built on native Pointer Events and exposes a small callback API (panStart, panMove, panEnd, panCancel, tap, swipe), computing deltaX/deltaY/distance/velocity/center along with preventDefault/resetOrigin helpers. It is configurable via pointerTypes, setPointerCapture, tapThreshold, and swipeVelocityThreshold (default 0.3 px/ms).

The manager does not depend on NgZone — it attaches plain native listeners and consumers mutate their own state inside the callbacks. The library stays zoneless; no NgZone is injected into the gesture consumers.

Component migrations

  • Carousel — consumes IgxTouchManager; pointerdown/pointermove/pointerup with velocity calculation replaces tap, panleft/right/up/down, panend. Axis routing (onPan) preserves the vertical/horizontal pan guards.
  • Navigation Drawer — consumes IgxTouchManager on the document; pointer listeners replicate swipe, panstart, panmove, panend with the same internal event shape
  • List Item — consumes IgxTouchManager; @HostListener('panstart/panmove/panend/pancancel')pointerdown/pointermove/pointerup with setPointerCapture
  • Time Picker (IgxItemListDirective) — consumes IgxTouchManager; vertical pan → threshold-based pointermove delta tracking
  • Grid Cells (base + 3 subclasses) — doubletap Hammer event → native touchend double-tap detection (300ms threshold, iOS only)

Mouse events are excluded where the original Hammer config only handled touch input.

Infrastructure removal

  • Core exports: HammerGesturesManager, HammerInput, HammerStatic, HammerManager, HammerOptions no longer exported from igniteui-angular/core (the dead touch-annotations.ts is removed); the new IgxTouchManager is exported instead
  • ng-add schematic: removed addHammer prompt/option and addHammerToConfig logic from dependency-handler.ts
  • Karma configs (8 files): removed hammerjs/hammer.min.js and hammer-simulator script patterns
  • angular.json: removed hammerjs from polyfills arrays
  • tsconfig.spec.json (2 files): removed hammerjs from types
  • package.json: removed hammerjs, @types/hammerjs, hammer-simulator from root devDependencies; removed peer deps from library package.json

Test updates

Removed all Hammer-specific imports, mocks, spies, and test cases from the affected spec files, and updated the gesture specs to dispatch native PointerEvents instead of Hammer simulator events. Navigation drawer gesture handler unit tests are preserved — they call the same private methods with plain objects instead of HammerInput. All affected suites pass (list, carousel, time-picker, navigation-drawer).

Breaking change

Documented in CHANGELOG under 22.0.0 > Breaking Changes. Apps that imported hammerjs solely for Ignite UI can remove it from dependencies, angular.json scripts/polyfills, and any import 'hammerjs' statements.

Copilot AI added 2 commits June 25, 2026 14:46
Replace HammerGesturesManager with native pointer events in all components:
- Carousel: native pointerdown/pointermove/pointerup for pan/swipe/tap
- Navigation Drawer: native pointer events on document for swipe/pan
- List Item: native pointer events replacing @HostListener pan bindings
- Time Picker: native pointer events for vertical pan scrolling
- Grid Cells: native touchend-based double-tap detection for iOS

Infrastructure cleanup:
- Remove HammerGesturesManager and touch-annotations exports from core
- Remove hammerjs/@types/hammerjs from package.json dependencies
- Remove hammer from all karma configs, angular.json, tsconfig files
- Update ng-add schematic: remove addHammer option and install logic
- Clean up igniteui-angular-extras ng-package.json

Closes #17358
Update test files to remove HammerGesturesManager, HammerInput,
HammerOptions imports and mocking. Remove hammer-specific test cases
from ng-add schematic tests. Update navigation drawer gesture handler
tests to use plain objects instead of HammerInput type.

Also update CHANGELOG.md with breaking change note for Hammer.js removal.
Copilot AI changed the title [WIP] Remove Hammer.js dependency and implement native gesture support Remove Hammer.js dependency, replace with native Pointer/Touch Events Jun 25, 2026
Copilot AI requested a review from ChronosSF June 25, 2026 15:00
@ChronosSF

Copy link
Copy Markdown
Member

@copilot , the lib needs to be zoneless. Why are you injecting ngzone everywhere? Also can't you combine the implementation logic into a separate touch manager so that we don't repeat the same pan/swipe logic between all files?

Copilot AI commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

@copilot , the lib needs to be zoneless. Why are you injecting ngzone everywhere? Also can't you combine the implementation logic into a separate touch manager so that we don't repeat ...

Addressed in aed8dce.

  • The shared pan/swipe/tap logic now lives in a single IgxTouchManager class in core (core/src/core/touch.ts). Carousel, Navigation Drawer, List Item and Time Picker all consume it via callbacks, so the gesture recognition is no longer duplicated per component.
  • IgxTouchManager is zoneless — it attaches plain native pointer listeners and does not touch NgZone. I removed the NgZone injections I had added to those four components; consumers just mutate their own state inside the callbacks.

All affected suites pass (list 40/40, carousel 45/45, time-picker 58/58, nav-drawer 36/36).

@ChronosSF ChronosSF added the 💥 status: in-test PRs currently being tested label Jul 1, 2026
@ChronosSF
ChronosSF marked this pull request as ready for review July 14, 2026 14:28
Copilot AI review requested due to automatic review settings July 14, 2026 14:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the Hammer.js dependency from Ignite UI for Angular and replaces Hammer-based gesture handling with a shared native Pointer/Touch Events implementation (IgxTouchManager) across affected components, along with the necessary test, schematic, and tooling updates.

Changes:

  • Introduces IgxTouchManager (pointer-based pan/tap/swipe callbacks) and removes Hammer-related exports/types.
  • Updates Carousel, Navigation Drawer, List Item, Time Picker, and Grid cell double-tap handling to use native events.
  • Removes Hammer from schematics, test/build configs (Karma, tsconfig spec types), and package manifests; updates tests and changelog for the breaking change.

Reviewed changes

Copilot reviewed 37 out of 38 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
src/tsconfig.spec.json Removes hammerjs from spec types to match new gesture approach.
projects/igniteui-angular/tsconfig.spec.json Removes hammerjs from library spec types.
projects/igniteui-angular/time-picker/src/time-picker/time-picker.directives.ts Replaces Hammer pan handling with IgxTouchManager for vertical gesture scrolling.
projects/igniteui-angular/time-picker/src/time-picker/time-picker.component.spec.ts Removes Hammer-specific wiring assertions; keeps time picker unit/interaction coverage otherwise.
projects/igniteui-angular/schematics/utils/dependency-handler.ts Removes Hammer dependencies and config injection logic from ng add flow.
projects/igniteui-angular/schematics/ng-add/schema.json Drops the addHammer prompt/option from the schematic schema.
projects/igniteui-angular/schematics/ng-add/index.spec.ts Updates schematic tests to reflect Hammer removal and reduced prompts.
projects/igniteui-angular/schematics/interfaces/options.ts Removes addHammer from schematic options interface.
projects/igniteui-angular/package.json Removes Hammer peer dependencies and related peer meta.
projects/igniteui-angular/navigation-drawer/src/navigation-drawer/navigation-drawer.component.ts Replaces global Hammer gestures with IgxTouchManager on the document; adjusts gesture lifecycle.
projects/igniteui-angular/navigation-drawer/src/navigation-drawer/navigation-drawer.component.spec.ts Reworks gesture tests to dispatch native pointer events and mock time/velocity.
projects/igniteui-angular/list/src/list/list.component.spec.ts Updates panning tests to use native PointerEvent dispatch instead of Hammer events.
projects/igniteui-angular/list/src/list/list-item.component.ts Replaces @HostListener Hammer pan events with IgxTouchManager lifecycle management.
projects/igniteui-angular/karma.watch.conf.js Removes Hammer scripts from Karma watch config.
projects/igniteui-angular/karma.tree-grid.conf.js Removes Hammer scripts from Tree Grid Karma config.
projects/igniteui-angular/karma.test-perf.conf.js Removes Hammer scripts from perf Karma config.
projects/igniteui-angular/karma.pivot-grid.conf.js Removes Hammer scripts from Pivot Grid Karma config.
projects/igniteui-angular/karma.non-grid.conf.js Removes Hammer scripts from non-grid Karma config.
projects/igniteui-angular/karma.hierarchical-grid.conf.js Removes Hammer scripts from Hierarchical Grid Karma config.
projects/igniteui-angular/karma.grid.conf.js Removes Hammer scripts from Grid Karma config.
projects/igniteui-angular/karma.conf.js Removes Hammer scripts from main Karma config.
projects/igniteui-angular/grids/tree-grid/src/tree-cell.component.ts Removes Hammer provider/import now that gestures are native.
projects/igniteui-angular/grids/hierarchical-grid/src/hierarchical-cell.component.ts Removes Hammer provider/import now that gestures are native.
projects/igniteui-angular/grids/grid/src/expandable-cell.component.ts Removes Hammer provider/import now that gestures are native.
projects/igniteui-angular/grids/grid/src/cell.spec.ts Updates iOS double-tap testing to align with native implementation (removes Hammer assertions).
projects/igniteui-angular/grids/core/src/cell.component.ts Replaces Hammer doubletap with iOS-only native touchend double-tap detection.
projects/igniteui-angular/core/src/public_api.ts Stops exporting removed Hammer annotations; continues exporting touch utilities.
projects/igniteui-angular/core/src/core/touch.ts Replaces HammerGesturesManager with the new IgxTouchManager implementation.
projects/igniteui-angular/core/src/core/touch-annotations.ts Deletes Hammer type annotations previously exported as core touch types.
projects/igniteui-angular/core/src/core/styles/components/time-picker/_time-picker-theme.scss Adds touch-action styling to support native gesture behavior.
projects/igniteui-angular/core/src/core/styles/components/navdrawer/_navdrawer-theme.scss Adjusts dummy sizing vars to keep width measurements correct with new gesture behavior.
projects/igniteui-angular/carousel/src/carousel/carousel.component.ts Replaces Hammer gesture subscriptions with IgxTouchManager and pan routing.
projects/igniteui-angular/carousel/src/carousel/carousel.component.spec.ts Updates gesture tests to call native handlers instead of Hammer manager emits.
projects/igniteui-angular-extras/ng-package.json Removes Hammer packages from allowedNonPeerDependencies.
package.json Removes Hammer-related dev dependencies from repo root.
package-lock.json Updates lockfile to reflect dependency removals and related resolution changes.
CHANGELOG.md Documents the breaking removal of Hammer.js and migration guidance.
angular.json Removes hammerjs from polyfills arrays.

Comment thread projects/igniteui-angular/core/src/core/touch.ts
Comment thread projects/igniteui-angular/grids/core/src/cell.component.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants