fix: convert property bag to args

This commit is contained in:
shirakaba
2022-12-21 10:40:25 +09:00
parent 253d313776
commit 1f3a62c3fb
5 changed files with 44 additions and 194 deletions

View File

@@ -56,17 +56,17 @@ function accessibilityEventHelper(view: View, eventType: number) {
*/
if (SDK_VERSION >= 26) {
// Trigger all tap handlers on this view.
new DOMEvent('tap').dispatchTo({
target: view as View,
data: {
new DOMEvent('tap').dispatchTo(
view as View,
{
android: view.android,
eventName: 'tap',
ios: null,
object: view,
type: GestureTypes.tap,
view,
} as GestureEventData,
});
} as GestureEventData
);
}
return;

View File

@@ -290,7 +290,9 @@ export class DOMEvent implements Event {
* event's cancelable attribute value is false or its preventDefault()
* method was not invoked, and false otherwise.
*/
dispatchTo({ target, data, getGlobalEventHandlersPreHandling, getGlobalEventHandlersPostHandling }: { target: Observable; data: EventData; getGlobalEventHandlersPreHandling?: () => MutationSensitiveArray<ListenerEntry>; getGlobalEventHandlersPostHandling?: () => MutationSensitiveArray<ListenerEntry> }): boolean {
// Taking multiple params rather than a single property bag saves about 100
// nanoseconds per call.
dispatchTo(target: Observable, data: EventData, getGlobalEventHandlersPreHandling?: () => MutationSensitiveArray<ListenerEntry>, getGlobalEventHandlersPostHandling?: () => MutationSensitiveArray<ListenerEntry>): boolean {
if (this.eventPhase !== DOMEvent.NONE) {
throw new Error('Tried to dispatch a dispatching event');
}

View File

@@ -377,12 +377,12 @@ export class Observable implements EventTarget {
* @param options Options for the event, in line with DOM Standard.
*/
public notify<T extends EventData>(data: T, options?: CustomEventInit): void {
new DOMEvent(data.eventName, options).dispatchTo({
target: this,
new DOMEvent(data.eventName, options).dispatchTo(
this,
data,
getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(data, 'First'),
getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(data, ''),
});
() => this._getGlobalEventHandlers(data, 'First'),
() => this._getGlobalEventHandlers(data, '')
);
}
dispatchEvent(event: DOMEvent): boolean {
@@ -392,12 +392,12 @@ export class Observable implements EventTarget {
detail: event.detail,
};
return event.dispatchTo({
target: this,
return event.dispatchTo(
this,
data,
getGlobalEventHandlersPreHandling: () => this._getGlobalEventHandlers(data, 'First'),
getGlobalEventHandlersPostHandling: () => this._getGlobalEventHandlers(data, ''),
});
() => this._getGlobalEventHandlers(data, 'First'),
() => this._getGlobalEventHandlers(data, '')
);
}
private _getGlobalEventHandlers(data: EventData, eventType: 'First' | ''): MutationSensitiveArray<ListenerEntry> {

View File

@@ -63,10 +63,7 @@ function initializeTapAndDoubleTapGestureListener() {
public onLongPress(motionEvent: android.view.MotionEvent): void {
if (this._type & GestureTypes.longPress && this._observer?.callback) {
new DOMEvent('longPress').dispatchTo({
target: this._target,
data: _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent),
});
new DOMEvent('longPress').dispatchTo(this._target, _getLongPressArgs(GestureTypes.longPress, this._target, GestureStateTypes.began, motionEvent));
}
}
@@ -74,10 +71,7 @@ function initializeTapAndDoubleTapGestureListener() {
if (this._target.getGestureObservers(GestureTypes.doubleTap).length) {
this._tapTimeoutId = timer.setTimeout(() => {
if (this._type & GestureTypes.tap && this._observer?.callback) {
new DOMEvent('tap').dispatchTo({
target: this._target,
data: _getTapArgs(GestureTypes.tap, this._target, motionEvent),
});
new DOMEvent('tap').dispatchTo(this._target, _getTapArgs(GestureTypes.tap, this._target, motionEvent));
}
timer.clearTimeout(this._tapTimeoutId);
}, TapAndDoubleTapGestureListenerImpl.DoubleTapTimeout);
@@ -85,10 +79,7 @@ function initializeTapAndDoubleTapGestureListener() {
}
if (this._type & GestureTypes.tap && this._observer?.callback) {
new DOMEvent('tap').dispatchTo({
target: this._target,
data: _getTapArgs(GestureTypes.tap, this._target, motionEvent),
});
new DOMEvent('tap').dispatchTo(this._target, _getTapArgs(GestureTypes.tap, this._target, motionEvent));
}
}
@@ -97,10 +88,7 @@ function initializeTapAndDoubleTapGestureListener() {
timer.clearTimeout(this._tapTimeoutId);
}
if (this._type & GestureTypes.doubleTap && this._observer?.callback) {
new DOMEvent('doubleTap').dispatchTo({
target: this._target,
data: _getTapArgs(GestureTypes.doubleTap, this._target, motionEvent),
});
new DOMEvent('doubleTap').dispatchTo(this._target, _getTapArgs(GestureTypes.doubleTap, this._target, motionEvent));
}
}
}
@@ -137,10 +125,7 @@ function initializePinchGestureListener() {
this._scale = detector.getScaleFactor();
if (this._observer?.callback) {
new DOMEvent('pinch').dispatchTo({
target: this._target,
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.began),
});
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.began));
}
return true;
@@ -150,10 +135,7 @@ function initializePinchGestureListener() {
this._scale *= detector.getScaleFactor();
if (this._observer?.callback) {
new DOMEvent('pinch').dispatchTo({
target: this._target,
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.changed),
});
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.changed));
}
return true;
@@ -163,10 +145,7 @@ function initializePinchGestureListener() {
this._scale *= detector.getScaleFactor();
if (this._observer?.callback) {
new DOMEvent('pinch').dispatchTo({
target: this._target,
data: new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.ended),
});
new DOMEvent('pinch').dispatchTo(this._target, new PinchGestureEventData(this._target, detector, this._scale, this._target, GestureStateTypes.ended));
}
}
}
@@ -212,19 +191,13 @@ function initializeSwipeGestureListener() {
if (Math.abs(deltaX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (deltaX > 0) {
if (this._observer?.callback) {
new DOMEvent('swipe').dispatchTo({
target: this._target,
data: _getSwipeArgs(SwipeDirection.right, this._target, initialEvent, currentEvent),
});
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.right, this._target, initialEvent, currentEvent));
}
result = true;
} else {
if (this._observer?.callback) {
new DOMEvent('swipe').dispatchTo({
target: this._target,
data: _getSwipeArgs(SwipeDirection.left, this._target, initialEvent, currentEvent),
});
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.left, this._target, initialEvent, currentEvent));
}
result = true;
}
@@ -233,18 +206,12 @@ function initializeSwipeGestureListener() {
if (Math.abs(deltaY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (deltaY > 0) {
if (this._observer?.callback) {
new DOMEvent('swipe').dispatchTo({
target: this._target,
data: _getSwipeArgs(SwipeDirection.down, this._target, initialEvent, currentEvent),
});
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.down, this._target, initialEvent, currentEvent));
}
result = true;
} else {
if (this._observer?.callback) {
new DOMEvent('swipe').dispatchTo({
target: this._target,
data: _getSwipeArgs(SwipeDirection.up, this._target, initialEvent, currentEvent),
});
new DOMEvent('swipe').dispatchTo(this._target, _getSwipeArgs(SwipeDirection.up, this._target, initialEvent, currentEvent));
}
result = true;
}
@@ -372,10 +339,7 @@ export class GesturesObserver extends GesturesObserverBase {
this._eventData.prepare(this.target, motionEvent);
if (this.callback) {
new DOMEvent('touch').dispatchTo({
target: this.target,
data: this._eventData,
});
new DOMEvent('touch').dispatchTo(this.target, this._eventData);
}
}
@@ -504,10 +468,7 @@ class CustomPanGestureDetector {
private trackStop(currentEvent: android.view.MotionEvent, cacheEvent: boolean) {
if (this.isTracking) {
if (this.observer?.callback) {
new DOMEvent('pan').dispatchTo({
target: this.target,
data: _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.ended, null, currentEvent),
});
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.ended, null, currentEvent));
}
this.deltaX = undefined;
@@ -529,10 +490,7 @@ class CustomPanGestureDetector {
this.isTracking = true;
if (this.observer?.callback) {
new DOMEvent('pan').dispatchTo({
target: this.target,
data: _getPanArgs(0, 0, this.target, GestureStateTypes.began, null, currentEvent),
});
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(0, 0, this.target, GestureStateTypes.began, null, currentEvent));
}
}
@@ -542,10 +500,7 @@ class CustomPanGestureDetector {
this.deltaY = current.y - this.initialY;
if (this.observer?.callback) {
new DOMEvent('pan').dispatchTo({
target: this.target,
data: _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.changed, null, currentEvent),
});
new DOMEvent('pan').dispatchTo(this.target, _getPanArgs(this.deltaX, this.deltaY, this.target, GestureStateTypes.changed, null, currentEvent));
}
}
@@ -665,10 +620,7 @@ class CustomRotateGestureDetector {
};
if (this.observer?.callback) {
new DOMEvent('rotation').dispatchTo({
target: this.target,
data: args,
});
new DOMEvent('rotation').dispatchTo(this.target, args);
}
}

View File

@@ -134,141 +134,37 @@ export class GesturesObserver extends GesturesObserverBase {
// release, we may make them bubbling.
if (type & GestureTypes.tap) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.tap,
(args) =>
args.view &&
new DOMEvent('tap').dispatchTo({
target: args.view as View,
data: _getTapData(args),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.tap, (args) => args.view && new DOMEvent('tap').dispatchTo(args.view as View, _getTapData(args))));
}
if (type & GestureTypes.doubleTap) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.doubleTap,
(args) =>
args.view &&
new DOMEvent('doubleTap').dispatchTo({
target: args.view as View,
data: _getTapData(args),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.doubleTap, (args) => args.view && new DOMEvent('doubleTap').dispatchTo(args.view as View, _getTapData(args))));
}
if (type & GestureTypes.pinch) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.pinch,
(args) =>
args.view &&
new DOMEvent('pinch').dispatchTo({
target: args.view as View,
data: _getPinchData(args),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pinch, (args) => args.view && new DOMEvent('pinch').dispatchTo(args.view as View, _getPinchData(args))));
}
if (type & GestureTypes.pan) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.pan,
(args) =>
args.view &&
new DOMEvent('pan').dispatchTo({
target: args.view as View,
data: _getPanData(args, target.nativeViewProtected),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.pan, (args) => args.view && new DOMEvent('pan').dispatchTo(args.view as View, _getPanData(args, target.nativeViewProtected))));
}
if (type & GestureTypes.swipe) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.swipe,
(args) =>
args.view &&
new DOMEvent('swipe').dispatchTo({
target: args.view as View,
data: _getSwipeData(args),
}),
UISwipeGestureRecognizerDirection.Down
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, (args) => args.view && new DOMEvent('swipe').dispatchTo(args.view as View, _getSwipeData(args)), UISwipeGestureRecognizerDirection.Down));
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.swipe,
(args) =>
args.view &&
new DOMEvent('swipe').dispatchTo({
target: args.view as View,
data: _getSwipeData(args),
}),
UISwipeGestureRecognizerDirection.Left
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, (args) => args.view && new DOMEvent('swipe').dispatchTo(args.view as View, _getSwipeData(args)), UISwipeGestureRecognizerDirection.Left));
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.swipe,
(args) =>
args.view &&
new DOMEvent('swipe').dispatchTo({
target: args.view as View,
data: _getSwipeData(args),
}),
UISwipeGestureRecognizerDirection.Right
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, (args) => args.view && new DOMEvent('swipe').dispatchTo(args.view as View, _getSwipeData(args)), UISwipeGestureRecognizerDirection.Right));
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.swipe,
(args) =>
args.view &&
new DOMEvent('swipe').dispatchTo({
target: args.view as View,
data: _getSwipeData(args),
}),
UISwipeGestureRecognizerDirection.Up
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.swipe, (args) => args.view && new DOMEvent('swipe').dispatchTo(args.view as View, _getSwipeData(args)), UISwipeGestureRecognizerDirection.Up));
}
if (type & GestureTypes.rotation) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.rotation,
(args) =>
args.view &&
new DOMEvent('rotation').dispatchTo({
target: args.view as View,
data: _getRotationData(args),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.rotation, (args) => args.view && new DOMEvent('rotation').dispatchTo(args.view as View, _getRotationData(args))));
}
if (type & GestureTypes.longPress) {
nativeView.addGestureRecognizer(
this._createRecognizer(
GestureTypes.longPress,
(args) =>
args.view &&
new DOMEvent('longPress').dispatchTo({
target: args.view as View,
data: _getLongPressData(args),
})
)
);
nativeView.addGestureRecognizer(this._createRecognizer(GestureTypes.longPress, (args) => args.view && new DOMEvent('longPress').dispatchTo(args.view as View, _getLongPressData(args))));
}
if (type & GestureTypes.touch) {