mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
chore: cleanup touchmanager
This commit is contained in:
@@ -62,14 +62,12 @@ export class TouchManager {
|
||||
* @param view NativeScript view instance
|
||||
*/
|
||||
static addAnimations(view: View) {
|
||||
// console.log("tapHandler:", tapHandler);
|
||||
const handleDown = (view?.touchAnimation && (<TouchAnimationOptions>view?.touchAnimation).down) || (TouchManager.animations && TouchManager.animations.down);
|
||||
const handleUp = (view?.touchAnimation && (<TouchAnimationOptions>view?.touchAnimation).up) || (TouchManager.animations && TouchManager.animations.up);
|
||||
|
||||
if (global.isIOS) {
|
||||
if (view?.ios?.addTargetActionForControlEvents) {
|
||||
// can use UIControlEvents
|
||||
// console.log('added UIControlEvents!');
|
||||
if (!TouchManager.touchHandlers) {
|
||||
TouchManager.touchHandlers = [];
|
||||
}
|
||||
@@ -81,20 +79,16 @@ export class TouchManager {
|
||||
if (handleDown) {
|
||||
(<UIControl>view.ios).addTargetActionForControlEvents(TouchManager.touchHandlers[TouchManager.touchHandlers.length - 1].handler, GestureEvents.touchDown, UIControlEvents.TouchDown | UIControlEvents.TouchDragEnter);
|
||||
view.on(GestureEvents.touchDown, (args) => {
|
||||
// console.log('touchDown {N} event');
|
||||
TouchManager.startAnimationForType(view, TouchAnimationTypes.down);
|
||||
});
|
||||
}
|
||||
if (handleUp) {
|
||||
(<UIControl>view.ios).addTargetActionForControlEvents(TouchManager.touchHandlers[TouchManager.touchHandlers.length - 1].handler, GestureEvents.touchUp, UIControlEvents.TouchDragExit | UIControlEvents.TouchCancel | UIControlEvents.TouchUpInside | UIControlEvents.TouchUpOutside);
|
||||
view.on(GestureEvents.touchUp, (args) => {
|
||||
// console.log('touchUp {N} event');
|
||||
TouchManager.startAnimationForType(view, TouchAnimationTypes.up);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
// console.log('added longPress to:', view.id);
|
||||
|
||||
if (handleDown || handleUp) {
|
||||
view.on(GestureEvents.gestureAttached, (args: GestureEventData) => {
|
||||
if (args.type === GestureTypes.longPress) {
|
||||
@@ -105,7 +99,6 @@ export class TouchManager {
|
||||
switch (args.state) {
|
||||
case GestureStateTypes.began:
|
||||
if (handleDown) {
|
||||
// console.log('longPress began:', args.view.id, args.state);
|
||||
TouchManager.startAnimationForType(<View>args.view, TouchAnimationTypes.down);
|
||||
}
|
||||
break;
|
||||
@@ -146,13 +139,11 @@ export class TouchManager {
|
||||
});
|
||||
if (handleDown) {
|
||||
view.on(GestureEvents.touchDown, (args) => {
|
||||
// console.log('touchDown {N} event');
|
||||
TouchManager.startAnimationForType(view, TouchAnimationTypes.down);
|
||||
});
|
||||
}
|
||||
if (handleUp) {
|
||||
view.on(GestureEvents.touchUp, (args) => {
|
||||
// console.log('touchUp {N} event');
|
||||
TouchManager.startAnimationForType(view, TouchAnimationTypes.up);
|
||||
});
|
||||
}
|
||||
@@ -160,14 +151,11 @@ export class TouchManager {
|
||||
}
|
||||
|
||||
view.on(View.disposeNativeViewEvent, (args) => {
|
||||
// console.log('calling disposeNativeView:', args.eventName, 'TouchManager.touchHandlers.length:', TouchManager.touchHandlers.length);
|
||||
const index = TouchManager.touchHandlers?.findIndex((handler) => handler.view === args.object);
|
||||
if (index > -1) {
|
||||
TouchManager.touchHandlers.splice(index, 1);
|
||||
}
|
||||
TouchManager.touchAnimationDefinitions = TouchManager.touchAnimationDefinitions?.filter((d) => d.view !== args.object);
|
||||
// console.log('after clearing with disposeNativeView:', args.eventName, 'TouchManager.touchHandlers.length:', TouchManager.touchHandlers.length);
|
||||
// console.log('TouchManager.touchAnimationDefinitions.length:', TouchManager.touchAnimationDefinitions.length);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user