Unverified Commit f6a88d03 authored by Mouad Debbar's avatar Mouad Debbar Committed by GitHub

Registering multiple transformed events should work (#48149)

parent 2221a9f5
...@@ -10,6 +10,10 @@ import 'events.dart'; ...@@ -10,6 +10,10 @@ import 'events.dart';
/// interest in a pointer signal event. /// interest in a pointer signal event.
typedef PointerSignalResolvedCallback = void Function(PointerSignalEvent event); typedef PointerSignalResolvedCallback = void Function(PointerSignalEvent event);
bool _isSameEvent(PointerSignalEvent event1, PointerSignalEvent event2) {
return (event1.original ?? event1) == (event2.original ?? event2);
}
/// An resolver for pointer signal events. /// An resolver for pointer signal events.
/// ///
/// Objects interested in a [PointerSignalEvent] should register a callback to /// Objects interested in a [PointerSignalEvent] should register a callback to
...@@ -29,7 +33,7 @@ class PointerSignalResolver { ...@@ -29,7 +33,7 @@ class PointerSignalResolver {
void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) { void register(PointerSignalEvent event, PointerSignalResolvedCallback callback) {
assert(event != null); assert(event != null);
assert(callback != null); assert(callback != null);
assert(_currentEvent == null || _currentEvent == event); assert(_currentEvent == null || _isSameEvent(_currentEvent, event));
if (_firstRegisteredCallback != null) { if (_firstRegisteredCallback != null) {
return; return;
} }
...@@ -47,7 +51,7 @@ class PointerSignalResolver { ...@@ -47,7 +51,7 @@ class PointerSignalResolver {
assert(_currentEvent == null); assert(_currentEvent == null);
return; return;
} }
assert((_currentEvent.original ?? _currentEvent) == event); assert(_isSameEvent(_currentEvent, event));
try { try {
_firstRegisteredCallback(_currentEvent); _firstRegisteredCallback(_currentEvent);
} catch (exception, stack) { } catch (exception, stack) {
......
...@@ -74,14 +74,29 @@ void main() { ...@@ -74,14 +74,29 @@ void main() {
const PointerScrollEvent originalEvent = PointerScrollEvent(); const PointerScrollEvent originalEvent = PointerScrollEvent();
final PointerSignalEvent transformedEvent = originalEvent final PointerSignalEvent transformedEvent = originalEvent
.transformed(Matrix4.translationValues(10.0, 20.0, 0.0)); .transformed(Matrix4.translationValues(10.0, 20.0, 0.0));
final PointerSignalEvent anotherTransformedEvent = originalEvent
.transformed(Matrix4.translationValues(30.0, 50.0, 0.0));
expect(originalEvent, isNot(same(transformedEvent))); expect(originalEvent, isNot(same(transformedEvent)));
expect(transformedEvent.original, same(originalEvent)); expect(transformedEvent.original, same(originalEvent));
expect(originalEvent, isNot(same(anotherTransformedEvent)));
expect(anotherTransformedEvent.original, same(originalEvent));
final List<PointerSignalEvent> events = <PointerSignalEvent>[]; final List<PointerSignalEvent> events = <PointerSignalEvent>[];
resolver.register(transformedEvent, (PointerSignalEvent event) { resolver.register(transformedEvent, (PointerSignalEvent event) {
events.add(event); events.add(event);
}); });
// Registering a second transformed event should not throw an assertion.
expect(() {
resolver.register(anotherTransformedEvent, (PointerSignalEvent event) {
// This shouldn't be called because only the first registered callback is
// invoked.
events.add(event);
});
}, returnsNormally);
resolver.resolve(originalEvent); resolver.resolve(originalEvent);
expect(events.single, same(transformedEvent)); expect(events.single, same(transformedEvent));
......
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