refactor!: Migrate Force Press events to new API - #3986
Conversation
There was a problem hiding this comment.
Pull request overview
This PR migrates Force Press input handling from the deprecated game-level detector API (ForcePressDetector / ForcePressInfo) to the component-based callbacks/dispatcher event system, aligning it with the rest of Flame’s input architecture and documenting the breaking change.
Changes:
- Removed
ForcePressDetectorandForcePressInfo(and their GameWidget recognizer wiring) from the old gestures detector system. - Added
ForcePressCallbacks,ForcePressDispatcher, andForcePressEventto route force press gestures through the component tree. - Replaced/added tests and updated migration + input documentation for the new Force Press API.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/flame/test/gestures/detectors_test.dart | Removes legacy ForcePressDetector tests tied to the old API. |
| packages/flame/test/events/component_mixins/force_press_callbacks_test.dart | Adds new tests for component-based force press dispatch, propagation, and lifecycle. |
| packages/flame/lib/src/gestures/events.dart | Removes legacy ForcePressInfo event wrapper. |
| packages/flame/lib/src/gestures/detectors.dart | Removes legacy ForcePressDetector mixin and handlers. |
| packages/flame/lib/src/game/game_widget/gesture_detector_builder.dart | Removes old Force Press recognizer registration for ForcePressDetector. |
| packages/flame/lib/src/game/flame_game.dart | Updates hit-testing detection to include ForcePressCallbacks components. |
| packages/flame/lib/src/events/messages/force_press_event.dart | Introduces ForcePressEvent as the new force press position event. |
| packages/flame/lib/src/events/dispatchers/force_press_dispatcher.dart | Introduces dispatcher that registers the recognizer and routes events to callbacks. |
| packages/flame/lib/src/events/callbacks/force_press_callbacks.dart | Introduces ForcePressCallbacks mixin and isForcePressed state. |
| packages/flame/lib/events.dart | Exports the new Force Press callbacks, dispatcher, and event; removes legacy exports. |
| packages/flame_test/lib/src/mock_force_press_events.dart | Adds a test helper for constructing ForcePressEvent. |
| packages/flame_test/lib/flame_test.dart | Re-exports the new force press mock helper. |
| doc/flame/migration.md | Documents the breaking migration from detector/info to callbacks/event. |
| doc/flame/inputs/tap_events.md | Documents ForcePressCallbacks usage and behavior. |
| doc/flame/inputs/gesture_input.md | Removes ForcePressDetector from the detector list. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (component is TapCallbacks || | ||
| component is DragCallbacks || | ||
| component is DoubleTapCallbacks || | ||
| component is ForcePressCallbacks || | ||
| component is ScaleCallbacks || |
There was a problem hiding this comment.
this is wrong, it does work at game level, because componentsAtPoint includes the game itself
that being said there are other new detectors missing here, which is indeed a bug, and this is not tested, but it is not tested for other detectors either
so I will followup with a broad approach here, but not part of this PR
spydon
left a comment
There was a problem hiding this comment.
I think we should just drop this instead
|
@spydon I was over the fence, but that settles it then, let me just drop |
|
(Apologies to intervene like this: on iOS, nowadays the |
Description
Migrate Force Press events to new API, removing the old one.
This is basically a 1:1 migration to the new system.
NOTE: this is a super edge-case API that we could also just consider removing it - apparently apple while has not officially killed it has effectively done so, and never been really a thing on Android. However, Flutter still supports it first class (and not deprecated), so I just migrated as is as the effort is low and won't impact our migration. We can still consider dropping later on as part of v2.
Checklist
docsand added dartdoc comments with///.examplesordocs.Breaking Change?