@react-native-oh-tpl/react-native-gesture-handler 2.12.6-1 → 2.12.9
Sign up to get free protection for your applications and to get access to all the features.
- package/harmony/gesture_handler/BuildProfile.ets +5 -0
- package/harmony/gesture_handler/build-profile.json5 +18 -7
- package/harmony/gesture_handler/hvigorfile.ts +2 -2
- package/harmony/gesture_handler/index.ets +3 -3
- package/harmony/gesture_handler/oh-package-lock.json5 +17 -0
- package/harmony/gesture_handler/oh-package.json5 +12 -11
- package/harmony/gesture_handler/src/main/cpp/CMakeLists.txt +8 -8
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.cpp +103 -34
- package/harmony/gesture_handler/src/main/cpp/GestureHandlerPackage.h +21 -15
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonComponentInstance.h +27 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerButtonJSIBinder.h +32 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.cpp +22 -17
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerModule.h +15 -12
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerPackage.h +72 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentDescriptor.h +36 -60
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewComponentInstance.h +78 -0
- package/harmony/gesture_handler/src/main/cpp/RNGestureHandlerRootViewJSIBinder.h +25 -0
- package/harmony/gesture_handler/src/main/ets/CircularBuffer.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/Event.ts +67 -67
- package/harmony/gesture_handler/src/main/ets/EventDispatcher.ts +52 -37
- package/harmony/gesture_handler/src/main/ets/GestureHandler.ts +663 -663
- package/harmony/gesture_handler/src/main/ets/{GestureHandlerArkUIAdapter.ets → GestureHandlerArkUIAdapter.ts} +202 -201
- package/harmony/gesture_handler/src/main/ets/GestureHandlerFactory.ts +44 -44
- package/harmony/gesture_handler/src/main/ets/GestureHandlerOrchestrator.ts +280 -280
- package/harmony/gesture_handler/src/main/ets/GestureHandlerPackage.ts +22 -22
- package/harmony/gesture_handler/src/main/ets/GestureHandlerRegistry.ts +27 -27
- package/harmony/gesture_handler/src/main/ets/InteractionManager.ts +108 -108
- package/harmony/gesture_handler/src/main/ets/LeastSquareSolver.ts +182 -182
- package/harmony/gesture_handler/src/main/ets/NativeViewGestureHandler.ts +114 -114
- package/harmony/gesture_handler/src/main/ets/OutgoingEvent.ts +33 -33
- package/harmony/gesture_handler/src/main/ets/PanGestureHandler.ts +327 -327
- package/harmony/gesture_handler/src/main/ets/PointerTracker.ts +239 -239
- package/harmony/gesture_handler/src/main/ets/RNGHError.ts +4 -4
- package/harmony/gesture_handler/src/main/ets/RNGHLogger.ts +47 -28
- package/harmony/gesture_handler/src/main/ets/{RNGHRootTouchHandler.ets → RNGHRootTouchHandlerArkTS.ts} +59 -57
- package/harmony/gesture_handler/src/main/ets/RNGHRootTouchHandlerCAPI.ts +87 -0
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerButton.ets +37 -36
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerModule.ts +183 -125
- package/harmony/gesture_handler/src/main/ets/RNGestureHandlerRootView.ets +52 -55
- package/harmony/gesture_handler/src/main/ets/RNOHScrollLocker.ts +23 -11
- package/harmony/gesture_handler/src/main/ets/State.ts +46 -46
- package/harmony/gesture_handler/src/main/ets/TapGestureHandler.ts +205 -205
- package/harmony/gesture_handler/src/main/ets/Vector2D.ts +36 -36
- package/harmony/gesture_handler/src/main/ets/VelocityTracker.ts +98 -98
- package/harmony/gesture_handler/src/main/ets/View.ts +70 -70
- package/harmony/gesture_handler/src/main/ets/ViewRegistry.ts +42 -42
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerButton.ts +140 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerModule.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/namespace/RNGestureHandlerRootView.ts +101 -0
- package/harmony/gesture_handler/src/main/ets/namespace/ts.ts +3 -0
- package/harmony/gesture_handler/src/main/ets/pages/Index.ets +16 -16
- package/harmony/gesture_handler/src/main/ets/types.ts +25 -0
- package/harmony/gesture_handler/src/main/ets/webviewability/WebviewAbility.ts +41 -41
- package/harmony/gesture_handler/src/main/module.json5 +7 -7
- package/harmony/gesture_handler/src/main/resources/base/element/color.json +7 -7
- package/harmony/gesture_handler/src/main/resources/base/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/base/profile/main_pages.json +5 -5
- package/harmony/gesture_handler/src/main/resources/en_US/element/string.json +15 -15
- package/harmony/gesture_handler/src/main/resources/zh_CN/element/string.json +15 -15
- package/harmony/gesture_handler/ts.ts +2 -1
- package/harmony/gesture_handler.har +0 -0
- package/lib/commonjs/RNGestureHandlerModule.js +6 -3
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +5 -13
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +31 -28
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/index.js +42 -19
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +10 -0
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js +11 -0
- package/lib/commonjs/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.js +3 -2
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js +3 -11
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/handlers/createHandler.js +20 -19
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/index.js +6 -14
- package/lib/module/index.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js +3 -0
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js +3 -0
- package/lib/module/specs/RNGestureHandlerRootViewNativeComponent.js.map +1 -0
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -6
- package/lib/typescript/RNGestureHandlerModule.d.ts.map +1 -1
- package/lib/typescript/components/GestureHandlerRootView.d.ts +6 -6
- package/lib/typescript/components/GestureHandlerRootView.d.ts.map +1 -1
- package/lib/typescript/handlers/createHandler.d.ts +11 -11
- package/lib/typescript/handlers/createHandler.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +9 -8
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +15 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +15 -0
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts.map +1 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts +7 -0
- package/lib/typescript/specs/RNGestureHandlerRootViewNativeComponent.d.ts.map +1 -0
- package/package.json +66 -70
- package/src/RNGestureHandlerModule.ts +5 -6
- package/src/components/GestureHandlerRootView.tsx +23 -34
- package/src/handlers/createHandler.tsx +534 -535
- package/src/index.ts +172 -172
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +18 -0
- package/src/specs/RNGestureHandlerRootViewNativeComponent.ts +6 -0
- package/README.md +0 -1
- package/lib/commonjs/components/GestureButtons.js +0 -186
- package/lib/commonjs/components/GestureButtons.js.map +0 -1
- package/lib/commonjs/components/GestureHandlerButton.js +0 -9
- package/lib/commonjs/components/GestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/RNGestureHandlerButton.js +0 -23
- package/lib/commonjs/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +0 -247
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableOpacity.js +0 -58
- package/lib/commonjs/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js +0 -18
- package/lib/commonjs/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/commonjs/components/touchables/index.js +0 -21
- package/lib/commonjs/components/touchables/index.js.map +0 -1
- package/lib/commonjs/handlers/NativeViewGestureHandler.js +0 -19
- package/lib/commonjs/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/PanGestureHandler.js +0 -103
- package/lib/commonjs/handlers/PanGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/TapGestureHandler.js +0 -22
- package/lib/commonjs/handlers/TapGestureHandler.js.map +0 -1
- package/lib/commonjs/handlers/createNativeWrapper.js +0 -64
- package/lib/commonjs/handlers/createNativeWrapper.js.map +0 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +0 -22
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +0 -554
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/commonjs/init.js +0 -24
- package/lib/commonjs/init.js.map +0 -1
- package/lib/module/components/GestureButtons.js +0 -168
- package/lib/module/components/GestureButtons.js.map +0 -1
- package/lib/module/components/GestureHandlerButton.js +0 -3
- package/lib/module/components/GestureHandlerButton.js.map +0 -1
- package/lib/module/components/RNGestureHandlerButton.js +0 -17
- package/lib/module/components/RNGestureHandlerButton.js.map +0 -1
- package/lib/module/components/touchables/GenericTouchable.js +0 -238
- package/lib/module/components/touchables/GenericTouchable.js.map +0 -1
- package/lib/module/components/touchables/TouchableOpacity.js +0 -49
- package/lib/module/components/touchables/TouchableOpacity.js.map +0 -1
- package/lib/module/components/touchables/TouchableWithoutFeedback.js +0 -9
- package/lib/module/components/touchables/TouchableWithoutFeedback.js.map +0 -1
- package/lib/module/components/touchables/index.js +0 -8
- package/lib/module/components/touchables/index.js.map +0 -1
- package/lib/module/handlers/NativeViewGestureHandler.js +0 -12
- package/lib/module/handlers/NativeViewGestureHandler.js.map +0 -1
- package/lib/module/handlers/PanGestureHandler.js +0 -92
- package/lib/module/handlers/PanGestureHandler.js.map +0 -1
- package/lib/module/handlers/TapGestureHandler.js +0 -14
- package/lib/module/handlers/TapGestureHandler.js.map +0 -1
- package/lib/module/handlers/createNativeWrapper.js +0 -57
- package/lib/module/handlers/createNativeWrapper.js.map +0 -1
- package/lib/module/handlers/gestureHandlerCommon.js +0 -15
- package/lib/module/handlers/gestureHandlerCommon.js.map +0 -1
- package/lib/module/handlers/gestures/GestureDetector.js +0 -543
- package/lib/module/handlers/gestures/GestureDetector.js.map +0 -1
- package/lib/module/init.js +0 -17
- package/lib/module/init.js.map +0 -1
- package/lib/typescript/components/GestureButtons.d.ts +0 -122
- package/lib/typescript/components/GestureButtons.d.ts.map +0 -1
- package/lib/typescript/components/GestureHandlerButton.d.ts +0 -5
- package/lib/typescript/components/GestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/RNGestureHandlerButton.d.ts +0 -2
- package/lib/typescript/components/RNGestureHandlerButton.d.ts.map +0 -1
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +0 -68
- package/lib/typescript/components/touchables/GenericTouchable.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts +0 -26
- package/lib/typescript/components/touchables/TouchableOpacity.d.ts.map +0 -1
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts +0 -8
- package/lib/typescript/components/touchables/TouchableWithoutFeedback.d.ts.map +0 -1
- package/lib/typescript/components/touchables/index.d.ts +0 -4
- package/lib/typescript/components/touchables/index.d.ts.map +0 -1
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +0 -29
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +0 -140
- package/lib/typescript/handlers/PanGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/TapGestureHandler.d.ts +0 -58
- package/lib/typescript/handlers/TapGestureHandler.d.ts.map +0 -1
- package/lib/typescript/handlers/createNativeWrapper.d.ts +0 -4
- package/lib/typescript/handlers/createNativeWrapper.d.ts.map +0 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +0 -2
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts.map +0 -1
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +0 -24
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts.map +0 -1
- package/lib/typescript/init.d.ts +0 -3
- package/lib/typescript/init.d.ts.map +0 -1
- package/src/components/GestureButtons.tsx +0 -334
- package/src/components/GestureHandlerButton.tsx +0 -5
- package/src/components/RNGestureHandlerButton.tsx +0 -23
- package/src/components/touchables/GenericTouchable.tsx +0 -301
- package/src/components/touchables/TouchableOpacity.tsx +0 -76
- package/src/components/touchables/TouchableWithoutFeedback.tsx +0 -14
- package/src/components/touchables/index.ts +0 -7
- package/src/handlers/NativeViewGestureHandler.ts +0 -55
- package/src/handlers/PanGestureHandler.ts +0 -327
- package/src/handlers/TapGestureHandler.ts +0 -95
- package/src/handlers/createNativeWrapper.tsx +0 -81
- package/src/handlers/gestureHandlerCommon.ts +0 -15
- package/src/handlers/gestures/GestureDetector.tsx +0 -823
- package/src/init.ts +0 -18
@@ -1,109 +1,109 @@
|
|
1
|
-
import { GestureHandler, Handler, GestureConfig as Config } from "./GestureHandler"
|
2
|
-
|
3
|
-
export class InteractionManager {
|
4
|
-
private readonly waitForRelations: Map<number, number[]> = new Map()
|
5
|
-
private readonly simultaneousRelations: Map<number, number[]> = new Map()
|
6
|
-
|
7
|
-
public configureInteractions(handler: GestureHandler, config: Config) {
|
8
|
-
this.dropRelationsForHandlerWithTag(handler.getTag());
|
9
|
-
|
10
|
-
if (config.waitFor) {
|
11
|
-
const waitFor: number[] = [];
|
12
|
-
config.waitFor.forEach((otherHandler: Handler): void => {
|
13
|
-
// New API reference
|
14
|
-
if (typeof otherHandler === 'number') {
|
15
|
-
waitFor.push(otherHandler);
|
16
|
-
} else {
|
17
|
-
// Old API reference
|
18
|
-
waitFor.push(otherHandler.handlerTag);
|
19
|
-
}
|
20
|
-
});
|
21
|
-
|
22
|
-
this.waitForRelations.set(handler.getTag(), waitFor);
|
23
|
-
}
|
24
|
-
|
25
|
-
if (config.simultaneousHandlers) {
|
26
|
-
const simultaneousHandlers: number[] = [];
|
27
|
-
config.simultaneousHandlers.forEach((otherHandler: Handler): void => {
|
28
|
-
if (typeof otherHandler === 'number') {
|
29
|
-
simultaneousHandlers.push(otherHandler);
|
30
|
-
} else {
|
31
|
-
simultaneousHandlers.push(otherHandler.handlerTag);
|
32
|
-
}
|
33
|
-
});
|
34
|
-
|
35
|
-
this.simultaneousRelations.set(handler.getTag(), simultaneousHandlers);
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
public shouldWaitForHandlerFailure(
|
40
|
-
handler: GestureHandler,
|
41
|
-
otherHandler: GestureHandler
|
42
|
-
): boolean {
|
43
|
-
const waitFor: number[] | undefined = this.waitForRelations.get(
|
44
|
-
handler.getTag()
|
45
|
-
);
|
46
|
-
if (!waitFor) {
|
47
|
-
return false;
|
48
|
-
}
|
49
|
-
|
50
|
-
let shouldWait = false;
|
51
|
-
|
52
|
-
waitFor.forEach((tag: number): void => {
|
53
|
-
if (tag === otherHandler.getTag()) {
|
54
|
-
shouldWait = true;
|
55
|
-
return; //Returns from callback
|
56
|
-
}
|
57
|
-
});
|
58
|
-
|
59
|
-
return shouldWait;
|
60
|
-
}
|
61
|
-
|
62
|
-
public shouldRecognizeSimultaneously(
|
63
|
-
handler: GestureHandler,
|
64
|
-
otherHandler: GestureHandler
|
65
|
-
): boolean {
|
66
|
-
const simultaneousHandlers: number[] | undefined =
|
67
|
-
this.simultaneousRelations.get(handler.getTag());
|
68
|
-
if (!simultaneousHandlers) {
|
69
|
-
return false;
|
70
|
-
}
|
71
|
-
|
72
|
-
let shouldRecognizeSimultaneously = false;
|
73
|
-
|
74
|
-
simultaneousHandlers.forEach((tag: number): void => {
|
75
|
-
if (tag === otherHandler.getTag()) {
|
76
|
-
shouldRecognizeSimultaneously = true;
|
77
|
-
return;
|
78
|
-
}
|
79
|
-
});
|
80
|
-
|
81
|
-
return shouldRecognizeSimultaneously;
|
82
|
-
}
|
83
|
-
|
84
|
-
public shouldRequireHandlerToWaitForFailure(
|
85
|
-
_handler: GestureHandler,
|
86
|
-
_otherHandler: GestureHandler
|
87
|
-
): boolean {
|
88
|
-
//TODO: Implement logic
|
89
|
-
return false;
|
90
|
-
}
|
91
|
-
|
92
|
-
public shouldHandlerBeCancelledBy(
|
93
|
-
_handler: GestureHandler,
|
94
|
-
_otherHandler: GestureHandler
|
95
|
-
): boolean {
|
96
|
-
//TODO: Implement logic
|
97
|
-
return false;
|
98
|
-
}
|
99
|
-
|
100
|
-
public dropRelationsForHandlerWithTag(handlerTag: number): void {
|
101
|
-
this.waitForRelations.delete(handlerTag);
|
102
|
-
this.simultaneousRelations.delete(handlerTag);
|
103
|
-
}
|
104
|
-
|
105
|
-
public reset() {
|
106
|
-
this.waitForRelations.clear();
|
107
|
-
this.simultaneousRelations.clear();
|
108
|
-
}
|
1
|
+
import { GestureHandler, Handler, GestureConfig as Config } from "./GestureHandler"
|
2
|
+
|
3
|
+
export class InteractionManager {
|
4
|
+
private readonly waitForRelations: Map<number, number[]> = new Map()
|
5
|
+
private readonly simultaneousRelations: Map<number, number[]> = new Map()
|
6
|
+
|
7
|
+
public configureInteractions(handler: GestureHandler, config: Config) {
|
8
|
+
this.dropRelationsForHandlerWithTag(handler.getTag());
|
9
|
+
|
10
|
+
if (config.waitFor) {
|
11
|
+
const waitFor: number[] = [];
|
12
|
+
config.waitFor.forEach((otherHandler: Handler): void => {
|
13
|
+
// New API reference
|
14
|
+
if (typeof otherHandler === 'number') {
|
15
|
+
waitFor.push(otherHandler);
|
16
|
+
} else {
|
17
|
+
// Old API reference
|
18
|
+
waitFor.push(otherHandler.handlerTag);
|
19
|
+
}
|
20
|
+
});
|
21
|
+
|
22
|
+
this.waitForRelations.set(handler.getTag(), waitFor);
|
23
|
+
}
|
24
|
+
|
25
|
+
if (config.simultaneousHandlers) {
|
26
|
+
const simultaneousHandlers: number[] = [];
|
27
|
+
config.simultaneousHandlers.forEach((otherHandler: Handler): void => {
|
28
|
+
if (typeof otherHandler === 'number') {
|
29
|
+
simultaneousHandlers.push(otherHandler);
|
30
|
+
} else {
|
31
|
+
simultaneousHandlers.push(otherHandler.handlerTag);
|
32
|
+
}
|
33
|
+
});
|
34
|
+
|
35
|
+
this.simultaneousRelations.set(handler.getTag(), simultaneousHandlers);
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
public shouldWaitForHandlerFailure(
|
40
|
+
handler: GestureHandler,
|
41
|
+
otherHandler: GestureHandler
|
42
|
+
): boolean {
|
43
|
+
const waitFor: number[] | undefined = this.waitForRelations.get(
|
44
|
+
handler.getTag()
|
45
|
+
);
|
46
|
+
if (!waitFor) {
|
47
|
+
return false;
|
48
|
+
}
|
49
|
+
|
50
|
+
let shouldWait = false;
|
51
|
+
|
52
|
+
waitFor.forEach((tag: number): void => {
|
53
|
+
if (tag === otherHandler.getTag()) {
|
54
|
+
shouldWait = true;
|
55
|
+
return; //Returns from callback
|
56
|
+
}
|
57
|
+
});
|
58
|
+
|
59
|
+
return shouldWait;
|
60
|
+
}
|
61
|
+
|
62
|
+
public shouldRecognizeSimultaneously(
|
63
|
+
handler: GestureHandler,
|
64
|
+
otherHandler: GestureHandler
|
65
|
+
): boolean {
|
66
|
+
const simultaneousHandlers: number[] | undefined =
|
67
|
+
this.simultaneousRelations.get(handler.getTag());
|
68
|
+
if (!simultaneousHandlers) {
|
69
|
+
return false;
|
70
|
+
}
|
71
|
+
|
72
|
+
let shouldRecognizeSimultaneously = false;
|
73
|
+
|
74
|
+
simultaneousHandlers.forEach((tag: number): void => {
|
75
|
+
if (tag === otherHandler.getTag()) {
|
76
|
+
shouldRecognizeSimultaneously = true;
|
77
|
+
return;
|
78
|
+
}
|
79
|
+
});
|
80
|
+
|
81
|
+
return shouldRecognizeSimultaneously;
|
82
|
+
}
|
83
|
+
|
84
|
+
public shouldRequireHandlerToWaitForFailure(
|
85
|
+
_handler: GestureHandler,
|
86
|
+
_otherHandler: GestureHandler
|
87
|
+
): boolean {
|
88
|
+
//TODO: Implement logic
|
89
|
+
return false;
|
90
|
+
}
|
91
|
+
|
92
|
+
public shouldHandlerBeCancelledBy(
|
93
|
+
_handler: GestureHandler,
|
94
|
+
_otherHandler: GestureHandler
|
95
|
+
): boolean {
|
96
|
+
//TODO: Implement logic
|
97
|
+
return false;
|
98
|
+
}
|
99
|
+
|
100
|
+
public dropRelationsForHandlerWithTag(handlerTag: number): void {
|
101
|
+
this.waitForRelations.delete(handlerTag);
|
102
|
+
this.simultaneousRelations.delete(handlerTag);
|
103
|
+
}
|
104
|
+
|
105
|
+
public reset() {
|
106
|
+
this.waitForRelations.clear();
|
107
|
+
this.simultaneousRelations.clear();
|
108
|
+
}
|
109
109
|
}
|
@@ -1,182 +1,182 @@
|
|
1
|
-
// Implementation taken from Flutter's LeastSquareSolver
|
2
|
-
// https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/lsq_solver.dart
|
3
|
-
|
4
|
-
class Vector {
|
5
|
-
private offset: number;
|
6
|
-
private length: number;
|
7
|
-
private elements: number[];
|
8
|
-
|
9
|
-
constructor(length: number) {
|
10
|
-
this.offset = 0;
|
11
|
-
this.length = length;
|
12
|
-
this.elements = new Array<number>(length);
|
13
|
-
}
|
14
|
-
|
15
|
-
public static fromVOL(
|
16
|
-
values: number[],
|
17
|
-
offset: number,
|
18
|
-
length: number
|
19
|
-
): Vector {
|
20
|
-
const result = new Vector(0);
|
21
|
-
|
22
|
-
result.offset = offset;
|
23
|
-
result.length = length;
|
24
|
-
result.elements = values;
|
25
|
-
|
26
|
-
return result;
|
27
|
-
}
|
28
|
-
|
29
|
-
public get(index: number): number {
|
30
|
-
return this.elements[this.offset + index];
|
31
|
-
}
|
32
|
-
|
33
|
-
public set(index: number, value: number): void {
|
34
|
-
this.elements[this.offset + index] = value;
|
35
|
-
}
|
36
|
-
|
37
|
-
public dot(other: Vector): number {
|
38
|
-
let result = 0;
|
39
|
-
for (let i = 0; i < this.length; i++) {
|
40
|
-
result += this.get(i) * other.get(i);
|
41
|
-
}
|
42
|
-
return result;
|
43
|
-
}
|
44
|
-
|
45
|
-
public norm() {
|
46
|
-
return Math.sqrt(this.dot(this));
|
47
|
-
}
|
48
|
-
}
|
49
|
-
|
50
|
-
class Matrix {
|
51
|
-
private columns: number;
|
52
|
-
private elements: number[];
|
53
|
-
|
54
|
-
constructor(rows: number, columns: number) {
|
55
|
-
this.columns = columns;
|
56
|
-
this.elements = new Array<number>(rows * columns);
|
57
|
-
}
|
58
|
-
|
59
|
-
public get(row: number, column: number): number {
|
60
|
-
return this.elements[row * this.columns + column];
|
61
|
-
}
|
62
|
-
|
63
|
-
public set(row: number, column: number, value: number): void {
|
64
|
-
this.elements[row * this.columns + column] = value;
|
65
|
-
}
|
66
|
-
|
67
|
-
public getRow(row: number): Vector {
|
68
|
-
return Vector.fromVOL(this.elements, row * this.columns, this.columns);
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
/// An nth degree polynomial fit to a dataset.
|
73
|
-
class PolynomialFit {
|
74
|
-
/// The polynomial coefficients of the fit.
|
75
|
-
///
|
76
|
-
/// For each `i`, the element `coefficients[i]` is the coefficient of
|
77
|
-
/// the `i`-th power of the variable.
|
78
|
-
public coefficients: number[];
|
79
|
-
|
80
|
-
/// Creates a polynomial fit of the given degree.
|
81
|
-
///
|
82
|
-
/// There are n + 1 coefficients in a fit of degree n.
|
83
|
-
constructor(degree: number) {
|
84
|
-
this.coefficients = new Array<number>(degree + 1);
|
85
|
-
}
|
86
|
-
}
|
87
|
-
|
88
|
-
const precisionErrorTolerance = 1e-10;
|
89
|
-
|
90
|
-
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
|
91
|
-
export class LeastSquareSolver {
|
92
|
-
/// The x-coordinates of each data point.
|
93
|
-
private x: number[];
|
94
|
-
/// The y-coordinates of each data point.
|
95
|
-
private y: number[];
|
96
|
-
/// The weight to use for each data point.
|
97
|
-
private w: number[];
|
98
|
-
|
99
|
-
/// Creates a least-squares solver.
|
100
|
-
///
|
101
|
-
/// The [x], [y], and [w] arguments must not be null.
|
102
|
-
constructor(x: number[], y: number[], w: number[]) {
|
103
|
-
this.x = x;
|
104
|
-
this.y = y;
|
105
|
-
this.w = w;
|
106
|
-
}
|
107
|
-
|
108
|
-
/// Fits a polynomial of the given degree to the data points.
|
109
|
-
///
|
110
|
-
/// When there is not enough data to fit a curve null is returned.
|
111
|
-
public solve(degree: number): PolynomialFit | null {
|
112
|
-
if (degree > this.x.length) {
|
113
|
-
// Not enough data to fit a curve.
|
114
|
-
return null;
|
115
|
-
}
|
116
|
-
|
117
|
-
const result = new PolynomialFit(degree);
|
118
|
-
|
119
|
-
// Shorthands for the purpose of notation equivalence to original C++ code.
|
120
|
-
const m = this.x.length;
|
121
|
-
const n = degree + 1;
|
122
|
-
|
123
|
-
// Expand the X vector to a matrix A, pre-multiplied by the weights.
|
124
|
-
const a = new Matrix(n, m);
|
125
|
-
for (let h = 0; h < m; h++) {
|
126
|
-
a.set(0, h, this.w[h]);
|
127
|
-
|
128
|
-
for (let i = 1; i < n; i++) {
|
129
|
-
a.set(i, h, a.get(i - 1, h) * this.x[h]);
|
130
|
-
}
|
131
|
-
}
|
132
|
-
|
133
|
-
// Apply the Gram-Schmidt process to A to obtain its QR decomposition.
|
134
|
-
|
135
|
-
// Orthonormal basis, column-major ordVectorer.
|
136
|
-
const q = new Matrix(n, m);
|
137
|
-
// Upper triangular matrix, row-major order.
|
138
|
-
const r = new Matrix(n, m);
|
139
|
-
|
140
|
-
for (let j = 0; j < n; j += 1) {
|
141
|
-
for (let h = 0; h < m; h += 1) {
|
142
|
-
q.set(j, h, a.get(j, h));
|
143
|
-
}
|
144
|
-
for (let i = 0; i < j; i += 1) {
|
145
|
-
const dot = q.getRow(j).dot(q.getRow(i));
|
146
|
-
for (let h = 0; h < m; h += 1) {
|
147
|
-
q.set(j, h, q.get(j, h) - dot * q.get(i, h));
|
148
|
-
}
|
149
|
-
}
|
150
|
-
|
151
|
-
const norm = q.getRow(j).norm();
|
152
|
-
if (norm < precisionErrorTolerance) {
|
153
|
-
// Vectors are linearly dependent or zero so no solution.
|
154
|
-
return null;
|
155
|
-
}
|
156
|
-
|
157
|
-
const inverseNorm = 1.0 / norm;
|
158
|
-
for (let h = 0; h < m; h += 1) {
|
159
|
-
q.set(j, h, q.get(j, h) * inverseNorm);
|
160
|
-
}
|
161
|
-
for (let i = 0; i < n; i += 1) {
|
162
|
-
r.set(j, i, i < j ? 0.0 : q.getRow(j).dot(a.getRow(i)));
|
163
|
-
}
|
164
|
-
}
|
165
|
-
|
166
|
-
// Solve R B = Qt W Y to find B. This is easy because R is upper triangular.
|
167
|
-
// We just work from bottom-right to top-left calculating B's coefficients.
|
168
|
-
const wy = new Vector(m);
|
169
|
-
for (let h = 0; h < m; h += 1) {
|
170
|
-
wy.set(h, this.y[h] * this.w[h]);
|
171
|
-
}
|
172
|
-
for (let i = n - 1; i >= 0; i -= 1) {
|
173
|
-
result.coefficients[i] = q.getRow(i).dot(wy);
|
174
|
-
for (let j = n - 1; j > i; j -= 1) {
|
175
|
-
result.coefficients[i] -= r.get(i, j) * result.coefficients[j];
|
176
|
-
}
|
177
|
-
result.coefficients[i] /= r.get(i, i);
|
178
|
-
}
|
179
|
-
|
180
|
-
return result;
|
181
|
-
}
|
182
|
-
}
|
1
|
+
// Implementation taken from Flutter's LeastSquareSolver
|
2
|
+
// https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/gestures/lsq_solver.dart
|
3
|
+
|
4
|
+
class Vector {
|
5
|
+
private offset: number;
|
6
|
+
private length: number;
|
7
|
+
private elements: number[];
|
8
|
+
|
9
|
+
constructor(length: number) {
|
10
|
+
this.offset = 0;
|
11
|
+
this.length = length;
|
12
|
+
this.elements = new Array<number>(length);
|
13
|
+
}
|
14
|
+
|
15
|
+
public static fromVOL(
|
16
|
+
values: number[],
|
17
|
+
offset: number,
|
18
|
+
length: number
|
19
|
+
): Vector {
|
20
|
+
const result = new Vector(0);
|
21
|
+
|
22
|
+
result.offset = offset;
|
23
|
+
result.length = length;
|
24
|
+
result.elements = values;
|
25
|
+
|
26
|
+
return result;
|
27
|
+
}
|
28
|
+
|
29
|
+
public get(index: number): number {
|
30
|
+
return this.elements[this.offset + index];
|
31
|
+
}
|
32
|
+
|
33
|
+
public set(index: number, value: number): void {
|
34
|
+
this.elements[this.offset + index] = value;
|
35
|
+
}
|
36
|
+
|
37
|
+
public dot(other: Vector): number {
|
38
|
+
let result = 0;
|
39
|
+
for (let i = 0; i < this.length; i++) {
|
40
|
+
result += this.get(i) * other.get(i);
|
41
|
+
}
|
42
|
+
return result;
|
43
|
+
}
|
44
|
+
|
45
|
+
public norm() {
|
46
|
+
return Math.sqrt(this.dot(this));
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
class Matrix {
|
51
|
+
private columns: number;
|
52
|
+
private elements: number[];
|
53
|
+
|
54
|
+
constructor(rows: number, columns: number) {
|
55
|
+
this.columns = columns;
|
56
|
+
this.elements = new Array<number>(rows * columns);
|
57
|
+
}
|
58
|
+
|
59
|
+
public get(row: number, column: number): number {
|
60
|
+
return this.elements[row * this.columns + column];
|
61
|
+
}
|
62
|
+
|
63
|
+
public set(row: number, column: number, value: number): void {
|
64
|
+
this.elements[row * this.columns + column] = value;
|
65
|
+
}
|
66
|
+
|
67
|
+
public getRow(row: number): Vector {
|
68
|
+
return Vector.fromVOL(this.elements, row * this.columns, this.columns);
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
/// An nth degree polynomial fit to a dataset.
|
73
|
+
class PolynomialFit {
|
74
|
+
/// The polynomial coefficients of the fit.
|
75
|
+
///
|
76
|
+
/// For each `i`, the element `coefficients[i]` is the coefficient of
|
77
|
+
/// the `i`-th power of the variable.
|
78
|
+
public coefficients: number[];
|
79
|
+
|
80
|
+
/// Creates a polynomial fit of the given degree.
|
81
|
+
///
|
82
|
+
/// There are n + 1 coefficients in a fit of degree n.
|
83
|
+
constructor(degree: number) {
|
84
|
+
this.coefficients = new Array<number>(degree + 1);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
const precisionErrorTolerance = 1e-10;
|
89
|
+
|
90
|
+
/// Uses the least-squares algorithm to fit a polynomial to a set of data.
|
91
|
+
export class LeastSquareSolver {
|
92
|
+
/// The x-coordinates of each data point.
|
93
|
+
private x: number[];
|
94
|
+
/// The y-coordinates of each data point.
|
95
|
+
private y: number[];
|
96
|
+
/// The weight to use for each data point.
|
97
|
+
private w: number[];
|
98
|
+
|
99
|
+
/// Creates a least-squares solver.
|
100
|
+
///
|
101
|
+
/// The [x], [y], and [w] arguments must not be null.
|
102
|
+
constructor(x: number[], y: number[], w: number[]) {
|
103
|
+
this.x = x;
|
104
|
+
this.y = y;
|
105
|
+
this.w = w;
|
106
|
+
}
|
107
|
+
|
108
|
+
/// Fits a polynomial of the given degree to the data points.
|
109
|
+
///
|
110
|
+
/// When there is not enough data to fit a curve null is returned.
|
111
|
+
public solve(degree: number): PolynomialFit | null {
|
112
|
+
if (degree > this.x.length) {
|
113
|
+
// Not enough data to fit a curve.
|
114
|
+
return null;
|
115
|
+
}
|
116
|
+
|
117
|
+
const result = new PolynomialFit(degree);
|
118
|
+
|
119
|
+
// Shorthands for the purpose of notation equivalence to original C++ code.
|
120
|
+
const m = this.x.length;
|
121
|
+
const n = degree + 1;
|
122
|
+
|
123
|
+
// Expand the X vector to a matrix A, pre-multiplied by the weights.
|
124
|
+
const a = new Matrix(n, m);
|
125
|
+
for (let h = 0; h < m; h++) {
|
126
|
+
a.set(0, h, this.w[h]);
|
127
|
+
|
128
|
+
for (let i = 1; i < n; i++) {
|
129
|
+
a.set(i, h, a.get(i - 1, h) * this.x[h]);
|
130
|
+
}
|
131
|
+
}
|
132
|
+
|
133
|
+
// Apply the Gram-Schmidt process to A to obtain its QR decomposition.
|
134
|
+
|
135
|
+
// Orthonormal basis, column-major ordVectorer.
|
136
|
+
const q = new Matrix(n, m);
|
137
|
+
// Upper triangular matrix, row-major order.
|
138
|
+
const r = new Matrix(n, m);
|
139
|
+
|
140
|
+
for (let j = 0; j < n; j += 1) {
|
141
|
+
for (let h = 0; h < m; h += 1) {
|
142
|
+
q.set(j, h, a.get(j, h));
|
143
|
+
}
|
144
|
+
for (let i = 0; i < j; i += 1) {
|
145
|
+
const dot = q.getRow(j).dot(q.getRow(i));
|
146
|
+
for (let h = 0; h < m; h += 1) {
|
147
|
+
q.set(j, h, q.get(j, h) - dot * q.get(i, h));
|
148
|
+
}
|
149
|
+
}
|
150
|
+
|
151
|
+
const norm = q.getRow(j).norm();
|
152
|
+
if (norm < precisionErrorTolerance) {
|
153
|
+
// Vectors are linearly dependent or zero so no solution.
|
154
|
+
return null;
|
155
|
+
}
|
156
|
+
|
157
|
+
const inverseNorm = 1.0 / norm;
|
158
|
+
for (let h = 0; h < m; h += 1) {
|
159
|
+
q.set(j, h, q.get(j, h) * inverseNorm);
|
160
|
+
}
|
161
|
+
for (let i = 0; i < n; i += 1) {
|
162
|
+
r.set(j, i, i < j ? 0.0 : q.getRow(j).dot(a.getRow(i)));
|
163
|
+
}
|
164
|
+
}
|
165
|
+
|
166
|
+
// Solve R B = Qt W Y to find B. This is easy because R is upper triangular.
|
167
|
+
// We just work from bottom-right to top-left calculating B's coefficients.
|
168
|
+
const wy = new Vector(m);
|
169
|
+
for (let h = 0; h < m; h += 1) {
|
170
|
+
wy.set(h, this.y[h] * this.w[h]);
|
171
|
+
}
|
172
|
+
for (let i = n - 1; i >= 0; i -= 1) {
|
173
|
+
result.coefficients[i] = q.getRow(i).dot(wy);
|
174
|
+
for (let j = n - 1; j > i; j -= 1) {
|
175
|
+
result.coefficients[i] -= r.get(i, j) * result.coefficients[j];
|
176
|
+
}
|
177
|
+
result.coefficients[i] /= r.get(i, i);
|
178
|
+
}
|
179
|
+
|
180
|
+
return result;
|
181
|
+
}
|
182
|
+
}
|