Unverified Commit b619b701 authored by Kostia Sokolovskyi's avatar Kostia Sokolovskyi Committed by GitHub

MultiDragPointerState should dispatch creation and disposal events. (#138807)

parent 81e390c6
......@@ -33,7 +33,17 @@ typedef GestureMultiDragStartCallback = Drag? Function(Offset position);
abstract class MultiDragPointerState {
/// Creates per-pointer state for a [MultiDragGestureRecognizer].
MultiDragPointerState(this.initialPosition, this.kind, this.gestureSettings)
: _velocityTracker = VelocityTracker.withKind(kind);
: _velocityTracker = VelocityTracker.withKind(kind) {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectCreated(
library: 'package:flutter/gestures.dart',
className: '$MultiDragPointerState',
object: this,
);
}
}
/// Device specific gesture configuration that should be preferred over
/// framework constants.
......@@ -178,6 +188,11 @@ abstract class MultiDragPointerState {
@protected
@mustCallSuper
void dispose() {
// TODO(polina-c): stop duplicating code across disposables
// https://github.com/flutter/flutter/issues/137435
if (kFlutterMemoryAllocationsEnabled) {
MemoryAllocations.instance.dispatchObjectDisposed(object: this);
}
_arenaEntry?.resolve(GestureDisposition.rejected);
_arenaEntry = null;
assert(() {
......
......@@ -4,6 +4,7 @@
import 'package:flutter/gestures.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leak_tracker_flutter_testing/leak_tracker_flutter_testing.dart';
import 'gesture_tester.dart';
......@@ -111,4 +112,34 @@ void main() {
// ignore: invalid_use_of_protected_member
expect(recognizer2.isPointerAllowed(rejectedPointer), false);
});
test('$MultiDragPointerState dispatches memory events', () async {
await expectLater(
await memoryEvents(
() => _MultiDragPointerState(
Offset.zero,
PointerDeviceKind.touch,
null,
).dispose(),
_MultiDragPointerState,
),
areCreateAndDispose,
);
});
}
class _MultiDragPointerState extends MultiDragPointerState {
_MultiDragPointerState(
super.initialPosition,
super.kind,
super.gestureSettings,
);
@override
void accepted(GestureMultiDragStartCallback starter) {}
@override
void dispose() {
super.dispose();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment