react-native-gesture-handler 2.16.0-rc.0 → 2.16.0
Sign up to get free protection for your applications and to get access to all the features.
- 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 +2 -2
- package/android/src/main/java/com/swmansion/gesturehandler/core/DiagonalDirections.kt +8 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +61 -24
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +17 -22
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +30 -11
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureUtils.kt +3 -0
- 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/RNGestureHandlerRootHelper.kt +4 -2
- 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/apple/Handlers/RNLongPressHandler.m +5 -13
- package/apple/Handlers/RNPinchHandler.m +12 -1
- package/apple/RNGestureHandler.m +3 -1
- package/lib/commonjs/Directions.js +19 -6
- package/lib/commonjs/Directions.js.map +1 -1
- 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/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/handlers/createHandler.js +2 -2
- 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 +8 -8
- 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/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 +4 -2
- 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 -13
- 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 +114 -115
- 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 +55 -27
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +26 -5
- 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 +9 -1
- 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/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/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/handlers/createHandler.js +2 -3
- 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 +1 -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/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 +3 -2
- 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 -11
- 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 +114 -115
- 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 +53 -26
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +26 -5
- 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 +2 -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/RNGestureHandlerModule.web.d.ts +4 -39
- package/lib/typescript/components/DrawerLayout.d.ts +1 -2
- package/lib/typescript/components/touchables/GenericTouchable.d.ts +2 -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 +11 -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 +1 -1
- package/lib/typescript/mocks.d.ts +1 -0
- 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 +11 -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 +7 -10
- 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 +4 -4
- package/lib/typescript/web_hammer/NodeManager.d.ts +1 -1
- package/package.json +2 -1
- package/src/Directions.ts +21 -4
- package/src/RNGestureHandlerModule.web.ts +3 -44
- package/src/components/DrawerLayout.tsx +1 -1
- package/src/components/Swipeable.tsx +2 -0
- package/src/components/touchables/GenericTouchable.tsx +3 -0
- package/src/handlers/createHandler.tsx +10 -4
- package/src/handlers/customDirectEventTypes.ts +2 -0
- package/src/handlers/customDirectEventTypes.web.ts +5 -0
- package/src/handlers/gestureHandlerCommon.ts +28 -1
- package/src/handlers/gestures/GestureDetector.tsx +15 -0
- package/src/handlers/gestures/gesture.ts +1 -1
- package/src/index.ts +1 -1
- package/src/mocks.ts +2 -0
- 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 +14 -10
- package/src/web/handlers/IGestureHandler.ts +50 -0
- package/src/web/handlers/NativeViewGestureHandler.ts +5 -6
- package/src/web/interfaces.ts +13 -10
- package/src/web/tools/EventManager.ts +16 -14
- package/src/web/tools/GestureHandlerDelegate.ts +3 -4
- package/src/web/tools/GestureHandlerOrchestrator.ts +160 -145
- 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 +181 -166
- package/src/web/tools/TouchEventManager.ts +126 -114
- package/src/web/tools/Vector.ts +60 -0
- package/src/web/utils.ts +7 -4
- package/src/web_hammer/NodeManager.ts +1 -1
package/android/noreanimated/src/main/java/com/swmansion/gesturehandler/ReanimatedEventDispatcher.kt
CHANGED
@@ -4,6 +4,8 @@ import com.facebook.react.bridge.ReactContext
|
|
4
4
|
import com.facebook.react.uimanager.events.Event
|
5
5
|
|
6
6
|
class ReanimatedEventDispatcher {
|
7
|
+
@Suppress("UNUSED_PARAMETER", "COMMENT_IN_SUPPRESSION")
|
8
|
+
// This is necessary on new architecture
|
7
9
|
fun <T : Event<T>>sendEvent(event: T, reactApplicationContext: ReactContext) {
|
8
10
|
// no-op
|
9
11
|
}
|
@@ -43,6 +43,15 @@ public class RNGestureHandlerButtonManagerDelegate<T extends View, U extends Bas
|
|
43
43
|
case "touchSoundDisabled":
|
44
44
|
mViewManager.setTouchSoundDisabled(view, value == null ? false : (boolean) value);
|
45
45
|
break;
|
46
|
+
case "borderWidth":
|
47
|
+
mViewManager.setBorderWidth(view, value == null ? 0f : ((Double) value).floatValue());
|
48
|
+
break;
|
49
|
+
case "borderColor":
|
50
|
+
mViewManager.setBorderColor(view, ColorPropConverter.getColor(value, view.getContext()));
|
51
|
+
break;
|
52
|
+
case "borderStyle":
|
53
|
+
mViewManager.setBorderStyle(view, value == null ? "solid" : (String) value);
|
54
|
+
break;
|
46
55
|
default:
|
47
56
|
super.setProperty(view, propName, value);
|
48
57
|
}
|
@@ -20,4 +20,7 @@ public interface RNGestureHandlerButtonManagerInterface<T extends View> {
|
|
20
20
|
void setRippleColor(T view, @Nullable Integer value);
|
21
21
|
void setRippleRadius(T view, int value);
|
22
22
|
void setTouchSoundDisabled(T view, boolean value);
|
23
|
+
void setBorderWidth(T view, float value);
|
24
|
+
void setBorderColor(T view, @Nullable Integer value);
|
25
|
+
void setBorderStyle(T view, @Nullable String value);
|
23
26
|
}
|
@@ -60,7 +60,7 @@ class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPac
|
|
60
60
|
try {
|
61
61
|
val reactModuleInfoProviderClass =
|
62
62
|
Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider")
|
63
|
-
return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider
|
63
|
+
return reactModuleInfoProviderClass.getDeclaredConstructor().newInstance() as ReactModuleInfoProvider
|
64
64
|
} catch (e: ClassNotFoundException) {
|
65
65
|
return ReactModuleInfoProvider {
|
66
66
|
val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!!
|
@@ -71,7 +71,7 @@ class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPac
|
|
71
71
|
RNGestureHandlerModule::class.java.name,
|
72
72
|
reactModule.canOverrideExistingModule,
|
73
73
|
reactModule.needsEagerInit,
|
74
|
-
|
74
|
+
true, // Has constants is hardcoded to return true, so replacing it with `true` changes nothing.
|
75
75
|
reactModule.isCxxModule,
|
76
76
|
true
|
77
77
|
)
|
@@ -0,0 +1,8 @@
|
|
1
|
+
package com.swmansion.gesturehandler.core
|
2
|
+
|
3
|
+
object DiagonalDirections {
|
4
|
+
const val DIRECTION_RIGHT_UP = GestureHandler.DIRECTION_RIGHT or GestureHandler.DIRECTION_UP
|
5
|
+
const val DIRECTION_RIGHT_DOWN = GestureHandler.DIRECTION_RIGHT or GestureHandler.DIRECTION_DOWN
|
6
|
+
const val DIRECTION_LEFT_UP = GestureHandler.DIRECTION_LEFT or GestureHandler.DIRECTION_UP
|
7
|
+
const val DIRECTION_LEFT_DOWN = GestureHandler.DIRECTION_LEFT or GestureHandler.DIRECTION_DOWN
|
8
|
+
}
|
@@ -3,18 +3,18 @@ package com.swmansion.gesturehandler.core
|
|
3
3
|
import android.os.Handler
|
4
4
|
import android.os.Looper
|
5
5
|
import android.view.MotionEvent
|
6
|
+
import android.view.VelocityTracker
|
6
7
|
|
7
8
|
class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
|
8
9
|
var numberOfPointersRequired = DEFAULT_NUMBER_OF_TOUCHES_REQUIRED
|
9
10
|
var direction = DEFAULT_DIRECTION
|
10
11
|
|
11
12
|
private val maxDurationMs = DEFAULT_MAX_DURATION_MS
|
12
|
-
private val
|
13
|
-
private var startX = 0f
|
14
|
-
private var startY = 0f
|
13
|
+
private val minVelocity = DEFAULT_MIN_VELOCITY
|
15
14
|
private var handler: Handler? = null
|
16
15
|
private var maxNumberOfPointersSimultaneously = 0
|
17
16
|
private val failDelayed = Runnable { fail() }
|
17
|
+
private var velocityTracker: VelocityTracker? = null
|
18
18
|
|
19
19
|
override fun resetConfig() {
|
20
20
|
super.resetConfig()
|
@@ -23,8 +23,7 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
|
|
23
23
|
}
|
24
24
|
|
25
25
|
private fun startFling(event: MotionEvent) {
|
26
|
-
|
27
|
-
startY = event.rawY
|
26
|
+
velocityTracker = VelocityTracker.obtain()
|
28
27
|
begin()
|
29
28
|
maxNumberOfPointersSimultaneously = 1
|
30
29
|
if (handler == null) {
|
@@ -35,26 +34,48 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
|
|
35
34
|
handler!!.postDelayed(failDelayed, maxDurationMs)
|
36
35
|
}
|
37
36
|
|
38
|
-
private fun tryEndFling(event: MotionEvent)
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
37
|
+
private fun tryEndFling(event: MotionEvent): Boolean {
|
38
|
+
addVelocityMovement(velocityTracker, event)
|
39
|
+
|
40
|
+
val velocityVector = Vector.fromVelocity(velocityTracker!!)
|
41
|
+
|
42
|
+
fun getVelocityAlignment(
|
43
|
+
direction: Int,
|
44
|
+
maxDeviationCosine: Double,
|
45
|
+
): Boolean = (
|
46
|
+
(this.direction and direction) == direction &&
|
47
|
+
velocityVector.isSimilar(Vector.fromDirection(direction), maxDeviationCosine)
|
49
48
|
)
|
50
|
-
) {
|
51
|
-
handler!!.removeCallbacksAndMessages(null)
|
52
|
-
activate()
|
53
|
-
true
|
54
|
-
} else {
|
55
|
-
false
|
56
|
-
}
|
57
49
|
|
50
|
+
val axialAlignmentsList = arrayOf(
|
51
|
+
DIRECTION_LEFT,
|
52
|
+
DIRECTION_RIGHT,
|
53
|
+
DIRECTION_UP,
|
54
|
+
DIRECTION_DOWN,
|
55
|
+
).map { direction -> getVelocityAlignment(direction, MAX_AXIAL_DEVIATION) }
|
56
|
+
|
57
|
+
val diagonalAlignmentsList = arrayOf(
|
58
|
+
DiagonalDirections.DIRECTION_RIGHT_UP,
|
59
|
+
DiagonalDirections.DIRECTION_RIGHT_DOWN,
|
60
|
+
DiagonalDirections.DIRECTION_LEFT_UP,
|
61
|
+
DiagonalDirections.DIRECTION_LEFT_DOWN,
|
62
|
+
).map { direction -> getVelocityAlignment(direction, MAX_DIAGONAL_DEVIATION) }
|
63
|
+
|
64
|
+
val isAligned = axialAlignmentsList.any { it } or diagonalAlignmentsList.any { it }
|
65
|
+
val isFast = velocityVector.magnitude > this.minVelocity
|
66
|
+
|
67
|
+
return if (
|
68
|
+
maxNumberOfPointersSimultaneously == numberOfPointersRequired &&
|
69
|
+
isAligned &&
|
70
|
+
isFast
|
71
|
+
) {
|
72
|
+
handler!!.removeCallbacksAndMessages(null)
|
73
|
+
activate()
|
74
|
+
true
|
75
|
+
} else {
|
76
|
+
false
|
77
|
+
}
|
78
|
+
}
|
58
79
|
override fun activate(force: Boolean) {
|
59
80
|
super.activate(force)
|
60
81
|
end()
|
@@ -92,13 +113,29 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
|
|
92
113
|
}
|
93
114
|
|
94
115
|
override fun onReset() {
|
116
|
+
velocityTracker?.recycle()
|
117
|
+
velocityTracker = null
|
95
118
|
handler?.removeCallbacksAndMessages(null)
|
96
119
|
}
|
97
120
|
|
121
|
+
private fun addVelocityMovement(tracker: VelocityTracker?, event: MotionEvent) {
|
122
|
+
val offsetX = event.rawX - event.x
|
123
|
+
val offsetY = event.rawY - event.y
|
124
|
+
event.offsetLocation(offsetX, offsetY)
|
125
|
+
tracker!!.addMovement(event)
|
126
|
+
event.offsetLocation(-offsetX, -offsetY)
|
127
|
+
}
|
128
|
+
|
98
129
|
companion object {
|
99
130
|
private const val DEFAULT_MAX_DURATION_MS: Long = 800
|
100
|
-
private const val
|
131
|
+
private const val DEFAULT_MIN_VELOCITY: Long = 2000
|
132
|
+
private const val DEFAULT_ALIGNMENT_CONE: Double = 30.0
|
101
133
|
private const val DEFAULT_DIRECTION = DIRECTION_RIGHT
|
102
134
|
private const val DEFAULT_NUMBER_OF_TOUCHES_REQUIRED = 1
|
135
|
+
|
136
|
+
private val MAX_AXIAL_DEVIATION: Double =
|
137
|
+
GestureUtils.coneToDeviation(DEFAULT_ALIGNMENT_CONE)
|
138
|
+
private val MAX_DIAGONAL_DEVIATION: Double =
|
139
|
+
GestureUtils.coneToDeviation(90 - DEFAULT_ALIGNMENT_CONE)
|
103
140
|
}
|
104
141
|
}
|
@@ -4,14 +4,13 @@ import android.app.Activity
|
|
4
4
|
import android.content.Context
|
5
5
|
import android.content.ContextWrapper
|
6
6
|
import android.graphics.PointF
|
7
|
-
import android.graphics.Rect
|
8
7
|
import android.os.Build
|
9
8
|
import android.view.MotionEvent
|
10
9
|
import android.view.MotionEvent.PointerCoords
|
11
10
|
import android.view.MotionEvent.PointerProperties
|
12
11
|
import android.view.View
|
13
|
-
import android.view.Window
|
14
12
|
import com.facebook.react.bridge.Arguments
|
13
|
+
import com.facebook.react.bridge.ReactContext
|
15
14
|
import com.facebook.react.bridge.UiThreadUtil
|
16
15
|
import com.facebook.react.bridge.WritableArray
|
17
16
|
import com.facebook.react.uimanager.PixelUtil
|
@@ -176,12 +175,9 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
176
175
|
this.view = view
|
177
176
|
this.orchestrator = orchestrator
|
178
177
|
|
179
|
-
val
|
180
|
-
if (
|
181
|
-
|
182
|
-
decorView.getWindowVisibleDisplayFrame(frame)
|
183
|
-
windowOffset[0] = frame.left
|
184
|
-
windowOffset[1] = frame.top
|
178
|
+
val content = getActivity(view?.context)?.findViewById<View>(android.R.id.content)
|
179
|
+
if (content != null) {
|
180
|
+
content.getLocationOnScreen(windowOffset)
|
185
181
|
} else {
|
186
182
|
windowOffset[0] = 0
|
187
183
|
windowOffset[1] = 0
|
@@ -192,13 +188,13 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
192
188
|
|
193
189
|
protected open fun onPrepare() {}
|
194
190
|
|
195
|
-
private fun
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
191
|
+
private fun getActivity(context: Context?): Activity? =
|
192
|
+
when (context) {
|
193
|
+
is ReactContext -> context.currentActivity
|
194
|
+
is Activity -> context
|
195
|
+
is ContextWrapper -> getActivity(context.baseContext)
|
196
|
+
else -> null
|
197
|
+
}
|
202
198
|
|
203
199
|
private fun findNextLocalPointerId(): Int {
|
204
200
|
var localPointerId = 0
|
@@ -656,7 +652,7 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
656
652
|
}
|
657
653
|
|
658
654
|
fun cancel() {
|
659
|
-
if (state == STATE_ACTIVE || state == STATE_UNDETERMINED || state == STATE_BEGAN) {
|
655
|
+
if (state == STATE_ACTIVE || state == STATE_UNDETERMINED || state == STATE_BEGAN || this.isAwaiting) {
|
660
656
|
onCancel()
|
661
657
|
moveToState(STATE_CANCELLED)
|
662
658
|
}
|
@@ -762,7 +758,6 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
762
758
|
orchestrator = null
|
763
759
|
Arrays.fill(trackedPointerIDs, -1)
|
764
760
|
trackedPointersIDsCount = 0
|
765
|
-
|
766
761
|
trackedPointersCount = 0
|
767
762
|
trackedPointers.fill(null)
|
768
763
|
touchEventType = RNGestureHandlerTouchEvent.EVENT_UNDETERMINED
|
@@ -836,15 +831,15 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
836
831
|
private lateinit var pointerProps: Array<PointerProperties?>
|
837
832
|
private lateinit var pointerCoords: Array<PointerCoords?>
|
838
833
|
private fun initPointerProps(size: Int) {
|
839
|
-
var
|
834
|
+
var pointerPropsSize = size
|
840
835
|
if (!Companion::pointerProps.isInitialized) {
|
841
836
|
pointerProps = arrayOfNulls(MAX_POINTERS_COUNT)
|
842
837
|
pointerCoords = arrayOfNulls(MAX_POINTERS_COUNT)
|
843
838
|
}
|
844
|
-
while (
|
845
|
-
pointerProps[
|
846
|
-
pointerCoords[
|
847
|
-
|
839
|
+
while (pointerPropsSize > 0 && pointerProps[pointerPropsSize - 1] == null) {
|
840
|
+
pointerProps[pointerPropsSize - 1] = PointerProperties()
|
841
|
+
pointerCoords[pointerPropsSize - 1] = PointerCoords()
|
842
|
+
pointerPropsSize--
|
848
843
|
}
|
849
844
|
}
|
850
845
|
|
package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
CHANGED
@@ -7,6 +7,7 @@ import android.view.View
|
|
7
7
|
import android.view.ViewGroup
|
8
8
|
import android.widget.EditText
|
9
9
|
import java.util.*
|
10
|
+
import kotlin.collections.HashSet
|
10
11
|
|
11
12
|
class GestureHandlerOrchestrator(
|
12
13
|
private val wrapperView: ViewGroup,
|
@@ -22,6 +23,14 @@ class GestureHandlerOrchestrator(
|
|
22
23
|
private val gestureHandlers = arrayListOf<GestureHandler<*>>()
|
23
24
|
private val awaitingHandlers = arrayListOf<GestureHandler<*>>()
|
24
25
|
private val preparedHandlers = arrayListOf<GestureHandler<*>>()
|
26
|
+
|
27
|
+
// In `onHandlerStateChange` method we iterate through `awaitingHandlers`, but calling `tryActivate` may modify this list.
|
28
|
+
// To avoid `ConcurrentModificationException` we iterate through copy. There is one more problem though - if handler was
|
29
|
+
// removed from `awaitingHandlers`, it was still present in copy of original list. This hashset helps us identify which handlers
|
30
|
+
// are really inside `awaitingHandlers`.
|
31
|
+
// `contains` method on HashSet has O(1) complexity, so calling it inside for loop won't result in O(n^2) (contrary to ArrayList)
|
32
|
+
private val awaitingHandlersTags = HashSet<Int>()
|
33
|
+
|
25
34
|
private var isHandlingTouch = false
|
26
35
|
private var handlingChangeSemaphore = 0
|
27
36
|
private var finishedHandlersCleanupScheduled = false
|
@@ -73,16 +82,18 @@ class GestureHandlerOrchestrator(
|
|
73
82
|
finishedHandlersCleanupScheduled = false
|
74
83
|
}
|
75
84
|
|
76
|
-
private fun hasOtherHandlerToWaitFor(handler: GestureHandler<*>)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
}
|
81
|
-
}
|
82
|
-
return false
|
83
|
-
}
|
85
|
+
private fun hasOtherHandlerToWaitFor(handler: GestureHandler<*>) =
|
86
|
+
gestureHandlers.any { !isFinished(it.state) && shouldHandlerWaitForOther(handler, it) }
|
87
|
+
|
88
|
+
private fun shouldBeCancelledByFinishedHandler(handler: GestureHandler<*>) = gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler.STATE_END }
|
84
89
|
|
85
90
|
private fun tryActivate(handler: GestureHandler<*>) {
|
91
|
+
// If we are waiting for a gesture that has successfully finished, we should cancel handler
|
92
|
+
if (shouldBeCancelledByFinishedHandler(handler)) {
|
93
|
+
handler.cancel()
|
94
|
+
return
|
95
|
+
}
|
96
|
+
|
86
97
|
// see if there is anyone else who we need to wait for
|
87
98
|
if (hasOtherHandlerToWaitFor(handler)) {
|
88
99
|
addAwaitingHandler(handler)
|
@@ -94,7 +105,14 @@ class GestureHandlerOrchestrator(
|
|
94
105
|
}
|
95
106
|
|
96
107
|
private fun cleanupAwaitingHandlers() {
|
97
|
-
|
108
|
+
val awaitingHandlersCopy = awaitingHandlers.toList()
|
109
|
+
|
110
|
+
for (handler in awaitingHandlersCopy) {
|
111
|
+
if (!handler.isAwaiting) {
|
112
|
+
awaitingHandlers.remove(handler)
|
113
|
+
awaitingHandlersTags.remove(handler.tag)
|
114
|
+
}
|
115
|
+
}
|
98
116
|
}
|
99
117
|
|
100
118
|
/*package*/
|
@@ -107,7 +125,7 @@ class GestureHandlerOrchestrator(
|
|
107
125
|
|
108
126
|
// if there were handlers awaiting completion of this handler, we can trigger active state
|
109
127
|
for (otherHandler in currentlyAwaitingHandlers) {
|
110
|
-
if (!shouldHandlerWaitForOther(otherHandler, handler)) {
|
128
|
+
if (!shouldHandlerWaitForOther(otherHandler, handler) || !awaitingHandlersTags.contains(otherHandler.tag)) {
|
111
129
|
continue
|
112
130
|
}
|
113
131
|
|
@@ -174,7 +192,6 @@ class GestureHandlerOrchestrator(
|
|
174
192
|
// Clear all awaiting handlers waiting for the current handler to fail
|
175
193
|
for (otherHandler in awaitingHandlers.reversed()) {
|
176
194
|
if (shouldHandlerBeCancelledBy(otherHandler, handler)) {
|
177
|
-
otherHandler.cancel()
|
178
195
|
otherHandler.isAwaiting = false
|
179
196
|
}
|
180
197
|
}
|
@@ -389,6 +406,8 @@ class GestureHandlerOrchestrator(
|
|
389
406
|
}
|
390
407
|
|
391
408
|
awaitingHandlers.add(handler)
|
409
|
+
awaitingHandlersTags.add(handler.tag)
|
410
|
+
|
392
411
|
with(handler) {
|
393
412
|
isAwaiting = true
|
394
413
|
activationIndex = this@GestureHandlerOrchestrator.activationIndex++
|
@@ -1,6 +1,7 @@
|
|
1
1
|
package com.swmansion.gesturehandler.core
|
2
2
|
|
3
3
|
import android.view.MotionEvent
|
4
|
+
import kotlin.math.cos
|
4
5
|
|
5
6
|
object GestureUtils {
|
6
7
|
fun getLastPointerX(event: MotionEvent, averageTouches: Boolean): Float {
|
@@ -44,4 +45,6 @@ object GestureUtils {
|
|
44
45
|
event.getY(lastPointerIdx)
|
45
46
|
}
|
46
47
|
}
|
48
|
+
fun coneToDeviation(angle: Double): Double =
|
49
|
+
cos(Math.toRadians(angle / 2.0))
|
47
50
|
}
|
@@ -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")
|