chore(core): clean up _gestureObservers

This commit is contained in:
shirakaba
2024-05-01 16:51:24 +09:00
parent 02e4d812c2
commit 41099bf361

View File

@ -123,7 +123,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
_setMinWidthNative: (value: CoreTypes.LengthType) => void; _setMinWidthNative: (value: CoreTypes.LengthType) => void;
_setMinHeightNative: (value: CoreTypes.LengthType) => void; _setMinHeightNative: (value: CoreTypes.LengthType) => void;
public _gestureObservers = {}; public readonly _gestureObservers = {} as Record<GestureTypes, Array<GesturesObserver>>;
_androidContentDescriptionUpdated?: boolean; _androidContentDescriptionUpdated?: boolean;
@ -177,7 +177,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
onLoaded() { onLoaded() {
if (!this.isLoaded) { if (!this.isLoaded) {
const hasTap = this.hasListeners('tap') || this.hasListeners('tapChange') || this.getGestureObservers(GestureTypes.tap); const hasTap = this.hasListeners('tap') || this.hasListeners('tapChange') || !!this.getGestureObservers(GestureTypes.tap);
const enableTapAnimations = TouchManager.enableGlobalTapAnimations && hasTap; const enableTapAnimations = TouchManager.enableGlobalTapAnimations && hasTap;
if (!this.ignoreTouchAnimation && (this.touchAnimation || enableTapAnimations)) { if (!this.ignoreTouchAnimation && (this.touchAnimation || enableTapAnimations)) {
TouchManager.addAnimations(this); TouchManager.addAnimations(this);
@ -286,7 +286,7 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
this._gestureObservers[type].push(gestureObserve(this, type, callback, thisArg)); this._gestureObservers[type].push(gestureObserve(this, type, callback, thisArg));
} }
public getGestureObservers(type: GestureTypes): Array<GesturesObserver> { public getGestureObservers(type: GestureTypes): Array<GesturesObserver> | undefined {
return this._gestureObservers[type]; return this._gestureObservers[type];
} }
@ -495,10 +495,12 @@ export abstract class ViewCommon extends ViewBase implements ViewDefinition {
private _disconnectGestureObservers(type: GestureTypes): void { private _disconnectGestureObservers(type: GestureTypes): void {
const observers = this.getGestureObservers(type); const observers = this.getGestureObservers(type);
if (observers) { if (!observers) {
for (let i = 0; i < observers.length; i++) { return;
observers[i].disconnect(); }
}
for (const observer of observers) {
observer.disconnect();
} }
} }