Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions doc/flame/inputs/gesture_input.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,6 @@ Detectors will be deprecated in the future. Prefer `Callbacks` instead.
```

```text
- VerticalDragDetector
- onVerticalDragDown
- onVerticalDragStart
- onVerticalDragUpdate
- onVerticalDragEnd
- onVerticalDragCancel

- HorizontalDragDetector
- onHorizontalDragDown
- onHorizontalDragStart
- onHorizontalDragUpdate
- onHorizontalDragEnd
- onHorizontalDragCancel

- PanDetector
- onPanDown
- onPanStart
Expand Down
33 changes: 33 additions & 0 deletions doc/flame/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,39 @@ major versions of Flame, together with the steps required to migrate your code.
## Migrating from v1.38.0 to v2.0.0


### `VerticalDragDetector` and `HorizontalDragDetector` removed

Both game-level mixins have been removed, with no direct replacement in Flame.

They existed only to expose Flutter's `VerticalDragGestureRecognizer` and
`HorizontalDragGestureRecognizer`, whose distinguishing feature is not the filtering itself but how
they behave in Flutter's gesture arena: an axis-constrained recognizer yields to a competitor on the
other axis. That matters when a `GameWidget` is nested inside a scrollable, which is a concern of
the widget tree rather than of the game, and it is not something the component-level `DragCallbacks`
can reproduce.

If your game accepts drags on any axis, use `DragCallbacks`, which can be mixed directly into your
game class:

```dart
// Before
class MyGame extends FlameGame with VerticalDragDetector {
@override
void onVerticalDragUpdate(DragUpdateInfo info) { /* ... */ }
}

// After
class MyGame extends FlameGame with DragCallbacks {
@override
void onDragUpdate(DragUpdateEvent event) { /* ... */ }
}
```

If you specifically need the arena behavior, wrap your `GameWidget` in Flutter's own
[`GestureDetector`](https://api.flutter.dev/flutter/widgets/GestureDetector-class.html) and use its
`onVerticalDragUpdate` / `onHorizontalDragUpdate` callbacks.


### `ForcePressDetector` removed

The `ForcePressDetector` mixin and its `ForcePressInfo` event class have been removed, with no
Expand Down
8 changes: 1 addition & 7 deletions packages/flame/lib/events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,7 @@ export 'src/events/multi_drag_scale_recognizer.dart'
export 'src/game/mixins/keyboard.dart'
show HasKeyboardHandlerComponents, KeyboardEvents;
export 'src/gestures/detectors.dart'
show
HorizontalDragDetector,
MouseMovementDetector,
PanDetector,
ScaleDetector,
ScrollDetector,
VerticalDragDetector;
show MouseMovementDetector, PanDetector, ScaleDetector, ScrollDetector;
export 'src/gestures/events.dart'
show
DragDownInfo,
Expand Down
4 changes: 1 addition & 3 deletions packages/flame/lib/src/game/flame_game.dart
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,7 @@ class FlameGame<W extends World> extends ComponentTreeRoot
bool containsEventHandlerAt(Vector2 position) {
// Game-level detector mixins handle events for the entire game surface,
// so any in-bounds point is a hit.
if (this is VerticalDragDetector ||
this is HorizontalDragDetector ||
this is PanDetector ||
if (this is PanDetector ||
this is ScaleDetector ||
this is MultiTapListener ||
this is MultiTouchDragDetector) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,6 @@ class GestureDetectorBuilder {
}

void initializeGestures(Game game) {
if (game is VerticalDragDetector) {
register(
VerticalDragGestureRecognizer.new,
(VerticalDragGestureRecognizer instance) {
instance.onDown = game.handleVerticalDragDown;
instance.onStart = game.handleVerticalDragStart;
instance.onUpdate = game.handleVerticalDragUpdate;
instance.onEnd = game.handleVerticalDragEnd;
instance.onCancel = game.onVerticalDragCancel;
},
);
}
if (game is HorizontalDragDetector) {
register(
HorizontalDragGestureRecognizer.new,
(HorizontalDragGestureRecognizer instance) {
instance.onDown = game.handleHorizontalDragDown;
instance.onStart = game.handleHorizontalDragStart;
instance.onUpdate = game.handleHorizontalDragUpdate;
instance.onEnd = game.handleHorizontalDragEnd;
instance.onCancel = game.onHorizontalDragCancel;
},
);
}
if (game is PanDetector) {
register(
PanGestureRecognizer.new,
Expand Down
48 changes: 0 additions & 48 deletions packages/flame/lib/src/gestures/detectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,6 @@ import 'package:flame/src/game/game.dart';
import 'package:flame/src/gestures/events.dart';
import 'package:flutter/gestures.dart';

mixin VerticalDragDetector on Game {
void onVerticalDragDown(DragDownInfo info) {}
void onVerticalDragStart(DragStartInfo info) {}
void onVerticalDragUpdate(DragUpdateInfo info) {}
void onVerticalDragEnd(DragEndInfo info) {}
void onVerticalDragCancel() {}

void handleVerticalDragDown(DragDownDetails details) {
onVerticalDragDown(DragDownInfo.fromDetails(this, details));
}

void handleVerticalDragStart(DragStartDetails details) {
onVerticalDragStart(DragStartInfo.fromDetails(this, details));
}

void handleVerticalDragUpdate(DragUpdateDetails details) {
onVerticalDragUpdate(DragUpdateInfo.fromDetails(this, details));
}

void handleVerticalDragEnd(DragEndDetails details) {
onVerticalDragEnd(DragEndInfo.fromDetails(details));
}
}

mixin HorizontalDragDetector on Game {
void onHorizontalDragDown(DragDownInfo info) {}
void onHorizontalDragStart(DragStartInfo info) {}
void onHorizontalDragUpdate(DragUpdateInfo info) {}
void onHorizontalDragEnd(DragEndInfo info) {}
void onHorizontalDragCancel() {}

void handleHorizontalDragDown(DragDownDetails details) {
onHorizontalDragDown(DragDownInfo.fromDetails(this, details));
}

void handleHorizontalDragStart(DragStartDetails details) {
onHorizontalDragStart(DragStartInfo.fromDetails(this, details));
}

void handleHorizontalDragUpdate(DragUpdateDetails details) {
onHorizontalDragUpdate(DragUpdateInfo.fromDetails(this, details));
}

void handleHorizontalDragEnd(DragEndDetails details) {
onHorizontalDragEnd(DragEndInfo.fromDetails(details));
}
}

mixin PanDetector on Game {
void onPanDown(DragDownInfo info) {}
void onPanStart(DragStartInfo info) {}
Expand Down
62 changes: 0 additions & 62 deletions packages/flame/test/game/game_widget/game_widget_drag_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,6 @@ import 'package:flame/input.dart';
import 'package:flame_test/flame_test.dart';
import 'package:flutter_test/flutter_test.dart';

class _HorizontalDragGame extends FlameGame with HorizontalDragDetector {
bool horizontalDragStarted = false;
bool horizontalDragEnded = false;

@override
void onHorizontalDragStart(_) {
horizontalDragStarted = true;
}

@override
void onHorizontalDragEnd(_) {
horizontalDragEnded = true;
}
}

class _VerticalDragGame extends FlameGame with VerticalDragDetector {
bool verticalDragStarted = false;
bool verticalDragEnded = false;

@override
void onVerticalDragStart(_) {
verticalDragStarted = true;
}

@override
void onVerticalDragEnd(_) {
verticalDragEnded = true;
}
}

class _PanGame extends FlameGame with PanDetector {
bool panStarted = false;
bool panEnded = false;
Expand All @@ -49,40 +19,8 @@ class _PanGame extends FlameGame with PanDetector {
}

void main() {
final horizontalGame = FlameTester(_HorizontalDragGame.new);
final verticalGame = FlameTester(_VerticalDragGame.new);
final panGame = FlameTester(_PanGame.new);

group('GameWidget - HorizontalDragDetector', () {
horizontalGame.testGameWidget(
'register drags',
verify: (game, tester) async {
await tester.drag(
find.byGame<_HorizontalDragGame>(),
const Offset(50, 0),
);

expect(game.horizontalDragStarted, isTrue);
expect(game.horizontalDragEnded, isTrue);
},
);
});

group('GameWidget - VerticalDragDetector', () {
verticalGame.testGameWidget(
'register drags',
verify: (game, tester) async {
await tester.drag(
find.byGame<_VerticalDragGame>(),
const Offset(50, 0),
);

expect(game.verticalDragStarted, isTrue);
expect(game.verticalDragEnded, isTrue);
},
);
});

group('GameWidget - PanDetector', () {
panGame.testGameWidget(
'register drags',
Expand Down
Loading
Loading