react-native-gesture-handler 2.15.0 → 2.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNGestureHandler.podspec +2 -23
- package/android/build.gradle +1 -1
- package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt +2 -0
- package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerDelegate.java +9 -0
- package/android/paper/src/main/java/com/facebook/react/viewmanagers/RNGestureHandlerButtonManagerInterface.java +3 -0
- package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +11 -6
- package/android/src/main/java/com/swmansion/gesturehandler/core/DiagonalDirections.kt +8 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +65 -24
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +86 -22
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +54 -29
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +3 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/LongPressGestureHandler.kt +5 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/PanGestureHandler.kt +5 -1
- package/android/src/main/java/com/swmansion/gesturehandler/core/TapGestureHandler.kt +7 -3
- package/android/src/main/java/com/swmansion/gesturehandler/core/Vector.kt +66 -0
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerButtonViewManager.kt +119 -19
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEvent.kt +1 -4
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +8 -5
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +7 -4
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt +1 -1
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt +1 -4
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt +4 -7
- package/android/src/main/java/com/swmansion/gesturehandler/react/eventbuilders/GestureHandlerEventDataBuilder.kt +3 -0
- package/android/src/main/jni/cpp-adapter.cpp +18 -22
- package/apple/Handlers/RNFlingHandler.m +5 -4
- package/apple/Handlers/RNForceTouchHandler.m +3 -1
- package/apple/Handlers/RNHoverHandler.m +2 -1
- package/apple/Handlers/RNLongPressHandler.m +8 -14
- package/apple/Handlers/RNManualHandler.m +1 -0
- package/apple/Handlers/RNNativeViewHandler.mm +9 -7
- package/apple/Handlers/RNPanHandler.m +7 -2
- package/apple/Handlers/RNPinchHandler.m +50 -26
- package/apple/Handlers/RNRotationHandler.m +43 -29
- package/apple/Handlers/RNTapHandler.m +6 -4
- package/apple/RNGestureHandler.h +9 -0
- package/apple/RNGestureHandler.m +41 -4
- package/apple/RNGestureHandlerEvents.h +18 -9
- package/apple/RNGestureHandlerEvents.m +29 -11
- package/apple/RNGestureHandlerManager.h +5 -0
- package/apple/RNGestureHandlerManager.mm +32 -6
- package/apple/RNGestureHandlerModule.h +5 -3
- package/apple/RNGestureHandlerModule.mm +33 -19
- package/apple/RNGestureHandlerPointerType.h +8 -0
- package/lib/commonjs/Directions.js +19 -6
- package/lib/commonjs/Directions.js.map +1 -1
- package/lib/commonjs/PointerType.js +16 -0
- package/lib/commonjs/PointerType.js.map +1 -0
- package/lib/commonjs/RNGestureHandlerModule.web.js +7 -61
- package/lib/commonjs/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/commonjs/components/DrawerLayout.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.android.js +17 -2
- package/lib/commonjs/components/GestureHandlerRootView.android.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.js +15 -2
- package/lib/commonjs/components/GestureHandlerRootView.js.map +1 -1
- package/lib/commonjs/components/GestureHandlerRootView.web.js +15 -2
- package/lib/commonjs/components/GestureHandlerRootView.web.js.map +1 -1
- package/lib/commonjs/components/Swipeable.js +3 -1
- package/lib/commonjs/components/Swipeable.js.map +1 -1
- package/lib/commonjs/components/touchables/GenericTouchable.js +1 -0
- package/lib/commonjs/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/commonjs/getShadowNodeFromRef.js +19 -2
- package/lib/commonjs/getShadowNodeFromRef.js.map +1 -1
- package/lib/commonjs/handlers/createHandler.js +5 -0
- package/lib/commonjs/handlers/createHandler.js.map +1 -1
- package/lib/commonjs/handlers/customDirectEventTypes.js +14 -0
- package/lib/commonjs/handlers/customDirectEventTypes.js.map +1 -0
- package/lib/commonjs/handlers/customDirectEventTypes.web.js +11 -0
- package/lib/commonjs/handlers/customDirectEventTypes.web.js.map +1 -0
- package/lib/commonjs/handlers/gestureHandlerCommon.js +13 -2
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +10 -0
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/index.js +11 -3
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/mocks.js +2 -0
- package/lib/commonjs/mocks.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/commonjs/web/Gestures.js +66 -0
- package/lib/commonjs/web/Gestures.js.map +1 -0
- package/lib/commonjs/web/constants.js +3 -8
- package/lib/commonjs/web/constants.js.map +1 -1
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +36 -12
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +10 -5
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/IGestureHandler.js +2 -0
- package/lib/commonjs/web/handlers/IGestureHandler.js.map +1 -0
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js +5 -6
- package/lib/commonjs/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js +1 -23
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/EventManager.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +117 -118
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +10 -5
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/InteractionManager.js +12 -3
- package/lib/commonjs/web/tools/InteractionManager.js.map +1 -1
- package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
- package/lib/commonjs/web/tools/PointerEventManager.js +77 -27
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +29 -6
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/Vector.js +58 -0
- package/lib/commonjs/web/tools/Vector.js.map +1 -0
- package/lib/commonjs/web/utils.js +14 -0
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/commonjs/web_hammer/NodeManager.js.map +1 -1
- package/lib/module/Directions.js +16 -4
- package/lib/module/Directions.js.map +1 -1
- package/lib/module/PointerType.js +9 -0
- package/lib/module/PointerType.js.map +1 -0
- package/lib/module/RNGestureHandlerModule.web.js +2 -39
- package/lib/module/RNGestureHandlerModule.web.js.map +1 -1
- package/lib/module/components/DrawerLayout.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.android.js +15 -2
- package/lib/module/components/GestureHandlerRootView.android.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.js +15 -3
- package/lib/module/components/GestureHandlerRootView.js.map +1 -1
- package/lib/module/components/GestureHandlerRootView.web.js +15 -3
- package/lib/module/components/GestureHandlerRootView.web.js.map +1 -1
- package/lib/module/components/Swipeable.js +3 -1
- package/lib/module/components/Swipeable.js.map +1 -1
- package/lib/module/components/touchables/GenericTouchable.js +1 -0
- package/lib/module/components/touchables/GenericTouchable.js.map +1 -1
- package/lib/module/getShadowNodeFromRef.js +19 -2
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/handlers/createHandler.js +5 -1
- package/lib/module/handlers/createHandler.js.map +1 -1
- package/lib/module/handlers/customDirectEventTypes.js +3 -0
- package/lib/module/handlers/customDirectEventTypes.js.map +1 -0
- package/lib/module/handlers/customDirectEventTypes.web.js +5 -0
- package/lib/module/handlers/customDirectEventTypes.web.js.map +1 -0
- package/lib/module/handlers/gestureHandlerCommon.js +11 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +10 -0
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/mocks.js +2 -0
- package/lib/module/mocks.js.map +1 -1
- package/lib/module/specs/NativeRNGestureHandlerModule.js.map +1 -1
- package/lib/module/specs/RNGestureHandlerButtonNativeComponent.js.map +1 -1
- package/lib/module/web/Gestures.js +39 -0
- package/lib/module/web/Gestures.js.map +1 -0
- package/lib/module/web/constants.js +1 -6
- package/lib/module/web/constants.js.map +1 -1
- package/lib/module/web/handlers/FlingGestureHandler.js +34 -12
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +7 -4
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/IGestureHandler.js +2 -0
- package/lib/module/web/handlers/IGestureHandler.js.map +1 -0
- package/lib/module/web/handlers/NativeViewGestureHandler.js +5 -6
- package/lib/module/web/handlers/NativeViewGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js +0 -20
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/EventManager.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerOrchestrator.js +116 -117
- package/lib/module/web/tools/GestureHandlerOrchestrator.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +9 -4
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/InteractionManager.js +9 -3
- package/lib/module/web/tools/InteractionManager.js.map +1 -1
- package/lib/module/web/tools/NodeManager.js.map +1 -1
- package/lib/module/web/tools/PointerEventManager.js +75 -27
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +28 -6
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/web/tools/Vector.js +47 -0
- package/lib/module/web/tools/Vector.js.map +1 -0
- package/lib/module/web/utils.js +4 -0
- package/lib/module/web/utils.js.map +1 -1
- package/lib/module/web_hammer/NodeManager.js.map +1 -1
- package/lib/typescript/Directions.d.ts +7 -0
- package/lib/typescript/PointerType.d.ts +6 -0
- package/lib/typescript/RNGestureHandlerModule.web.d.ts +4 -39
- package/lib/typescript/components/DrawerLayout.d.ts +1 -2
- package/lib/typescript/components/GestureHandlerRootView.android.d.ts +1 -1
- package/lib/typescript/components/GestureHandlerRootView.d.ts +1 -1
- package/lib/typescript/components/GestureHandlerRootView.web.d.ts +1 -1
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +2 -1
- package/lib/typescript/getShadowNodeFromRef.d.ts +1 -1
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/customDirectEventTypes.d.ts +1 -0
- package/lib/typescript/handlers/customDirectEventTypes.web.d.ts +2 -0
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +13 -2
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +1 -2
- package/lib/typescript/index.d.ts +2 -1
- package/lib/typescript/mocks.d.ts +1 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +6 -6
- package/lib/typescript/specs/RNGestureHandlerButtonNativeComponent.d.ts +4 -1
- package/lib/typescript/web/Gestures.d.ts +36 -0
- package/lib/typescript/web/constants.d.ts +1 -6
- package/lib/typescript/web/handlers/FlingGestureHandler.d.ts +3 -3
- package/lib/typescript/web/handlers/GestureHandler.d.ts +12 -9
- package/lib/typescript/web/handlers/IGestureHandler.d.ts +38 -0
- package/lib/typescript/web/handlers/NativeViewGestureHandler.d.ts +1 -0
- package/lib/typescript/web/interfaces.d.ts +9 -16
- package/lib/typescript/web/tools/EventManager.d.ts +15 -12
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +3 -4
- package/lib/typescript/web/tools/GestureHandlerOrchestrator.d.ts +7 -5
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +3 -3
- package/lib/typescript/web/tools/InteractionManager.d.ts +6 -6
- package/lib/typescript/web/tools/NodeManager.d.ts +4 -3
- package/lib/typescript/web/tools/PointerEventManager.d.ts +11 -2
- package/lib/typescript/web/tools/TouchEventManager.d.ts +6 -1
- package/lib/typescript/web/tools/Vector.d.ts +15 -0
- package/lib/typescript/web/utils.d.ts +6 -4
- package/lib/typescript/web_hammer/NodeManager.d.ts +1 -1
- package/package.json +2 -1
- package/src/Directions.ts +21 -4
- package/src/PointerType.ts +6 -0
- package/src/RNGestureHandlerModule.web.ts +3 -44
- package/src/components/DrawerLayout.tsx +1 -1
- package/src/components/GestureHandlerRootView.android.tsx +13 -5
- package/src/components/GestureHandlerRootView.tsx +10 -5
- package/src/components/GestureHandlerRootView.web.tsx +10 -5
- package/src/components/Swipeable.tsx +2 -0
- package/src/components/touchables/GenericTouchable.tsx +3 -0
- package/src/getShadowNodeFromRef.ts +28 -6
- package/src/handlers/createHandler.tsx +14 -2
- package/src/handlers/customDirectEventTypes.ts +2 -0
- package/src/handlers/customDirectEventTypes.web.ts +5 -0
- package/src/handlers/gestureHandlerCommon.ts +30 -1
- package/src/handlers/gestures/GestureDetector.tsx +15 -0
- package/src/handlers/gestures/gesture.ts +1 -1
- package/src/index.ts +2 -1
- package/src/mocks.ts +2 -0
- package/src/specs/NativeRNGestureHandlerModule.ts +8 -8
- package/src/specs/RNGestureHandlerButtonNativeComponent.ts +4 -0
- package/src/web/Gestures.ts +41 -0
- package/src/web/constants.ts +1 -7
- package/src/web/handlers/FlingGestureHandler.ts +54 -24
- package/src/web/handlers/GestureHandler.ts +17 -12
- package/src/web/handlers/IGestureHandler.ts +50 -0
- package/src/web/handlers/NativeViewGestureHandler.ts +5 -6
- package/src/web/interfaces.ts +15 -17
- package/src/web/tools/EventManager.ts +16 -14
- package/src/web/tools/GestureHandlerDelegate.ts +3 -4
- package/src/web/tools/GestureHandlerOrchestrator.ts +162 -147
- package/src/web/tools/GestureHandlerWebDelegate.ts +14 -9
- package/src/web/tools/InteractionManager.ts +18 -12
- package/src/web/tools/NodeManager.ts +4 -3
- package/src/web/tools/PointerEventManager.ts +189 -154
- package/src/web/tools/TouchEventManager.ts +128 -120
- package/src/web/tools/Vector.ts +60 -0
- package/src/web/utils.ts +16 -4
- package/src/web_hammer/NodeManager.ts +1 -1
|
@@ -208,6 +208,10 @@ class PanGestureHandler(context: Context?) : GestureHandler<PanGestureHandler>()
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
|
|
211
|
+
if (!shouldActivateWithMouse(sourceEvent)) {
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
|
|
211
215
|
val state = state
|
|
212
216
|
val action = sourceEvent.actionMasked
|
|
213
217
|
if (action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN) {
|
|
@@ -246,7 +250,7 @@ class PanGestureHandler(context: Context?) : GestureHandler<PanGestureHandler>()
|
|
|
246
250
|
velocityX = velocityTracker!!.xVelocity
|
|
247
251
|
velocityY = velocityTracker!!.yVelocity
|
|
248
252
|
}
|
|
249
|
-
if (action == MotionEvent.ACTION_UP) {
|
|
253
|
+
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_BUTTON_RELEASE) {
|
|
250
254
|
if (state == STATE_ACTIVE) {
|
|
251
255
|
end()
|
|
252
256
|
} else {
|
|
@@ -105,6 +105,10 @@ class TapGestureHandler : GestureHandler<TapGestureHandler>() {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
|
|
108
|
+
if (!shouldActivateWithMouse(sourceEvent)) {
|
|
109
|
+
return
|
|
110
|
+
}
|
|
111
|
+
|
|
108
112
|
val state = state
|
|
109
113
|
val action = sourceEvent.actionMasked
|
|
110
114
|
if (state == STATE_UNDETERMINED) {
|
|
@@ -130,14 +134,14 @@ class TapGestureHandler : GestureHandler<TapGestureHandler>() {
|
|
|
130
134
|
if (shouldFail()) {
|
|
131
135
|
fail()
|
|
132
136
|
} else if (state == STATE_UNDETERMINED) {
|
|
133
|
-
if (action == MotionEvent.ACTION_DOWN) {
|
|
137
|
+
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_BUTTON_PRESS) {
|
|
134
138
|
begin()
|
|
135
139
|
}
|
|
136
140
|
startTap()
|
|
137
141
|
} else if (state == STATE_BEGAN) {
|
|
138
|
-
if (action == MotionEvent.ACTION_UP) {
|
|
142
|
+
if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_BUTTON_RELEASE) {
|
|
139
143
|
endTap()
|
|
140
|
-
} else if (action == MotionEvent.ACTION_DOWN) {
|
|
144
|
+
} else if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_BUTTON_PRESS) {
|
|
141
145
|
startTap()
|
|
142
146
|
}
|
|
143
147
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
package com.swmansion.gesturehandler.core
|
|
2
|
+
|
|
3
|
+
import android.view.VelocityTracker
|
|
4
|
+
import com.swmansion.gesturehandler.core.GestureHandler.Companion.DIRECTION_DOWN
|
|
5
|
+
import com.swmansion.gesturehandler.core.GestureHandler.Companion.DIRECTION_LEFT
|
|
6
|
+
import com.swmansion.gesturehandler.core.GestureHandler.Companion.DIRECTION_RIGHT
|
|
7
|
+
import com.swmansion.gesturehandler.core.GestureHandler.Companion.DIRECTION_UP
|
|
8
|
+
import kotlin.math.hypot
|
|
9
|
+
|
|
10
|
+
class Vector(val x: Double, val y: Double) {
|
|
11
|
+
private val unitX: Double
|
|
12
|
+
private val unitY: Double
|
|
13
|
+
val magnitude = hypot(x, y)
|
|
14
|
+
|
|
15
|
+
init {
|
|
16
|
+
val isMagnitudeSufficient = magnitude > MINIMAL_MAGNITUDE
|
|
17
|
+
|
|
18
|
+
unitX = if (isMagnitudeSufficient) x / magnitude else 0.0
|
|
19
|
+
unitY = if (isMagnitudeSufficient) y / magnitude else 0.0
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
private fun computeSimilarity(vector: Vector): Double {
|
|
23
|
+
return unitX * vector.unitX + unitY * vector.unitY
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
fun isSimilar(vector: Vector, threshold: Double): Boolean {
|
|
27
|
+
return computeSimilarity(vector) > threshold
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
companion object {
|
|
31
|
+
private val VECTOR_LEFT: Vector = Vector(-1.0, 0.0)
|
|
32
|
+
private val VECTOR_RIGHT: Vector = Vector(1.0, 0.0)
|
|
33
|
+
private val VECTOR_UP: Vector = Vector(0.0, -1.0)
|
|
34
|
+
private val VECTOR_DOWN: Vector = Vector(0.0, 1.0)
|
|
35
|
+
|
|
36
|
+
private val VECTOR_RIGHT_UP: Vector = Vector(1.0, -1.0)
|
|
37
|
+
private val VECTOR_RIGHT_DOWN: Vector = Vector(1.0, 1.0)
|
|
38
|
+
private val VECTOR_LEFT_UP: Vector = Vector(-1.0, -1.0)
|
|
39
|
+
private val VECTOR_LEFT_DOWN: Vector = Vector(-1.0, 1.0)
|
|
40
|
+
|
|
41
|
+
private val VECTOR_ZERO: Vector = Vector(0.0, 0.0)
|
|
42
|
+
private const val MINIMAL_MAGNITUDE = 0.1
|
|
43
|
+
|
|
44
|
+
fun fromDirection(direction: Int): Vector =
|
|
45
|
+
when (direction) {
|
|
46
|
+
DIRECTION_LEFT -> VECTOR_LEFT
|
|
47
|
+
DIRECTION_RIGHT -> VECTOR_RIGHT
|
|
48
|
+
DIRECTION_UP -> VECTOR_UP
|
|
49
|
+
DIRECTION_DOWN -> VECTOR_DOWN
|
|
50
|
+
DiagonalDirections.DIRECTION_RIGHT_UP -> VECTOR_RIGHT_UP
|
|
51
|
+
DiagonalDirections.DIRECTION_RIGHT_DOWN -> VECTOR_RIGHT_DOWN
|
|
52
|
+
DiagonalDirections.DIRECTION_LEFT_UP -> VECTOR_LEFT_UP
|
|
53
|
+
DiagonalDirections.DIRECTION_LEFT_DOWN -> VECTOR_LEFT_DOWN
|
|
54
|
+
else -> VECTOR_ZERO
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
fun fromVelocity(tracker: VelocityTracker): Vector {
|
|
58
|
+
tracker.computeCurrentVelocity(1000)
|
|
59
|
+
|
|
60
|
+
val velocityX = tracker.xVelocity.toDouble()
|
|
61
|
+
val velocityY = tracker.yVelocity.toDouble()
|
|
62
|
+
|
|
63
|
+
return Vector(velocityX, velocityY)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
@@ -5,6 +5,9 @@ import android.annotation.TargetApi
|
|
|
5
5
|
import android.content.Context
|
|
6
6
|
import android.content.res.ColorStateList
|
|
7
7
|
import android.graphics.Color
|
|
8
|
+
import android.graphics.DashPathEffect
|
|
9
|
+
import android.graphics.Paint
|
|
10
|
+
import android.graphics.PathEffect
|
|
8
11
|
import android.graphics.drawable.Drawable
|
|
9
12
|
import android.graphics.drawable.LayerDrawable
|
|
10
13
|
import android.graphics.drawable.PaintDrawable
|
|
@@ -65,6 +68,41 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
|
65
68
|
view.borderRadius = borderRadius
|
|
66
69
|
}
|
|
67
70
|
|
|
71
|
+
@ReactProp(name = "borderTopLeftRadius")
|
|
72
|
+
override fun setBorderTopLeftRadius(view: ButtonViewGroup, borderTopLeftRadius: Float) {
|
|
73
|
+
view.borderTopLeftRadius = borderTopLeftRadius
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@ReactProp(name = "borderTopRightRadius")
|
|
77
|
+
override fun setBorderTopRightRadius(view: ButtonViewGroup, borderTopRightRadius: Float) {
|
|
78
|
+
view.borderTopRightRadius = borderTopRightRadius
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@ReactProp(name = "borderBottomLeftRadius")
|
|
82
|
+
override fun setBorderBottomLeftRadius(view: ButtonViewGroup, borderBottomLeftRadius: Float) {
|
|
83
|
+
view.borderBottomLeftRadius = borderBottomLeftRadius
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@ReactProp(name = "borderBottomRightRadius")
|
|
87
|
+
override fun setBorderBottomRightRadius(view: ButtonViewGroup, borderBottomRightRadius: Float) {
|
|
88
|
+
view.borderBottomRightRadius = borderBottomRightRadius
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
@ReactProp(name = "borderWidth")
|
|
92
|
+
override fun setBorderWidth(view: ButtonViewGroup, borderWidth: Float) {
|
|
93
|
+
view.borderWidth = borderWidth
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
@ReactProp(name = "borderColor")
|
|
97
|
+
override fun setBorderColor(view: ButtonViewGroup, borderColor: Int?) {
|
|
98
|
+
view.borderColor = borderColor
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@ReactProp(name = "borderStyle")
|
|
102
|
+
override fun setBorderStyle(view: ButtonViewGroup, borderStyle: String?) {
|
|
103
|
+
view.borderStyle = borderStyle
|
|
104
|
+
}
|
|
105
|
+
|
|
68
106
|
@ReactProp(name = "rippleColor")
|
|
69
107
|
override fun setRippleColor(view: ButtonViewGroup, rippleColor: Int?) {
|
|
70
108
|
view.rippleColor = rippleColor
|
|
@@ -115,6 +153,42 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
|
115
153
|
set(radius) = withBackgroundUpdate {
|
|
116
154
|
field = radius * resources.displayMetrics.density
|
|
117
155
|
}
|
|
156
|
+
var borderTopLeftRadius = 0f
|
|
157
|
+
set(radius) = withBackgroundUpdate {
|
|
158
|
+
field = radius * resources.displayMetrics.density
|
|
159
|
+
}
|
|
160
|
+
var borderTopRightRadius = 0f
|
|
161
|
+
set(radius) = withBackgroundUpdate {
|
|
162
|
+
field = radius * resources.displayMetrics.density
|
|
163
|
+
}
|
|
164
|
+
var borderBottomLeftRadius = 0f
|
|
165
|
+
set(radius) = withBackgroundUpdate {
|
|
166
|
+
field = radius * resources.displayMetrics.density
|
|
167
|
+
}
|
|
168
|
+
var borderBottomRightRadius = 0f
|
|
169
|
+
set(radius) = withBackgroundUpdate {
|
|
170
|
+
field = radius * resources.displayMetrics.density
|
|
171
|
+
}
|
|
172
|
+
var borderWidth = 0f
|
|
173
|
+
set(width) = withBackgroundUpdate {
|
|
174
|
+
field = width * resources.displayMetrics.density
|
|
175
|
+
}
|
|
176
|
+
var borderColor: Int? = null
|
|
177
|
+
set(color) = withBackgroundUpdate {
|
|
178
|
+
field = color
|
|
179
|
+
}
|
|
180
|
+
var borderStyle: String? = "solid"
|
|
181
|
+
set(style) = withBackgroundUpdate {
|
|
182
|
+
field = style
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private val hasBorderRadii: Boolean
|
|
186
|
+
get() = borderRadius != 0f ||
|
|
187
|
+
borderTopLeftRadius != 0f ||
|
|
188
|
+
borderTopRightRadius != 0f ||
|
|
189
|
+
borderBottomLeftRadius != 0f ||
|
|
190
|
+
borderBottomRightRadius != 0f
|
|
191
|
+
|
|
118
192
|
var exclusive = true
|
|
119
193
|
|
|
120
194
|
private var _backgroundColor = Color.TRANSPARENT
|
|
@@ -139,6 +213,30 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
|
139
213
|
needBackgroundUpdate = true
|
|
140
214
|
}
|
|
141
215
|
|
|
216
|
+
private fun buildBorderRadii(): FloatArray {
|
|
217
|
+
// duplicate radius for each corner, as setCornerRadii expects X radius and Y radius for each
|
|
218
|
+
return floatArrayOf(
|
|
219
|
+
borderTopLeftRadius,
|
|
220
|
+
borderTopLeftRadius,
|
|
221
|
+
borderTopRightRadius,
|
|
222
|
+
borderTopRightRadius,
|
|
223
|
+
borderBottomRightRadius,
|
|
224
|
+
borderBottomRightRadius,
|
|
225
|
+
borderBottomLeftRadius,
|
|
226
|
+
borderBottomLeftRadius,
|
|
227
|
+
)
|
|
228
|
+
.map { if (it != 0f) it else borderRadius }
|
|
229
|
+
.toFloatArray()
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
private fun buildBorderStyle(): PathEffect? {
|
|
233
|
+
return when (borderStyle) {
|
|
234
|
+
"dotted" -> DashPathEffect(floatArrayOf(borderWidth, borderWidth, borderWidth, borderWidth), 0f)
|
|
235
|
+
"dashed" -> DashPathEffect(floatArrayOf(borderWidth * 3, borderWidth * 3, borderWidth * 3, borderWidth * 3), 0f)
|
|
236
|
+
else -> null
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
142
240
|
override fun setBackgroundColor(color: Int) = withBackgroundUpdate {
|
|
143
241
|
_backgroundColor = color
|
|
144
242
|
}
|
|
@@ -188,14 +286,25 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
|
188
286
|
return false
|
|
189
287
|
}
|
|
190
288
|
|
|
191
|
-
private fun updateBackgroundColor(backgroundColor: Int,
|
|
289
|
+
private fun updateBackgroundColor(backgroundColor: Int, selectable: Drawable?) {
|
|
192
290
|
val colorDrawable = PaintDrawable(backgroundColor)
|
|
291
|
+
val borderDrawable = PaintDrawable(Color.TRANSPARENT)
|
|
193
292
|
|
|
194
|
-
if (
|
|
195
|
-
colorDrawable.
|
|
293
|
+
if (hasBorderRadii) {
|
|
294
|
+
colorDrawable.setCornerRadii(buildBorderRadii())
|
|
295
|
+
borderDrawable.setCornerRadii(buildBorderRadii())
|
|
196
296
|
}
|
|
197
297
|
|
|
198
|
-
|
|
298
|
+
if (borderWidth > 0f) {
|
|
299
|
+
borderDrawable.paint.apply {
|
|
300
|
+
style = Paint.Style.STROKE
|
|
301
|
+
strokeWidth = borderWidth
|
|
302
|
+
color = borderColor ?: Color.BLACK
|
|
303
|
+
pathEffect = buildBorderStyle()
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
val layerDrawable = LayerDrawable(if (selectable != null) arrayOf(colorDrawable, selectable, borderDrawable) else arrayOf(colorDrawable, borderDrawable))
|
|
199
308
|
background = layerDrawable
|
|
200
309
|
}
|
|
201
310
|
|
|
@@ -216,30 +325,21 @@ class RNGestureHandlerButtonViewManager : ViewGroupManager<ButtonViewGroup>(), R
|
|
|
216
325
|
|
|
217
326
|
val selectable = createSelectableDrawable()
|
|
218
327
|
|
|
219
|
-
if (
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
// fine for button-related use cases.
|
|
224
|
-
// Therefore it might be used as long as:
|
|
225
|
-
// 1. ReactViewManager is not a generic class with a possibility to handle another ViewGroup
|
|
226
|
-
// 2. There's no way to force native behavior of ReactViewGroup's superclass's onTouchEvent
|
|
227
|
-
if (selectable is RippleDrawable) {
|
|
228
|
-
val mask = PaintDrawable(Color.WHITE)
|
|
229
|
-
mask.setCornerRadius(borderRadius)
|
|
230
|
-
selectable.setDrawableByLayerId(android.R.id.mask, mask)
|
|
231
|
-
}
|
|
328
|
+
if (hasBorderRadii && selectable is RippleDrawable) {
|
|
329
|
+
val mask = PaintDrawable(Color.WHITE)
|
|
330
|
+
mask.setCornerRadii(buildBorderRadii())
|
|
331
|
+
selectable.setDrawableByLayerId(android.R.id.mask, mask)
|
|
232
332
|
}
|
|
233
333
|
|
|
234
334
|
if (useDrawableOnForeground && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
235
335
|
foreground = selectable
|
|
236
336
|
if (_backgroundColor != Color.TRANSPARENT) {
|
|
237
|
-
updateBackgroundColor(_backgroundColor,
|
|
337
|
+
updateBackgroundColor(_backgroundColor, null)
|
|
238
338
|
}
|
|
239
339
|
} else if (_backgroundColor == Color.TRANSPARENT && rippleColor == null) {
|
|
240
340
|
background = selectable
|
|
241
341
|
} else {
|
|
242
|
-
updateBackgroundColor(_backgroundColor,
|
|
342
|
+
updateBackgroundColor(_backgroundColor, selectable)
|
|
243
343
|
}
|
|
244
344
|
}
|
|
245
345
|
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerEnabledRootView.kt
CHANGED
|
@@ -6,8 +6,8 @@ import com.facebook.react.ReactRootView
|
|
|
6
6
|
|
|
7
7
|
@Deprecated(message = "Use <GestureHandlerRootView /> component instead. Check gesture handler installation instructions in documentation for more information.")
|
|
8
8
|
class RNGestureHandlerEnabledRootView : ReactRootView {
|
|
9
|
-
constructor(context: Context?) : super(context)
|
|
10
|
-
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
|
9
|
+
constructor(context: Context?) : super(context)
|
|
10
|
+
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs)
|
|
11
11
|
|
|
12
12
|
init {
|
|
13
13
|
throw UnsupportedOperationException("Your application is configured to use RNGestureHandlerEnabledRootView which is no longer supported. You can see how to migrate to <GestureHandlerRootView /> here: https://docs.swmansion.com/react-native-gesture-handler/docs/guides/migrating-off-rnghenabledroot")
|
|
@@ -10,7 +10,6 @@ import androidx.core.util.Pools
|
|
|
10
10
|
import com.facebook.react.bridge.Arguments
|
|
11
11
|
import com.facebook.react.bridge.WritableMap
|
|
12
12
|
import com.facebook.react.uimanager.events.Event
|
|
13
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
14
13
|
import com.swmansion.gesturehandler.core.GestureHandler
|
|
15
14
|
import com.swmansion.gesturehandler.react.eventbuilders.GestureHandlerEventDataBuilder
|
|
16
15
|
|
|
@@ -47,9 +46,7 @@ class RNGestureHandlerEvent private constructor() : Event<RNGestureHandlerEvent>
|
|
|
47
46
|
|
|
48
47
|
override fun getCoalescingKey() = coalescingKey
|
|
49
48
|
|
|
50
|
-
override fun
|
|
51
|
-
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, createEventData(dataBuilder!!))
|
|
52
|
-
}
|
|
49
|
+
override fun getEventData(): WritableMap = createEventData(dataBuilder!!)
|
|
53
50
|
|
|
54
51
|
companion object {
|
|
55
52
|
const val EVENT_NAME = "onGestureHandlerEvent"
|
|
@@ -47,7 +47,7 @@ import com.swmansion.gesturehandler.react.eventbuilders.TapGestureHandlerEventDa
|
|
|
47
47
|
// UIManagerModule.resolveRootTagFromReactTag() was deprecated and will be removed in the next RN release
|
|
48
48
|
// ref: https://github.com/facebook/react-native/commit/acbf9e18ea666b07c1224a324602a41d0a66985e
|
|
49
49
|
@Suppress("DEPRECATION")
|
|
50
|
-
@ReactModule(name = RNGestureHandlerModule.
|
|
50
|
+
@ReactModule(name = RNGestureHandlerModule.NAME)
|
|
51
51
|
class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
52
52
|
NativeRNGestureHandlerModuleSpec(reactContext), GestureHandlerStateManager {
|
|
53
53
|
private abstract class HandlerFactory<T : GestureHandler<T>> {
|
|
@@ -71,6 +71,9 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
|
71
71
|
if (config.hasKey(KEY_MANUAL_ACTIVATION)) {
|
|
72
72
|
handler.setManualActivation(config.getBoolean(KEY_MANUAL_ACTIVATION))
|
|
73
73
|
}
|
|
74
|
+
if (config.hasKey("mouseButton")) {
|
|
75
|
+
handler.setMouseButton(config.getInt("mouseButton"))
|
|
76
|
+
}
|
|
74
77
|
}
|
|
75
78
|
|
|
76
79
|
abstract fun createEventBuilder(handler: T): GestureHandlerEventDataBuilder<T>
|
|
@@ -331,7 +334,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
|
331
334
|
private val interactionManager = RNGestureHandlerInteractionManager()
|
|
332
335
|
private val roots: MutableList<RNGestureHandlerRootHelper> = ArrayList()
|
|
333
336
|
private val reanimatedEventDispatcher = ReanimatedEventDispatcher()
|
|
334
|
-
override fun getName() =
|
|
337
|
+
override fun getName() = NAME
|
|
335
338
|
|
|
336
339
|
@Suppress("UNCHECKED_CAST")
|
|
337
340
|
private fun <T : GestureHandler<T>> createGestureHandlerHelper(
|
|
@@ -476,7 +479,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
|
476
479
|
)
|
|
477
480
|
}
|
|
478
481
|
|
|
479
|
-
override fun
|
|
482
|
+
override fun invalidate() {
|
|
480
483
|
registry.dropAllHandlers()
|
|
481
484
|
interactionManager.reset()
|
|
482
485
|
synchronized(roots) {
|
|
@@ -489,7 +492,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
|
489
492
|
}
|
|
490
493
|
}
|
|
491
494
|
}
|
|
492
|
-
super.
|
|
495
|
+
super.invalidate()
|
|
493
496
|
}
|
|
494
497
|
|
|
495
498
|
fun registerRootHelper(root: RNGestureHandlerRootHelper) {
|
|
@@ -645,7 +648,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
|
645
648
|
}
|
|
646
649
|
|
|
647
650
|
companion object {
|
|
648
|
-
const val
|
|
651
|
+
const val NAME = "RNGestureHandlerModule"
|
|
649
652
|
private const val KEY_SHOULD_CANCEL_WHEN_OUTSIDE = "shouldCancelWhenOutside"
|
|
650
653
|
private const val KEY_ENABLED = "enabled"
|
|
651
654
|
private const val KEY_NEEDS_POINTER_DATA = "needsPointerData"
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt
CHANGED
|
@@ -10,6 +10,7 @@ import com.facebook.react.bridge.ReactContext
|
|
|
10
10
|
import com.facebook.react.bridge.UiThreadUtil
|
|
11
11
|
import com.facebook.react.common.ReactConstants
|
|
12
12
|
import com.facebook.react.uimanager.RootView
|
|
13
|
+
import com.facebook.react.uimanager.ThemedReactContext
|
|
13
14
|
import com.swmansion.gesturehandler.core.GestureHandler
|
|
14
15
|
import com.swmansion.gesturehandler.core.GestureHandlerOrchestrator
|
|
15
16
|
|
|
@@ -24,7 +25,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
|
|
|
24
25
|
UiThreadUtil.assertOnUiThread()
|
|
25
26
|
val wrappedViewTag = wrappedView.id
|
|
26
27
|
check(wrappedViewTag >= 1) { "Expect view tag to be set for $wrappedView" }
|
|
27
|
-
val module = context.getNativeModule(RNGestureHandlerModule::class.java)!!
|
|
28
|
+
val module = (context as ThemedReactContext).reactApplicationContext.getNativeModule(RNGestureHandlerModule::class.java)!!
|
|
28
29
|
val registry = module.registry
|
|
29
30
|
rootView = findRootViewTag(wrappedView)
|
|
30
31
|
Log.i(
|
|
@@ -49,7 +50,7 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
|
|
|
49
50
|
ReactConstants.TAG,
|
|
50
51
|
"[GESTURE HANDLER] Tearing down gesture handler registered for root view $rootView"
|
|
51
52
|
)
|
|
52
|
-
val module = context.getNativeModule(RNGestureHandlerModule::class.java)!!
|
|
53
|
+
val module = (context as ThemedReactContext).reactApplicationContext.getNativeModule(RNGestureHandlerModule::class.java)!!
|
|
53
54
|
with(module) {
|
|
54
55
|
registry.dropHandler(jsGestureHandler!!.tag)
|
|
55
56
|
unregisterRootHelper(this@RNGestureHandlerRootHelper)
|
|
@@ -77,13 +78,13 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
|
|
|
77
78
|
action = MotionEvent.ACTION_CANCEL
|
|
78
79
|
}
|
|
79
80
|
if (rootView is RootView) {
|
|
80
|
-
rootView.onChildStartedNativeGesture(event)
|
|
81
|
+
rootView.onChildStartedNativeGesture(rootView, event)
|
|
81
82
|
}
|
|
82
83
|
event.recycle()
|
|
83
84
|
}
|
|
84
85
|
}
|
|
85
86
|
|
|
86
|
-
fun requestDisallowInterceptTouchEvent(
|
|
87
|
+
fun requestDisallowInterceptTouchEvent() {
|
|
87
88
|
// If this method gets called it means that some native view is attempting to grab lock for
|
|
88
89
|
// touch event delivery. In that case we cancel all gesture recognizers
|
|
89
90
|
if (orchestrator != null && !passingTouch) {
|
|
@@ -115,6 +116,8 @@ class RNGestureHandlerRootHelper(private val context: ReactContext, wrappedView:
|
|
|
115
116
|
}
|
|
116
117
|
|
|
117
118
|
/*package*/
|
|
119
|
+
@Suppress("UNUSED_PARAMETER", "COMMENT_IN_SUPPRESSION")
|
|
120
|
+
// We want to keep order of parameters, so instead of removing viewTag we suppress the warning
|
|
118
121
|
fun handleSetJSResponder(viewTag: Int, blockNativeResponder: Boolean) {
|
|
119
122
|
if (blockNativeResponder) {
|
|
120
123
|
UiThreadUtil.runOnUiThread { tryCancelAllHandlers() }
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootView.kt
CHANGED
|
@@ -44,7 +44,7 @@ class RNGestureHandlerRootView(context: Context?) : ReactViewGroup(context) {
|
|
|
44
44
|
|
|
45
45
|
override fun requestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {
|
|
46
46
|
if (_enabled) {
|
|
47
|
-
rootHelper!!.requestDisallowInterceptTouchEvent(
|
|
47
|
+
rootHelper!!.requestDisallowInterceptTouchEvent()
|
|
48
48
|
}
|
|
49
49
|
super.requestDisallowInterceptTouchEvent(disallowIntercept)
|
|
50
50
|
}
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerStateChangeEvent.kt
CHANGED
|
@@ -10,7 +10,6 @@ import androidx.core.util.Pools
|
|
|
10
10
|
import com.facebook.react.bridge.Arguments
|
|
11
11
|
import com.facebook.react.bridge.WritableMap
|
|
12
12
|
import com.facebook.react.uimanager.events.Event
|
|
13
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
14
13
|
import com.swmansion.gesturehandler.core.GestureHandler
|
|
15
14
|
import com.swmansion.gesturehandler.react.eventbuilders.GestureHandlerEventDataBuilder
|
|
16
15
|
|
|
@@ -46,9 +45,7 @@ class RNGestureHandlerStateChangeEvent private constructor() : Event<RNGestureHa
|
|
|
46
45
|
// TODO: coalescing
|
|
47
46
|
override fun getCoalescingKey(): Short = 0
|
|
48
47
|
|
|
49
|
-
override fun
|
|
50
|
-
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, createEventData(dataBuilder!!, newState, oldState))
|
|
51
|
-
}
|
|
48
|
+
override fun getEventData(): WritableMap = createEventData(dataBuilder!!, newState, oldState)
|
|
52
49
|
|
|
53
50
|
companion object {
|
|
54
51
|
const val EVENT_NAME = "onGestureHandlerStateChange"
|
package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerTouchEvent.kt
CHANGED
|
@@ -3,15 +3,15 @@ package com.swmansion.gesturehandler.react
|
|
|
3
3
|
import androidx.core.util.Pools
|
|
4
4
|
import com.facebook.react.bridge.Arguments
|
|
5
5
|
import com.facebook.react.bridge.WritableMap
|
|
6
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
6
7
|
import com.facebook.react.uimanager.events.Event
|
|
7
|
-
import com.facebook.react.uimanager.events.RCTEventEmitter
|
|
8
8
|
import com.swmansion.gesturehandler.core.GestureHandler
|
|
9
9
|
|
|
10
10
|
class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerTouchEvent>() {
|
|
11
11
|
private var extraData: WritableMap? = null
|
|
12
12
|
private var coalescingKey: Short = 0
|
|
13
13
|
private fun <T : GestureHandler<T>> init(handler: T) {
|
|
14
|
-
super.init(handler.view!!.id)
|
|
14
|
+
super.init(UIManagerHelper.getSurfaceId(handler.view), handler.view!!.id)
|
|
15
15
|
extraData = createEventData(handler)
|
|
16
16
|
coalescingKey = handler.eventCoalescingKey
|
|
17
17
|
}
|
|
@@ -26,10 +26,7 @@ class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerT
|
|
|
26
26
|
override fun canCoalesce() = true
|
|
27
27
|
|
|
28
28
|
override fun getCoalescingKey() = coalescingKey
|
|
29
|
-
|
|
30
|
-
override fun dispatch(rctEventEmitter: RCTEventEmitter) {
|
|
31
|
-
rctEventEmitter.receiveEvent(viewTag, EVENT_NAME, extraData)
|
|
32
|
-
}
|
|
29
|
+
override fun getEventData(): WritableMap? = extraData
|
|
33
30
|
|
|
34
31
|
companion object {
|
|
35
32
|
const val EVENT_UNDETERMINED = 0
|
|
@@ -47,7 +44,7 @@ class RNGestureHandlerTouchEvent private constructor() : Event<RNGestureHandlerT
|
|
|
47
44
|
init(handler)
|
|
48
45
|
}
|
|
49
46
|
|
|
50
|
-
fun <T : GestureHandler<T>> createEventData(handler: T
|
|
47
|
+
fun <T : GestureHandler<T>> createEventData(handler: T): WritableMap = Arguments.createMap().apply {
|
|
51
48
|
putInt("handlerTag", handler.tag)
|
|
52
49
|
putInt("state", handler.state)
|
|
53
50
|
putInt("numberOfTouches", handler.trackedPointersCount)
|
|
@@ -7,16 +7,19 @@ abstract class GestureHandlerEventDataBuilder<T : GestureHandler<T>>(handler: T)
|
|
|
7
7
|
private val numberOfPointers: Int
|
|
8
8
|
private val handlerTag: Int
|
|
9
9
|
private val state: Int
|
|
10
|
+
private val pointerType: Int
|
|
10
11
|
|
|
11
12
|
init {
|
|
12
13
|
numberOfPointers = handler.numberOfPointers
|
|
13
14
|
handlerTag = handler.tag
|
|
14
15
|
state = handler.state
|
|
16
|
+
pointerType = handler.pointerType
|
|
15
17
|
}
|
|
16
18
|
|
|
17
19
|
open fun buildEventData(eventData: WritableMap) {
|
|
18
20
|
eventData.putInt("numberOfPointers", numberOfPointers)
|
|
19
21
|
eventData.putInt("handlerTag", handlerTag)
|
|
20
22
|
eventData.putInt("state", state)
|
|
23
|
+
eventData.putInt("pointerType", pointerType)
|
|
21
24
|
}
|
|
22
25
|
}
|
|
@@ -7,29 +7,25 @@ using namespace facebook;
|
|
|
7
7
|
using namespace react;
|
|
8
8
|
|
|
9
9
|
void decorateRuntime(jsi::Runtime &runtime) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
auto isFormsStackingContext = jsi::Function::createFromHostFunction(
|
|
11
|
+
runtime,
|
|
12
|
+
jsi::PropNameID::forAscii(runtime, "isFormsStackingContext"),
|
|
13
|
+
1,
|
|
14
|
+
[](jsi::Runtime &runtime,
|
|
15
|
+
const jsi::Value &thisValue,
|
|
16
|
+
const jsi::Value *arguments,
|
|
17
|
+
size_t count) -> jsi::Value {
|
|
18
|
+
if (!arguments[0].isObject()) {
|
|
19
|
+
return jsi::Value::null();
|
|
20
|
+
}
|
|
21
|
+
auto shadowNode = arguments[0]
|
|
22
|
+
.asObject(runtime).getNativeState<ShadowNode>(runtime);
|
|
23
|
+
bool isFormsStackingContext = shadowNode->getTraits().check(ShadowNodeTraits::FormsStackingContext);
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
bool isFormsStackingContext = shadowNode->getTraits().check(
|
|
27
|
-
ShadowNodeTraits::FormsStackingContext);
|
|
28
|
-
|
|
29
|
-
return jsi::Value(isFormsStackingContext);
|
|
30
|
-
});
|
|
31
|
-
runtime.global().setProperty(
|
|
32
|
-
runtime, "isFormsStackingContext", std::move(isFormsStackingContext));
|
|
25
|
+
return jsi::Value(isFormsStackingContext);
|
|
26
|
+
});
|
|
27
|
+
runtime.global().setProperty(
|
|
28
|
+
runtime, "isFormsStackingContext", std::move(isFormsStackingContext));
|
|
33
29
|
}
|
|
34
30
|
|
|
35
31
|
extern "C" JNIEXPORT void JNICALL
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
|
|
27
27
|
- (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
|
28
28
|
{
|
|
29
|
+
[_gestureHandler setCurrentPointerType:event];
|
|
29
30
|
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
|
|
30
31
|
[_gestureHandler reset];
|
|
31
32
|
[super touchesBegan:touches withEvent:event];
|
|
@@ -141,16 +142,16 @@
|
|
|
141
142
|
|
|
142
143
|
RNBetterSwipeGestureRecognizer *recognizer = (RNBetterSwipeGestureRecognizer *)_recognizer;
|
|
143
144
|
|
|
144
|
-
CGPoint viewAbsolutePosition =
|
|
145
|
-
|
|
146
|
-
toView:RCTKeyWindow().rootViewController.view];
|
|
145
|
+
CGPoint viewAbsolutePosition = [recognizer.view convertPoint:recognizer.view.bounds.origin
|
|
146
|
+
toView:RCTKeyWindow().rootViewController.view];
|
|
147
147
|
CGPoint locationInView = [recognizer getLastLocation];
|
|
148
148
|
|
|
149
149
|
return [RNGestureHandlerEventExtraData
|
|
150
150
|
forPosition:locationInView
|
|
151
151
|
withAbsolutePosition:CGPointMake(
|
|
152
152
|
viewAbsolutePosition.x + locationInView.x, viewAbsolutePosition.y + locationInView.y)
|
|
153
|
-
withNumberOfTouches:recognizer.numberOfTouches
|
|
153
|
+
withNumberOfTouches:recognizer.numberOfTouches
|
|
154
|
+
withPointerType:_pointerType];
|
|
154
155
|
}
|
|
155
156
|
@end
|
|
156
157
|
|
|
@@ -40,6 +40,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
|
40
40
|
|
|
41
41
|
- (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
|
42
42
|
{
|
|
43
|
+
[_gestureHandler setCurrentPointerType:event];
|
|
43
44
|
if (_firstTouch) {
|
|
44
45
|
// ignore rest of fingers
|
|
45
46
|
return;
|
|
@@ -171,7 +172,8 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
|
171
172
|
return [RNGestureHandlerEventExtraData forForce:recognizer.force
|
|
172
173
|
forPosition:[recognizer locationInView:recognizer.view]
|
|
173
174
|
withAbsolutePosition:[recognizer locationInView:recognizer.view.window]
|
|
174
|
-
withNumberOfTouches:recognizer.numberOfTouches
|
|
175
|
+
withNumberOfTouches:recognizer.numberOfTouches
|
|
176
|
+
withPointerType:_pointerType];
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
@end
|
|
@@ -155,7 +155,8 @@ API_AVAILABLE(ios(13.4))
|
|
|
155
155
|
- (RNGestureHandlerEventExtraData *)eventExtraData:(UIGestureRecognizer *)recognizer
|
|
156
156
|
{
|
|
157
157
|
return [RNGestureHandlerEventExtraData forPosition:[recognizer locationInView:recognizer.view]
|
|
158
|
-
withAbsolutePosition:[recognizer locationInView:recognizer.view.window]
|
|
158
|
+
withAbsolutePosition:[recognizer locationInView:recognizer.view.window]
|
|
159
|
+
withPointerType:UITouchTypePencil];
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
@end
|