mirror of
				https://github.com/flame-engine/flame.git
				synced 2025-10-31 17:06:50 +08:00 
			
		
		
		
	docs: Remove references to Tappable and Draggable (#2912)
We still had some references to `Tappable` and `Draggable`, this PR removes them and removes a superfluous test for `TapCallbacks`. --------- Co-authored-by: jonathan <sharyari@gmail.com>
This commit is contained in:
		| @ -201,7 +201,8 @@ MD044: | |||||||
|   html_elements: true |   html_elements: true | ||||||
|  |  | ||||||
| # MD045/no-alt-text - Images should have alternate text (alt text) | # MD045/no-alt-text - Images should have alternate text (alt text) | ||||||
| MD045: true | # TODO: Activate this with #2913  | ||||||
|  | MD045: false | ||||||
|  |  | ||||||
| # MD046/code-block-style - Code block style | # MD046/code-block-style - Code block style | ||||||
| MD046: | MD046: | ||||||
|  | |||||||
| @ -105,12 +105,12 @@ In the following example we first initialize the component with priority 1, and | |||||||
| user taps the component we change its priority to 2: | user taps the component we change its priority to 2: | ||||||
|  |  | ||||||
| ```dart | ```dart | ||||||
| class MyComponent extends PositionComponent with Tappable { | class MyComponent extends PositionComponent with TapCallbacks { | ||||||
|  |  | ||||||
|   MyComponent() : super(priority: 1); |   MyComponent() : super(priority: 1); | ||||||
|  |  | ||||||
|   @override |   @override | ||||||
|   void onTap() { |   void onTapDown(TapDownEvent event) { | ||||||
|     priority = 2; |     priority = 2; | ||||||
|   } |   } | ||||||
| } | } | ||||||
| @ -818,8 +818,8 @@ robot.animationTickers?[RobotState.idle]?.onFrame = (currentIndex) { | |||||||
| Example: | Example: | ||||||
|  |  | ||||||
| ```dart | ```dart | ||||||
| class ButtonComponent extends SpriteGroupComponent<ButtonState> | class PlayerComponent extends SpriteGroupComponent<ButtonState> | ||||||
|     with HasGameRef<SpriteGroupExample>, Tappable { |     with HasGameReference<SpriteGroupExample>, TapCallbacks { | ||||||
|   @override |   @override | ||||||
|   Future<void>? onLoad() async { |   Future<void>? onLoad() async { | ||||||
|     final pressedSprite = await gameRef.loadSprite(/* omitted */); |     final pressedSprite = await gameRef.loadSprite(/* omitted */); | ||||||
|  | |||||||
| @ -3,7 +3,7 @@ import 'package:flame/collisions.dart'; | |||||||
| import 'package:flame/components.dart'; | import 'package:flame/components.dart'; | ||||||
| import 'package:flame/effects.dart'; | import 'package:flame/effects.dart'; | ||||||
| import 'package:flame/game.dart'; | import 'package:flame/game.dart'; | ||||||
| import 'package:flutter/material.dart' hide Image, Draggable; | import 'package:flutter/material.dart' hide Image; | ||||||
|  |  | ||||||
| class CollisionDetectionGame extends FlameGame with HasCollisionDetection { | class CollisionDetectionGame extends FlameGame with HasCollisionDetection { | ||||||
|   @override |   @override | ||||||
|  | |||||||
| @ -76,7 +76,7 @@ class MyGame extends FlameGame with KeyboardEvents { | |||||||
|  |  | ||||||
| To receive keyboard events directly in components, there is the mixin `KeyboardHandler`. | To receive keyboard events directly in components, there is the mixin `KeyboardHandler`. | ||||||
|  |  | ||||||
| Similarly to `Tappable` and `Draggable`, `KeyboardHandler` can be mixed into any subclass of | Similarly to `TapCallbacks` and `DragCallbacks`, `KeyboardHandler` can be mixed into any subclass of | ||||||
| `Component`. | `Component`. | ||||||
|  |  | ||||||
| KeyboardHandlers must only be added to games that are mixed with `HasKeyboardHandlerComponents`. | KeyboardHandlers must only be added to games that are mixed with `HasKeyboardHandlerComponents`. | ||||||
|  | |||||||
| @ -58,7 +58,7 @@ Every component that received an `onTapDown` event will eventually receive eithe | |||||||
| ### onLongTapDown | ### onLongTapDown | ||||||
|  |  | ||||||
| If the user holds their finger down for some time (as configured by the `.longTapDelay` property | If the user holds their finger down for some time (as configured by the `.longTapDelay` property | ||||||
| in `HasTappableComponents`), the "long tap" will be generated. This event invokes the | in `MultiTapDispatcher`), "long tap" will be triggered. This event invokes the | ||||||
| `void onLongTapDown(TapDownEvent)` handler on those components that previously received the | `void onLongTapDown(TapDownEvent)` handler on those components that previously received the | ||||||
| `onTapDown` event. | `onTapDown` event. | ||||||
|  |  | ||||||
|  | |||||||
| @ -23,7 +23,7 @@ import 'package:flutter/material.dart'; | |||||||
| void addInputStories(Dashbook dashbook) { | void addInputStories(Dashbook dashbook) { | ||||||
|   dashbook.storiesOf('Input') |   dashbook.storiesOf('Input') | ||||||
|     ..add( |     ..add( | ||||||
|       'Tappables', |       'TapCallbacks', | ||||||
|       (_) => GameWidget(game: TapCallbacksExample()), |       (_) => GameWidget(game: TapCallbacksExample()), | ||||||
|       codeLink: baseLink('input/tap_callbacks_example.dart'), |       codeLink: baseLink('input/tap_callbacks_example.dart'), | ||||||
|       info: TapCallbacksExample.description, |       info: TapCallbacksExample.description, | ||||||
|  | |||||||
| @ -6,8 +6,8 @@ import 'package:flutter/material.dart'; | |||||||
|  |  | ||||||
| class TapCallbacksExample extends FlameGame { | class TapCallbacksExample extends FlameGame { | ||||||
|   static const String description = ''' |   static const String description = ''' | ||||||
|     In this example we show the `Tappable` mixin functionality. You can add the |     In this example we show the `TapCallbacks` mixin functionality. You can add | ||||||
|     `Tappable` mixin to any `PositionComponent`.\n\n |     the `TapCallbacks` mixin to any `PositionComponent`.\n\n | ||||||
|     Tap the squares to see them change their angle around their anchor. |     Tap the squares to see them change their angle around their anchor. | ||||||
|   '''; |   '''; | ||||||
|  |  | ||||||
|  | |||||||
| @ -10,8 +10,6 @@ import 'package:meta/meta.dart'; | |||||||
| /// In addition to adding this mixin, the component must also implement the | /// In addition to adding this mixin, the component must also implement the | ||||||
| /// [containsLocalPoint] method -- the component will only be considered | /// [containsLocalPoint] method -- the component will only be considered | ||||||
| /// "tapped" if the point where the tap has occurred is inside the component. | /// "tapped" if the point where the tap has occurred is inside the component. | ||||||
| /// |  | ||||||
| /// This mixin is the replacement of the Tappable mixin. |  | ||||||
| mixin TapCallbacks on Component { | mixin TapCallbacks on Component { | ||||||
|   void onTapDown(TapDownEvent event) {} |   void onTapDown(TapDownEvent event) {} | ||||||
|   void onLongTapDown(TapDownEvent event) {} |   void onLongTapDown(TapDownEvent event) {} | ||||||
|  | |||||||
| @ -1,283 +0,0 @@ | |||||||
| import 'package:flame/components.dart'; |  | ||||||
| import 'package:flame/events.dart'; |  | ||||||
| import 'package:flame/game.dart'; |  | ||||||
| import 'package:flame/src/events/flame_game_mixins/multi_tap_dispatcher.dart'; |  | ||||||
| import 'package:flame_test/flame_test.dart'; |  | ||||||
| import 'package:flutter/gestures.dart'; |  | ||||||
| import 'package:test/test.dart'; |  | ||||||
|  |  | ||||||
| void main() { |  | ||||||
|   final withTappables = FlameTester(_GameHasTappables.new); |  | ||||||
|  |  | ||||||
|   group('Tappable', () { |  | ||||||
|     testWithGame<_GameHasTappables>( |  | ||||||
|       'make sure they can be added to game with HasTappables', |  | ||||||
|       _GameHasTappables.new, |  | ||||||
|       (game) async { |  | ||||||
|         await game.add(_TappableComponent()); |  | ||||||
|         await game.ready(); |  | ||||||
|       }, |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     testWithGame<_GameHasTappables>( |  | ||||||
|       'can be Tapped Down', |  | ||||||
|       _GameHasTappables.new, |  | ||||||
|       (game) async { |  | ||||||
|         final component = _TappableComponent() |  | ||||||
|           ..x = 10 |  | ||||||
|           ..y = 10 |  | ||||||
|           ..width = 10 |  | ||||||
|           ..height = 10; |  | ||||||
|  |  | ||||||
|         await game.ensureAdd(component); |  | ||||||
|         final tapDispatcher = game.firstChild<MultiTapDispatcher>()!; |  | ||||||
|  |  | ||||||
|         tapDispatcher.handleTapDown( |  | ||||||
|           1, |  | ||||||
|           TapDownDetails( |  | ||||||
|             kind: PointerDeviceKind.touch, |  | ||||||
|             globalPosition: const Offset(10, 10), |  | ||||||
|             localPosition: const Offset(10, 10), |  | ||||||
|           ), |  | ||||||
|         ); |  | ||||||
|  |  | ||||||
|         expect(component.hasOnTapDown, true); |  | ||||||
|       }, |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     testWithGame<_GameHasTappables>( |  | ||||||
|       'can be Tapped Up', |  | ||||||
|       _GameHasTappables.new, |  | ||||||
|       (game) async { |  | ||||||
|         final component = _TappableComponent() |  | ||||||
|           ..x = 10 |  | ||||||
|           ..y = 10 |  | ||||||
|           ..width = 10 |  | ||||||
|           ..height = 10; |  | ||||||
|  |  | ||||||
|         await game.ensureAdd(component); |  | ||||||
|         final tapDispatcher = game.firstChild<MultiTapDispatcher>()!; |  | ||||||
|  |  | ||||||
|         tapDispatcher |  | ||||||
|           ..handleTapDown( |  | ||||||
|             1, |  | ||||||
|             TapDownDetails( |  | ||||||
|               kind: PointerDeviceKind.touch, |  | ||||||
|               globalPosition: const Offset(10, 10), |  | ||||||
|               localPosition: const Offset(10, 10), |  | ||||||
|             ), |  | ||||||
|           ) |  | ||||||
|           ..handleTapUp( |  | ||||||
|             1, |  | ||||||
|             TapUpDetails( |  | ||||||
|               kind: PointerDeviceKind.touch, |  | ||||||
|               globalPosition: const Offset(10, 10), |  | ||||||
|               localPosition: const Offset(10, 10), |  | ||||||
|             ), |  | ||||||
|           ); |  | ||||||
|  |  | ||||||
|         expect(component.hasOnTapUp, true); |  | ||||||
|       }, |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     testWithGame<_GameHasTappables>( |  | ||||||
|       'can be Tapped Canceled', |  | ||||||
|       _GameHasTappables.new, |  | ||||||
|       (game) async { |  | ||||||
|         final component = _TappableComponent() |  | ||||||
|           ..x = 10 |  | ||||||
|           ..y = 10 |  | ||||||
|           ..width = 10 |  | ||||||
|           ..height = 10; |  | ||||||
|  |  | ||||||
|         await game.ensureAdd(component); |  | ||||||
|         final tapDispatcher = game.firstChild<MultiTapDispatcher>()!; |  | ||||||
|  |  | ||||||
|         tapDispatcher |  | ||||||
|           ..handleTapDown( |  | ||||||
|             1, |  | ||||||
|             TapDownDetails( |  | ||||||
|               kind: PointerDeviceKind.touch, |  | ||||||
|               globalPosition: const Offset(10, 10), |  | ||||||
|               localPosition: const Offset(10, 10), |  | ||||||
|             ), |  | ||||||
|           ) |  | ||||||
|           ..handleTapCancel( |  | ||||||
|             1, |  | ||||||
|           ); |  | ||||||
|  |  | ||||||
|         expect(component.hasOnTapCancel, true); |  | ||||||
|       }, |  | ||||||
|     ); |  | ||||||
|  |  | ||||||
|     testWithGame<_GameHasTappables>( |  | ||||||
|       'can be Long Tapped Down', |  | ||||||
|       _GameHasTappables.new, |  | ||||||
|       (game) async { |  | ||||||
|         final component = _TappableComponent() |  | ||||||
|           ..x = 10 |  | ||||||
|           ..y = 10 |  | ||||||
|           ..width = 10 |  | ||||||
|           ..height = 10; |  | ||||||
|  |  | ||||||
|         await game.ensureAdd(component); |  | ||||||
|         final tapDispatcher = game.firstChild<MultiTapDispatcher>()!; |  | ||||||
|  |  | ||||||
|         tapDispatcher |  | ||||||
|           ..handleTapDown( |  | ||||||
|             1, |  | ||||||
|             TapDownDetails( |  | ||||||
|               kind: PointerDeviceKind.touch, |  | ||||||
|               globalPosition: const Offset(10, 10), |  | ||||||
|               localPosition: const Offset(10, 10), |  | ||||||
|             ), |  | ||||||
|           ) |  | ||||||
|           ..handleLongTapDown( |  | ||||||
|             1, |  | ||||||
|             TapDownDetails( |  | ||||||
|               kind: PointerDeviceKind.touch, |  | ||||||
|               globalPosition: const Offset(10, 10), |  | ||||||
|               localPosition: const Offset(10, 10), |  | ||||||
|             ), |  | ||||||
|           ); |  | ||||||
|  |  | ||||||
|         expect(component.hasOnLongTapDown, isTrue); |  | ||||||
|       }, |  | ||||||
|     ); |  | ||||||
|   }); |  | ||||||
|  |  | ||||||
|   withTappables.testGameWidget( |  | ||||||
|     'tap correctly registered handled event', |  | ||||||
|     setUp: (game, _) async { |  | ||||||
|       final component = _TappableComponent() |  | ||||||
|         ..x = 10 |  | ||||||
|         ..y = 10 |  | ||||||
|         ..width = 10 |  | ||||||
|         ..height = 10; |  | ||||||
|  |  | ||||||
|       await game.ensureAdd(component); |  | ||||||
|     }, |  | ||||||
|     verify: (game, tester) async { |  | ||||||
|       await tester.tapAt(const Offset(10, 10)); |  | ||||||
|       await tester.pump(const Duration(seconds: 1)); |  | ||||||
|  |  | ||||||
|       expect(game.handledOnTapDown, equals(1)); |  | ||||||
|       expect(game.handledOnLongTapDown, equals(0)); |  | ||||||
|       expect(game.handledOnTapUp, equals(1)); |  | ||||||
|       expect(game.handledOnTapCancel, equals(0)); |  | ||||||
|     }, |  | ||||||
|   ); |  | ||||||
|  |  | ||||||
|   withTappables.testGameWidget( |  | ||||||
|     'long tap correctly registered handled event', |  | ||||||
|     setUp: (game, _) async { |  | ||||||
|       final component = _TappableComponent() |  | ||||||
|         ..x = 10 |  | ||||||
|         ..y = 10 |  | ||||||
|         ..width = 10 |  | ||||||
|         ..height = 10; |  | ||||||
|  |  | ||||||
|       await game.ensureAdd(component); |  | ||||||
|     }, |  | ||||||
|     verify: (game, tester) async { |  | ||||||
|       await tester.longPressAt(const Offset(10, 10)); |  | ||||||
|       await tester.pump(const Duration(seconds: 1)); |  | ||||||
|       expect(game.handledOnTapDown, equals(1)); |  | ||||||
|       expect(game.handledOnLongTapDown, equals(1)); |  | ||||||
|       expect(game.handledOnTapUp, equals(1)); |  | ||||||
|       expect(game.handledOnTapCancel, equals(0)); |  | ||||||
|     }, |  | ||||||
|   ); |  | ||||||
|  |  | ||||||
|   withTappables.testGameWidget( |  | ||||||
|     'tap outside of component is not registered as handled', |  | ||||||
|     setUp: (game, _) async { |  | ||||||
|       final component = _TappableComponent() |  | ||||||
|         ..x = 10 |  | ||||||
|         ..y = 10 |  | ||||||
|         ..width = 10 |  | ||||||
|         ..height = 10; |  | ||||||
|  |  | ||||||
|       await game.ensureAdd(component); |  | ||||||
|     }, |  | ||||||
|     verify: (game, tester) async { |  | ||||||
|       await tester.tapAt(const Offset(200, 200)); |  | ||||||
|       await tester.pump(const Duration(seconds: 1)); |  | ||||||
|       expect(game.handledOnTapDown, equals(0)); |  | ||||||
|       expect(game.handledOnLongTapDown, equals(0)); |  | ||||||
|       expect(game.handledOnTapUp, equals(0)); |  | ||||||
|       expect(game.handledOnTapCancel, equals(0)); |  | ||||||
|     }, |  | ||||||
|   ); |  | ||||||
| } |  | ||||||
|  |  | ||||||
| class _TappableComponent extends PositionComponent with TapCallbacks { |  | ||||||
|   bool hasOnTapUp = false; |  | ||||||
|   bool hasOnTapDown = false; |  | ||||||
|   bool hasOnTapCancel = false; |  | ||||||
|   bool hasOnLongTapDown = false; |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapDown(TapDownEvent info) { |  | ||||||
|     info.handled = true; |  | ||||||
|     info.continuePropagation = true; |  | ||||||
|     hasOnTapDown = true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapUp(TapUpEvent info) { |  | ||||||
|     info.handled = true; |  | ||||||
|     info.continuePropagation = true; |  | ||||||
|     hasOnTapUp = true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapCancel(TapCancelEvent info) { |  | ||||||
|     info.continuePropagation = true; |  | ||||||
|     hasOnTapCancel = true; |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onLongTapDown(TapDownEvent info) { |  | ||||||
|     info.handled = true; |  | ||||||
|     info.continuePropagation = true; |  | ||||||
|     hasOnLongTapDown = true; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
|  |  | ||||||
| class _GameHasTappables extends FlameGame with TapCallbacks { |  | ||||||
|   int handledOnTapDown = 0; |  | ||||||
|   int handledOnLongTapDown = 0; |  | ||||||
|   int handledOnTapUp = 0; |  | ||||||
|   int handledOnTapCancel = 0; |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapDown(TapDownEvent info) { |  | ||||||
|     super.onTapDown(info); |  | ||||||
|     if (info.handled) { |  | ||||||
|       handledOnTapDown++; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onLongTapDown(TapDownEvent info) { |  | ||||||
|     super.onLongTapDown(info); |  | ||||||
|     if (info.handled) { |  | ||||||
|       handledOnLongTapDown++; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapUp(TapUpEvent info) { |  | ||||||
|     super.onTapUp(info); |  | ||||||
|     if (info.handled) { |  | ||||||
|       handledOnTapUp++; |  | ||||||
|     } |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @override |  | ||||||
|   void onTapCancel(_) { |  | ||||||
|     super.onTapCancel(_); |  | ||||||
|     handledOnTapCancel++; |  | ||||||
|   } |  | ||||||
| } |  | ||||||
| @ -56,7 +56,7 @@ void main() { | |||||||
|       }); |       }); | ||||||
|  |  | ||||||
|       testWithFlameGame( |       testWithFlameGame( | ||||||
|         'Can Add with Tappable', |         'Can Add with TapCallbacks', | ||||||
|         (game) async { |         (game) async { | ||||||
|           final child = _RiveComponentWithTappable( |           final child = _RiveComponentWithTappable( | ||||||
|             artboard: await loadArtboard(riveFile), |             artboard: await loadArtboard(riveFile), | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Lukas Klingsbo
					Lukas Klingsbo