Skip to content

feat!: The HasTappableComponents mixin is no longer needed#2450

Merged
spydon merged 28 commits into
mainfrom
spydon/deprecate-hastappablecomponents
Apr 2, 2023
Merged

feat!: The HasTappableComponents mixin is no longer needed#2450
spydon merged 28 commits into
mainfrom
spydon/deprecate-hastappablecomponents

Conversation

@spydon
Copy link
Copy Markdown
Member

@spydon spydon commented Mar 30, 2023

Description

This PR is the second in a series of refactors that aim to simplify event handling in Flame. The approach is as follows:

  • Added the MultiTapDispatcher component, which contains the logic that used to be within the HasTappableComponents mixin. This component is internal; it mounts to a FlameGame directly, and ensures that it is a singleton.
  • Whenever any TapCallbacks component is added to a game, it automatically adds the MultiTapDispatcher component (unless there is already one), which in turn registers a tap gesture detector with GestureDetectorBuilder and rebuilds the game widget.

The end result is that now in order to make a component tappable you only need to add the TapCallbacks mixin to that component, everything else will be handled by the framework.

Consequently, the HasTappableComponents mixin is now empty and marked as deprecated.

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.

Migration instructions

The HasTappableComponents mixin is now empty & deprecated. If your game used this mixin overriding its methods onTapDown, onTapUp, etc -- then they will no longer work. If you want to receive tap events at the top level of the game, then simply add a TapCallbacks component to the top level of the game.

Related Issues

WIP for #1733

@spydon spydon changed the title feat!: HasTappableComponents mixin is no longer needed feat!: The HasTappableComponents mixin is no longer needed Mar 30, 2023
@spydon spydon requested review from a team and st-pasha March 30, 2023 17:54
Comment thread packages/flame/test/game/mixins/has_tappables_test.dart
Copy link
Copy Markdown
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

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

Great job 🔥! Overall LGTM, just left a couple of simple comments!

Comment thread doc/flame/inputs/tap_events.md Outdated
Comment thread doc/flame/inputs/tap_events.md Outdated
Comment thread packages/flame/example/lib/main.dart Outdated
Comment thread packages/flame/test/events/component_mixins/drag_callbacks_test.dart Outdated
Copy link
Copy Markdown
Member

@erickzanardo erickzanardo left a comment

Choose a reason for hiding this comment

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

LGTM awesome job!!!

@spydon spydon enabled auto-merge (squash) April 2, 2023 16:30
@spydon spydon merged commit b5bdf4e into main Apr 2, 2023
@spydon spydon deleted the spydon/deprecate-hastappablecomponents branch April 2, 2023 16:52
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.

3 participants