Skip to content

refactor!: Migrate Force Press events to new API - #3986

Open
luanpotter wants to merge 1 commit into
mainfrom
luan.force-press
Open

refactor!: Migrate Force Press events to new API#3986
luanpotter wants to merge 1 commit into
mainfrom
luan.force-press

Conversation

@luanpotter

@luanpotter luanpotter commented Aug 7, 2026

Copy link
Copy Markdown
Member

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

  • I have followed the Contributor Guide when preparing my PR.
  • I have updated/added tests for ALL new/updated/fixed functionality.
  • I have updated/added relevant documentation in docs and added dartdoc comments with ///.
  • I have updated/added relevant examples in examples or docs.

Breaking Change?

  • Yes, this PR is a breaking change.
  • No, this PR is not a breaking change.

@luanpotter
luanpotter marked this pull request as ready for review August 7, 2026 04:34
@luanpotter
luanpotter requested a lite review from Copilot August 7, 2026 04:34

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 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 ForcePressDetector and ForcePressInfo (and their GameWidget recognizer wiring) from the old gestures detector system.
  • Added ForcePressCallbacks, ForcePressDispatcher, and ForcePressEvent to 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.

Comment on lines 265 to 269
if (component is TapCallbacks ||
component is DragCallbacks ||
component is DoubleTapCallbacks ||
component is ForcePressCallbacks ||
component is ScaleCallbacks ||

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

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

@luanpotter
luanpotter requested a review from spydon August 7, 2026 04:55

@spydon spydon left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we should just drop this instead

@luanpotter

Copy link
Copy Markdown
Member Author

@spydon I was over the fence, but that settles it then, let me just drop

@adario

adario commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

(Apologies to intervene like this: on iOS, nowadays the UITouch.force property is used only on iPad by some drawing apps, since the Apple Pencil supports it... honestly, I've not seen the property used on iPhone for several years now.)

@luanpotter

Copy link
Copy Markdown
Member Author

That's great context @adario , thanks for providing!

I opened an alternative to just remove it, it can still be easily used by wrapping the game with your own flutter gesture detector, so I think this is totally acceptable

#3989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants