react-native-gesture-handler 2.14.1 → 2.15.0
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -0
- package/RNGestureHandler.podspec +2 -2
- package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
- package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +64 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +12 -2
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +53 -19
- package/{ios → apple}/Handlers/RNFlingHandler.m +25 -5
- package/{ios → apple}/Handlers/RNForceTouchHandler.m +25 -7
- package/{ios → apple}/Handlers/RNHoverHandler.m +26 -1
- package/{ios → apple}/Handlers/RNLongPressHandler.m +24 -4
- package/{ios → apple}/Handlers/RNManualHandler.m +24 -4
- package/{ios → apple}/Handlers/RNNativeViewHandler.mm +42 -6
- package/{ios → apple}/Handlers/RNPanHandler.m +100 -15
- package/apple/Handlers/RNPinchHandler.m +162 -0
- package/{ios → apple}/Handlers/RNRotationHandler.m +71 -9
- package/{ios → apple}/Handlers/RNTapHandler.m +96 -26
- package/apple/RNGHUIKit.h +27 -0
- package/{ios → apple}/RNGestureHandler.h +3 -3
- package/{ios → apple}/RNGestureHandler.m +31 -5
- package/{ios → apple}/RNGestureHandlerButton.h +4 -1
- package/{ios → apple}/RNGestureHandlerButton.m +12 -4
- package/{ios → apple}/RNGestureHandlerButtonManager.m +4 -2
- package/{ios → apple}/RNGestureHandlerEvents.h +1 -1
- package/{ios → apple}/RNGestureHandlerManager.h +2 -2
- package/{ios → apple}/RNGestureHandlerManager.mm +46 -11
- package/apple/RNGestureHandlerModule.h +17 -0
- package/{ios → apple}/RNGestureHandlerModule.mm +46 -60
- package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
- package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
- package/{ios → apple}/RNGestureHandlerRegistry.h +1 -1
- package/{ios → apple}/RNGestureHandlerRegistry.m +1 -1
- package/{ios → apple}/RNManualActivationRecognizer.h +8 -0
- package/{ios → apple}/RNManualActivationRecognizer.m +27 -7
- package/{ios → apple}/RNRootViewGestureRecognizer.m +72 -4
- package/lib/commonjs/RNGestureHandlerModule.js +5 -18
- package/lib/commonjs/RNGestureHandlerModule.js.map +1 -1
- package/lib/commonjs/RNGestureHandlerModule.windows.js +10 -102
- package/lib/commonjs/RNGestureHandlerModule.windows.js.map +1 -1
- package/lib/commonjs/components/DrawerLayout.js +2 -0
- package/lib/commonjs/components/DrawerLayout.js.map +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js +1 -1
- package/lib/commonjs/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js +11 -1
- package/lib/commonjs/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/commonjs/handlers/gestures/gesture.js +5 -0
- package/lib/commonjs/handlers/gestures/gesture.js.map +1 -1
- package/lib/commonjs/index.js +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js +13 -0
- package/lib/commonjs/specs/NativeRNGestureHandlerModule.js.map +1 -0
- package/lib/commonjs/web/handlers/FlingGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/GestureHandler.js +13 -1
- package/lib/commonjs/web/handlers/GestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js +8 -6
- package/lib/commonjs/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/PanGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/commonjs/web/handlers/TapGestureHandler.js +4 -0
- package/lib/commonjs/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/commonjs/web/interfaces.js +12 -14
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js +35 -0
- package/lib/commonjs/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/commonjs/web/tools/NodeManager.js +3 -2
- package/lib/commonjs/web/tools/NodeManager.js.map +1 -1
- package/lib/commonjs/web/tools/PointerEventManager.js +11 -3
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +0 -1
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.js +4 -18
- package/lib/module/RNGestureHandlerModule.js.map +1 -1
- package/lib/module/RNGestureHandlerModule.windows.js +10 -81
- package/lib/module/RNGestureHandlerModule.windows.js.map +1 -1
- package/lib/module/components/DrawerLayout.js +2 -0
- package/lib/module/components/DrawerLayout.js.map +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js +1 -1
- package/lib/module/handlers/gestureHandlerCommon.js.map +1 -1
- package/lib/module/handlers/gestures/GestureDetector.js +11 -1
- package/lib/module/handlers/gestures/GestureDetector.js.map +1 -1
- package/lib/module/handlers/gestures/gesture.js +5 -0
- package/lib/module/handlers/gestures/gesture.js.map +1 -1
- package/lib/module/index.js +1 -0
- 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/web/handlers/FlingGestureHandler.js +4 -0
- package/lib/module/web/handlers/FlingGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/GestureHandler.js +14 -2
- package/lib/module/web/handlers/GestureHandler.js.map +1 -1
- package/lib/module/web/handlers/LongPressGestureHandler.js +8 -5
- package/lib/module/web/handlers/LongPressGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/PanGestureHandler.js +4 -0
- package/lib/module/web/handlers/PanGestureHandler.js.map +1 -1
- package/lib/module/web/handlers/TapGestureHandler.js +4 -0
- package/lib/module/web/handlers/TapGestureHandler.js.map +1 -1
- package/lib/module/web/interfaces.js +9 -11
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerWebDelegate.js +34 -0
- package/lib/module/web/tools/GestureHandlerWebDelegate.js.map +1 -1
- package/lib/module/web/tools/NodeManager.js +3 -2
- package/lib/module/web/tools/NodeManager.js.map +1 -1
- package/lib/module/web/tools/PointerEventManager.js +12 -4
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +1 -2
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/typescript/RNGestureHandlerModule.d.ts +2 -13
- package/lib/typescript/RNGestureHandlerModule.windows.d.ts +5 -21
- package/lib/typescript/components/DrawerLayout.d.ts +11 -0
- package/lib/typescript/handlers/NativeViewGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/PanGestureHandler.d.ts +1 -1
- package/lib/typescript/handlers/gestureHandlerCommon.d.ts +4 -1
- package/lib/typescript/handlers/gestures/GestureDetector.d.ts +2 -1
- package/lib/typescript/handlers/gestures/gesture.d.ts +2 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +3 -1
- package/lib/typescript/web/interfaces.d.ts +9 -9
- package/lib/typescript/web/tools/GestureHandlerDelegate.d.ts +2 -0
- package/lib/typescript/web/tools/GestureHandlerWebDelegate.d.ts +7 -0
- package/lib/typescript/web/tools/PointerEventManager.d.ts +2 -0
- package/package.json +14 -11
- package/src/RNGestureHandlerModule.ts +4 -49
- package/src/RNGestureHandlerModule.windows.ts +18 -100
- package/src/components/DrawerLayout.tsx +15 -0
- package/src/handlers/gestureHandlerCommon.ts +5 -0
- package/src/handlers/gestures/GestureDetector.tsx +16 -2
- package/src/handlers/gestures/gesture.ts +6 -0
- package/src/index.ts +1 -0
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/web/handlers/FlingGestureHandler.ts +4 -0
- package/src/web/handlers/GestureHandler.ts +17 -0
- package/src/web/handlers/LongPressGestureHandler.ts +8 -5
- package/src/web/handlers/PanGestureHandler.ts +4 -0
- package/src/web/handlers/TapGestureHandler.ts +4 -0
- package/src/web/interfaces.ts +10 -10
- package/src/web/tools/GestureHandlerDelegate.ts +3 -0
- package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
- package/src/web/tools/NodeManager.ts +5 -1
- package/src/web/tools/PointerEventManager.ts +18 -2
- package/src/web/tools/TouchEventManager.ts +0 -2
- package/ios/Handlers/RNPinchHandler.m +0 -95
- package/ios/RNGestureHandlerModule.h +0 -7
- package/lib/commonjs/RNGestureHandlerModule.macos.js +0 -149
- package/lib/commonjs/RNGestureHandlerModule.macos.js.map +0 -1
- package/lib/module/RNGestureHandlerModule.macos.js +0 -110
- package/lib/module/RNGestureHandlerModule.macos.js.map +0 -1
- package/lib/typescript/RNGestureHandlerModule.macos.d.ts +0 -47
- package/src/RNGestureHandlerModule.macos.ts +0 -133
- /package/{ios → apple}/Handlers/RNFlingHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNForceTouchHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNHoverHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNLongPressHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNManualHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNNativeViewHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNPanHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNPinchHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNRotationHandler.h +0 -0
- /package/{ios → apple}/Handlers/RNTapHandler.h +0 -0
- /package/{ios → apple}/RNGHTouchEventType.h +0 -0
- /package/{ios → apple}/RNGestureHandler.xcodeproj/project.pbxproj +0 -0
- /package/{ios → apple}/RNGestureHandler.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -0
- /package/{ios → apple}/RNGestureHandlerActionType.h +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonComponentView.h +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonComponentView.mm +0 -0
- /package/{ios → apple}/RNGestureHandlerButtonManager.h +0 -0
- /package/{ios → apple}/RNGestureHandlerDirection.h +0 -0
- /package/{ios → apple}/RNGestureHandlerEvents.m +0 -0
- /package/{ios → apple}/RNGestureHandlerRootViewComponentView.mm +0 -0
- /package/{ios → apple}/RNGestureHandlerState.h +0 -0
- /package/{ios → apple}/RNGestureHandlerStateManager.h +0 -0
- /package/{ios → apple}/RNRootViewGestureRecognizer.h +0 -0
package/README.md
CHANGED
package/RNGestureHandler.podspec
CHANGED
@@ -14,9 +14,9 @@ Pod::Spec.new do |s|
|
|
14
14
|
s.license = "MIT"
|
15
15
|
s.author = { package["author"]["name"] => package["author"]["email"] }
|
16
16
|
s.source = { :git => "https://github.com/software-mansion/react-native-gesture-handler", :tag => "#{s.version}" }
|
17
|
-
s.source_files = "
|
17
|
+
s.source_files = "apple/**/*.{h,m,mm}"
|
18
18
|
s.requires_arc = true
|
19
|
-
s.platforms = { ios: apple_platform, tvos: apple_platform }
|
19
|
+
s.platforms = { ios: apple_platform, tvos: apple_platform, osx: '10.15', visionos: '1.0' }
|
20
20
|
|
21
21
|
if defined?(install_modules_dependencies()) != nil
|
22
22
|
install_modules_dependencies(s);
|
@@ -0,0 +1,55 @@
|
|
1
|
+
package com.swmansion.gesturehandler;
|
2
|
+
|
3
|
+
import com.facebook.proguard.annotations.DoNotStrip;
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
5
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
6
|
+
import com.facebook.react.bridge.ReactMethod;
|
7
|
+
import com.facebook.react.bridge.ReadableMap;
|
8
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
9
|
+
import javax.annotation.Nonnull;
|
10
|
+
import com.facebook.react.bridge.ReactMethod;
|
11
|
+
|
12
|
+
public abstract class NativeRNGestureHandlerModuleSpec extends ReactContextBaseJavaModule implements TurboModule {
|
13
|
+
public static final String NAME = "RNGestureHandlerModule";
|
14
|
+
|
15
|
+
public NativeRNGestureHandlerModuleSpec(ReactApplicationContext reactContext) {
|
16
|
+
super(reactContext);
|
17
|
+
}
|
18
|
+
|
19
|
+
@Override
|
20
|
+
public @Nonnull String getName() {
|
21
|
+
return NAME;
|
22
|
+
}
|
23
|
+
|
24
|
+
@DoNotStrip
|
25
|
+
@ReactMethod
|
26
|
+
public abstract void handleSetJSResponder(double tag, boolean blockNativeResponder);
|
27
|
+
|
28
|
+
@DoNotStrip
|
29
|
+
@ReactMethod
|
30
|
+
public abstract void handleClearJSResponder();
|
31
|
+
|
32
|
+
@DoNotStrip
|
33
|
+
@ReactMethod
|
34
|
+
public abstract void createGestureHandler(String handlerName, double handlerTag, ReadableMap config);
|
35
|
+
|
36
|
+
@DoNotStrip
|
37
|
+
@ReactMethod
|
38
|
+
public abstract void attachGestureHandler(double handlerTag, double newView, double actionType);
|
39
|
+
|
40
|
+
@DoNotStrip
|
41
|
+
@ReactMethod
|
42
|
+
public abstract void updateGestureHandler(double handlerTag, ReadableMap newConfig);
|
43
|
+
|
44
|
+
@DoNotStrip
|
45
|
+
@ReactMethod
|
46
|
+
public abstract void dropGestureHandler(double handlerTag);
|
47
|
+
|
48
|
+
@DoNotStrip
|
49
|
+
@ReactMethod
|
50
|
+
public abstract boolean install();
|
51
|
+
|
52
|
+
@DoNotStrip
|
53
|
+
@ReactMethod
|
54
|
+
public abstract void flushOperations();
|
55
|
+
}
|
@@ -1,16 +1,29 @@
|
|
1
1
|
package com.swmansion.gesturehandler
|
2
2
|
|
3
|
-
import com.facebook.react.
|
3
|
+
import com.facebook.react.TurboReactPackage
|
4
|
+
import com.facebook.react.ViewManagerOnDemandReactPackage
|
5
|
+
import com.facebook.react.bridge.ModuleSpec
|
4
6
|
import com.facebook.react.bridge.NativeModule
|
5
7
|
import com.facebook.react.bridge.ReactApplicationContext
|
8
|
+
import com.facebook.react.module.annotations.ReactModule
|
9
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
11
|
+
import com.facebook.react.turbomodule.core.interfaces.TurboModule
|
6
12
|
import com.facebook.react.uimanager.ViewManager
|
7
13
|
import com.swmansion.gesturehandler.react.RNGestureHandlerButtonViewManager
|
8
14
|
import com.swmansion.gesturehandler.react.RNGestureHandlerModule
|
9
15
|
import com.swmansion.gesturehandler.react.RNGestureHandlerRootViewManager
|
10
16
|
|
11
|
-
class RNGestureHandlerPackage :
|
12
|
-
|
13
|
-
|
17
|
+
class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPackage {
|
18
|
+
private val viewManagers: Map<String, ModuleSpec> by lazy {
|
19
|
+
mapOf(
|
20
|
+
RNGestureHandlerRootViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
21
|
+
RNGestureHandlerRootViewManager()
|
22
|
+
},
|
23
|
+
RNGestureHandlerButtonViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
24
|
+
RNGestureHandlerButtonViewManager()
|
25
|
+
}
|
26
|
+
)
|
14
27
|
}
|
15
28
|
|
16
29
|
override fun createViewManagers(reactContext: ReactApplicationContext) =
|
@@ -18,4 +31,51 @@ class RNGestureHandlerPackage : ReactPackage {
|
|
18
31
|
RNGestureHandlerRootViewManager(),
|
19
32
|
RNGestureHandlerButtonViewManager()
|
20
33
|
)
|
34
|
+
|
35
|
+
override fun getViewManagerNames(reactContext: ReactApplicationContext?) =
|
36
|
+
viewManagers.keys.toList()
|
37
|
+
|
38
|
+
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> =
|
39
|
+
viewManagers.values.toMutableList()
|
40
|
+
|
41
|
+
override fun createViewManager(
|
42
|
+
reactContext: ReactApplicationContext?,
|
43
|
+
viewManagerName: String?
|
44
|
+
) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
|
45
|
+
|
46
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
47
|
+
return if (name == RNGestureHandlerModule.MODULE_NAME) {
|
48
|
+
RNGestureHandlerModule(reactContext)
|
49
|
+
} else {
|
50
|
+
null
|
51
|
+
}
|
52
|
+
}
|
53
|
+
|
54
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
55
|
+
try {
|
56
|
+
val reactModuleInfoProviderClass =
|
57
|
+
Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider")
|
58
|
+
return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider
|
59
|
+
} catch (e: ClassNotFoundException) {
|
60
|
+
return ReactModuleInfoProvider {
|
61
|
+
val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!!
|
62
|
+
|
63
|
+
mutableMapOf(
|
64
|
+
RNGestureHandlerModule.MODULE_NAME to ReactModuleInfo(
|
65
|
+
reactModule.name,
|
66
|
+
RNGestureHandlerModule::class.java.name,
|
67
|
+
reactModule.canOverrideExistingModule,
|
68
|
+
reactModule.needsEagerInit,
|
69
|
+
reactModule.hasConstants,
|
70
|
+
reactModule.isCxxModule,
|
71
|
+
TurboModule::class.java.isAssignableFrom(RNGestureHandlerModule::class.java)
|
72
|
+
)
|
73
|
+
)
|
74
|
+
}
|
75
|
+
} catch (e: InstantiationException) {
|
76
|
+
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
77
|
+
} catch (e: IllegalAccessException) {
|
78
|
+
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
79
|
+
}
|
80
|
+
}
|
21
81
|
}
|
package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
CHANGED
@@ -174,9 +174,19 @@ class GestureHandlerOrchestrator(
|
|
174
174
|
}
|
175
175
|
cleanupAwaitingHandlers()
|
176
176
|
|
177
|
-
//
|
178
|
-
//
|
177
|
+
// At this point the waiting handler is allowed to activate, so we need to send BEGAN -> ACTIVE event
|
178
|
+
// as it wasn't sent before. If handler has finished recognizing the gesture before it was allowed to
|
179
|
+
// activate, we also need to send ACTIVE -> END and END -> UNDETERMINED events, as it was blocked from
|
180
|
+
// sending events while waiting.
|
181
|
+
// There is one catch though - if the handler failed or was cancelled while waiting, relevant event has
|
182
|
+
// already been sent. The following chain would result in artificially activating that handler after the
|
183
|
+
// failure logic was ran and we don't want to do that.
|
184
|
+
if (currentState == GestureHandler.STATE_FAILED || currentState == GestureHandler.STATE_CANCELLED) {
|
185
|
+
return
|
186
|
+
}
|
187
|
+
|
179
188
|
handler.dispatchStateChange(GestureHandler.STATE_ACTIVE, GestureHandler.STATE_BEGAN)
|
189
|
+
|
180
190
|
if (currentState != GestureHandler.STATE_ACTIVE) {
|
181
191
|
handler.dispatchStateChange(GestureHandler.STATE_END, GestureHandler.STATE_ACTIVE)
|
182
192
|
if (currentState != GestureHandler.STATE_END) {
|
@@ -6,7 +6,6 @@ import android.view.MotionEvent
|
|
6
6
|
import com.facebook.react.ReactRootView
|
7
7
|
import com.facebook.react.bridge.JSApplicationIllegalArgumentException
|
8
8
|
import com.facebook.react.bridge.ReactApplicationContext
|
9
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule
|
10
9
|
import com.facebook.react.bridge.ReactMethod
|
11
10
|
import com.facebook.react.bridge.ReadableMap
|
12
11
|
import com.facebook.react.bridge.ReadableType
|
@@ -17,6 +16,7 @@ import com.facebook.react.uimanager.events.Event
|
|
17
16
|
import com.facebook.soloader.SoLoader
|
18
17
|
import com.swmansion.common.GestureHandlerStateManager
|
19
18
|
import com.swmansion.gesturehandler.BuildConfig
|
19
|
+
import com.swmansion.gesturehandler.NativeRNGestureHandlerModuleSpec
|
20
20
|
import com.swmansion.gesturehandler.ReanimatedEventDispatcher
|
21
21
|
import com.swmansion.gesturehandler.core.FlingGestureHandler
|
22
22
|
import com.swmansion.gesturehandler.core.GestureHandler
|
@@ -49,7 +49,7 @@ import com.swmansion.gesturehandler.react.eventbuilders.TapGestureHandlerEventDa
|
|
49
49
|
@Suppress("DEPRECATION")
|
50
50
|
@ReactModule(name = RNGestureHandlerModule.MODULE_NAME)
|
51
51
|
class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
52
|
-
|
52
|
+
NativeRNGestureHandlerModuleSpec(reactContext), GestureHandlerStateManager {
|
53
53
|
private abstract class HandlerFactory<T : GestureHandler<T>> {
|
54
54
|
abstract val type: Class<T>
|
55
55
|
abstract val name: String
|
@@ -333,13 +333,19 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
333
333
|
private val reanimatedEventDispatcher = ReanimatedEventDispatcher()
|
334
334
|
override fun getName() = MODULE_NAME
|
335
335
|
|
336
|
-
@ReactMethod
|
337
336
|
@Suppress("UNCHECKED_CAST")
|
338
|
-
fun <T : GestureHandler<T>>
|
337
|
+
private fun <T : GestureHandler<T>> createGestureHandlerHelper(
|
339
338
|
handlerName: String,
|
340
339
|
handlerTag: Int,
|
341
340
|
config: ReadableMap,
|
342
341
|
) {
|
342
|
+
|
343
|
+
if (registry.getHandler(handlerTag) !== null) {
|
344
|
+
throw IllegalStateException(
|
345
|
+
"Handler with tag $handlerTag already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors."
|
346
|
+
)
|
347
|
+
}
|
348
|
+
|
343
349
|
for (handlerFactory in handlerFactories as Array<HandlerFactory<T>>) {
|
344
350
|
if (handlerFactory.name == handlerName) {
|
345
351
|
val handler = handlerFactory.create(reactApplicationContext).apply {
|
@@ -356,7 +362,21 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
356
362
|
}
|
357
363
|
|
358
364
|
@ReactMethod
|
359
|
-
fun
|
365
|
+
override fun createGestureHandler(
|
366
|
+
handlerName: String,
|
367
|
+
handlerTagDouble: Double,
|
368
|
+
config: ReadableMap,
|
369
|
+
) {
|
370
|
+
val handlerTag = handlerTagDouble.toInt()
|
371
|
+
|
372
|
+
createGestureHandlerHelper(handlerName, handlerTag, config)
|
373
|
+
}
|
374
|
+
|
375
|
+
@ReactMethod
|
376
|
+
override fun attachGestureHandler(handlerTagDouble: Double, viewTagDouble: Double, actionTypeDouble: Double) {
|
377
|
+
val handlerTag = handlerTagDouble.toInt()
|
378
|
+
val viewTag = viewTagDouble.toInt()
|
379
|
+
val actionType = actionTypeDouble.toInt()
|
360
380
|
// We don't have to handle view flattening in any special way since handlers are stored as
|
361
381
|
// a map: viewTag -> [handler]. If the view with attached handlers was to be flattened
|
362
382
|
// then that viewTag simply wouldn't be visited when traversing the view hierarchy in the
|
@@ -366,9 +386,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
366
386
|
}
|
367
387
|
}
|
368
388
|
|
369
|
-
@ReactMethod
|
370
389
|
@Suppress("UNCHECKED_CAST")
|
371
|
-
fun <T : GestureHandler<T>>
|
390
|
+
private fun <T : GestureHandler<T>> updateGestureHandlerHelper(handlerTag: Int, config: ReadableMap) {
|
372
391
|
val handler = registry.getHandler(handlerTag) as T?
|
373
392
|
if (handler != null) {
|
374
393
|
val factory = findFactoryForHandler(handler)
|
@@ -381,19 +400,32 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
381
400
|
}
|
382
401
|
|
383
402
|
@ReactMethod
|
384
|
-
fun
|
403
|
+
override fun updateGestureHandler(handlerTagDouble: Double, config: ReadableMap) {
|
404
|
+
val handlerTag = handlerTagDouble.toInt()
|
405
|
+
|
406
|
+
updateGestureHandlerHelper(handlerTag, config)
|
407
|
+
}
|
408
|
+
|
409
|
+
@ReactMethod
|
410
|
+
override fun dropGestureHandler(handlerTagDouble: Double) {
|
411
|
+
val handlerTag = handlerTagDouble.toInt()
|
385
412
|
interactionManager.dropRelationsForHandlerWithTag(handlerTag)
|
386
413
|
registry.dropHandler(handlerTag)
|
387
414
|
}
|
388
415
|
|
389
416
|
@ReactMethod
|
390
|
-
fun handleSetJSResponder(
|
417
|
+
override fun handleSetJSResponder(viewTagDouble: Double, blockNativeResponder: Boolean) {
|
418
|
+
val viewTag = viewTagDouble.toInt()
|
391
419
|
val rootView = findRootHelperForViewAncestor(viewTag)
|
392
420
|
rootView?.handleSetJSResponder(viewTag, blockNativeResponder)
|
393
421
|
}
|
394
422
|
|
395
423
|
@ReactMethod
|
396
|
-
fun handleClearJSResponder() {
|
424
|
+
override fun handleClearJSResponder() {
|
425
|
+
}
|
426
|
+
|
427
|
+
@ReactMethod
|
428
|
+
override fun flushOperations() {
|
397
429
|
}
|
398
430
|
|
399
431
|
override fun setGestureHandlerState(handlerTag: Int, newState: Int) {
|
@@ -409,16 +441,18 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
409
441
|
}
|
410
442
|
|
411
443
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
412
|
-
fun install(): Boolean {
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
444
|
+
override fun install(): Boolean {
|
445
|
+
reactApplicationContext.runOnJSQueueThread {
|
446
|
+
try {
|
447
|
+
SoLoader.loadLibrary("gesturehandler")
|
448
|
+
val jsContext = reactApplicationContext.javaScriptContextHolder!!
|
449
|
+
decorateRuntime(jsContext.get())
|
450
|
+
} catch (exception: Exception) {
|
451
|
+
Log.w("[RNGestureHandler]", "Could not install JSI bindings.")
|
452
|
+
}
|
421
453
|
}
|
454
|
+
|
455
|
+
return true
|
422
456
|
}
|
423
457
|
|
424
458
|
private external fun decorateRuntime(jsiPtr: Long)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
#import "RNFlingHandler.h"
|
2
2
|
|
3
|
+
#if !TARGET_OS_OSX
|
4
|
+
|
3
5
|
@interface RNBetterSwipeGestureRecognizer : UISwipeGestureRecognizer
|
4
6
|
|
5
7
|
- (id)initWithGestureHandler:(RNGestureHandler *)gestureHandler;
|
@@ -22,7 +24,7 @@
|
|
22
24
|
return self;
|
23
25
|
}
|
24
26
|
|
25
|
-
- (void)touchesBegan:(NSSet<
|
27
|
+
- (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
26
28
|
{
|
27
29
|
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
|
28
30
|
[_gestureHandler reset];
|
@@ -38,21 +40,21 @@
|
|
38
40
|
}
|
39
41
|
}
|
40
42
|
|
41
|
-
- (void)touchesMoved:(NSSet<
|
43
|
+
- (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
42
44
|
{
|
43
45
|
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
|
44
46
|
[super touchesMoved:touches withEvent:event];
|
45
47
|
[_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
|
46
48
|
}
|
47
49
|
|
48
|
-
- (void)touchesEnded:(NSSet<
|
50
|
+
- (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
49
51
|
{
|
50
52
|
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
|
51
53
|
[super touchesEnded:touches withEvent:event];
|
52
54
|
[_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
|
53
55
|
}
|
54
56
|
|
55
|
-
- (void)touchesCancelled:(NSSet<
|
57
|
+
- (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
56
58
|
{
|
57
59
|
_lastPoint = [[[touches allObjects] objectAtIndex:0] locationInView:_gestureHandler.recognizer.view];
|
58
60
|
[super touchesCancelled:touches withEvent:event];
|
@@ -70,6 +72,7 @@
|
|
70
72
|
[_gestureHandler.pointerTracker reset];
|
71
73
|
_hasBegan = NO;
|
72
74
|
[super reset];
|
75
|
+
[_gestureHandler reset];
|
73
76
|
}
|
74
77
|
|
75
78
|
- (CGPoint)getLastLocation
|
@@ -91,6 +94,7 @@
|
|
91
94
|
}
|
92
95
|
return self;
|
93
96
|
}
|
97
|
+
|
94
98
|
- (void)resetConfig
|
95
99
|
{
|
96
100
|
[super resetConfig];
|
@@ -139,7 +143,7 @@
|
|
139
143
|
|
140
144
|
CGPoint viewAbsolutePosition =
|
141
145
|
[recognizer.view convertPoint:recognizer.view.bounds.origin
|
142
|
-
toView:
|
146
|
+
toView:RCTKeyWindow().rootViewController.view];
|
143
147
|
CGPoint locationInView = [recognizer getLastLocation];
|
144
148
|
|
145
149
|
return [RNGestureHandlerEventExtraData
|
@@ -148,5 +152,21 @@
|
|
148
152
|
viewAbsolutePosition.x + locationInView.x, viewAbsolutePosition.y + locationInView.y)
|
149
153
|
withNumberOfTouches:recognizer.numberOfTouches];
|
150
154
|
}
|
155
|
+
@end
|
156
|
+
|
157
|
+
#else
|
158
|
+
|
159
|
+
@implementation RNFlingGestureHandler
|
160
|
+
|
161
|
+
- (instancetype)initWithTag:(NSNumber *)tag
|
162
|
+
{
|
163
|
+
RCTLogWarn(@"FlingGestureHandler is not supported on macOS");
|
164
|
+
if ((self = [super initWithTag:tag])) {
|
165
|
+
_recognizer = [NSGestureRecognizer alloc];
|
166
|
+
}
|
167
|
+
return self;
|
168
|
+
}
|
151
169
|
|
152
170
|
@end
|
171
|
+
|
172
|
+
#endif
|
@@ -1,5 +1,6 @@
|
|
1
1
|
#import "RNForceTouchHandler.h"
|
2
2
|
|
3
|
+
#if !TARGET_OS_OSX
|
3
4
|
#import <UIKit/UIGestureRecognizerSubclass.h>
|
4
5
|
|
5
6
|
#import <React/RCTConvert.h>
|
@@ -17,7 +18,7 @@
|
|
17
18
|
|
18
19
|
@implementation RNForceTouchGestureRecognizer {
|
19
20
|
__weak RNGestureHandler *_gestureHandler;
|
20
|
-
|
21
|
+
RNGHUITouch *_firstTouch;
|
21
22
|
}
|
22
23
|
|
23
24
|
static const CGFloat defaultForce = 0;
|
@@ -37,7 +38,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
37
38
|
return self;
|
38
39
|
}
|
39
40
|
|
40
|
-
- (void)touchesBegan:(NSSet<
|
41
|
+
- (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
41
42
|
{
|
42
43
|
if (_firstTouch) {
|
43
44
|
// ignore rest of fingers
|
@@ -51,7 +52,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
51
52
|
self.state = UIGestureRecognizerStatePossible;
|
52
53
|
}
|
53
54
|
|
54
|
-
- (void)touchesMoved:(NSSet<
|
55
|
+
- (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
55
56
|
{
|
56
57
|
if (![touches containsObject:_firstTouch]) {
|
57
58
|
// Considered only the very first touch
|
@@ -85,7 +86,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
85
86
|
|
86
87
|
- (void)performFeedbackIfRequired
|
87
88
|
{
|
88
|
-
#if !TARGET_OS_TV
|
89
|
+
#if !TARGET_OS_TV && !TARGET_OS_VISION
|
89
90
|
if (_feedbackOnActivation) {
|
90
91
|
if (@available(iOS 10.0, *)) {
|
91
92
|
[[[UIImpactFeedbackGenerator alloc] initWithStyle:(UIImpactFeedbackStyleMedium)] impactOccurred];
|
@@ -94,7 +95,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
94
95
|
#endif
|
95
96
|
}
|
96
97
|
|
97
|
-
- (void)touchesEnded:(NSSet<
|
98
|
+
- (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
98
99
|
{
|
99
100
|
if (![touches containsObject:_firstTouch]) {
|
100
101
|
// Considered only the very first touch
|
@@ -109,13 +110,13 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
109
110
|
}
|
110
111
|
}
|
111
112
|
|
112
|
-
- (void)touchesCancelled:(NSSet<
|
113
|
+
- (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
113
114
|
{
|
114
115
|
[super touchesCancelled:touches withEvent:event];
|
115
116
|
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
|
116
117
|
}
|
117
118
|
|
118
|
-
- (void)handleForceWithTouches:(NSSet<
|
119
|
+
- (void)handleForceWithTouches:(NSSet<RNGHUITouch *> *)touches
|
119
120
|
{
|
120
121
|
_force = _firstTouch.force / _firstTouch.maximumPossibleForce;
|
121
122
|
}
|
@@ -124,6 +125,7 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
124
125
|
{
|
125
126
|
[_gestureHandler.pointerTracker reset];
|
126
127
|
[super reset];
|
128
|
+
[_gestureHandler reset];
|
127
129
|
_force = 0;
|
128
130
|
_firstTouch = NULL;
|
129
131
|
}
|
@@ -173,3 +175,19 @@ static const BOOL defaultFeedbackOnActivation = NO;
|
|
173
175
|
}
|
174
176
|
|
175
177
|
@end
|
178
|
+
|
179
|
+
#else
|
180
|
+
|
181
|
+
@implementation RNForceTouchHandler
|
182
|
+
|
183
|
+
- (instancetype)initWithTag:(NSNumber *)tag
|
184
|
+
{
|
185
|
+
if ((self = [super initWithTag:tag])) {
|
186
|
+
_recognizer = [NSGestureRecognizer alloc];
|
187
|
+
}
|
188
|
+
return self;
|
189
|
+
}
|
190
|
+
|
191
|
+
@end
|
192
|
+
|
193
|
+
#endif
|
@@ -7,6 +7,8 @@
|
|
7
7
|
|
8
8
|
#import "RNHoverHandler.h"
|
9
9
|
|
10
|
+
#if !TARGET_OS_OSX
|
11
|
+
|
10
12
|
#import <React/RCTConvert.h>
|
11
13
|
#import <UIKit/UIGestureRecognizerSubclass.h>
|
12
14
|
|
@@ -54,6 +56,12 @@ API_AVAILABLE(ios(13.4))
|
|
54
56
|
self.enabled = NO;
|
55
57
|
}
|
56
58
|
|
59
|
+
- (void)reset
|
60
|
+
{
|
61
|
+
[super reset];
|
62
|
+
[_gestureHandler reset];
|
63
|
+
}
|
64
|
+
|
57
65
|
- (UIPointerStyle *)pointerInteraction:(UIPointerInteraction *)interaction styleForRegion:(UIPointerRegion *)region
|
58
66
|
{
|
59
67
|
if (interaction.view != nil && _hoverEffect != RNGestureHandlerHoverEffectNone) {
|
@@ -85,7 +93,7 @@ API_AVAILABLE(ios(13.4))
|
|
85
93
|
- (instancetype)initWithTag:(NSNumber *)tag
|
86
94
|
{
|
87
95
|
#if TARGET_OS_TV
|
88
|
-
RCTLogWarn(@"
|
96
|
+
RCTLogWarn(@"HoverGestureHandler is not supported on tvOS");
|
89
97
|
#endif
|
90
98
|
|
91
99
|
if ((self = [super initWithTag:tag])) {
|
@@ -151,3 +159,20 @@ API_AVAILABLE(ios(13.4))
|
|
151
159
|
}
|
152
160
|
|
153
161
|
@end
|
162
|
+
|
163
|
+
#else
|
164
|
+
|
165
|
+
@implementation RNHoverGestureHandler
|
166
|
+
|
167
|
+
- (instancetype)initWithTag:(NSNumber *)tag
|
168
|
+
{
|
169
|
+
RCTLogWarn(@"HoverGestureHandler is not supported on macOS");
|
170
|
+
if ((self = [super initWithTag:tag])) {
|
171
|
+
_recognizer = [NSGestureRecognizer alloc];
|
172
|
+
}
|
173
|
+
return self;
|
174
|
+
}
|
175
|
+
|
176
|
+
@end
|
177
|
+
|
178
|
+
#endif
|
@@ -8,6 +8,8 @@
|
|
8
8
|
|
9
9
|
#import "RNLongPressHandler.h"
|
10
10
|
|
11
|
+
#if !TARGET_OS_OSX
|
12
|
+
|
11
13
|
#import <UIKit/UIGestureRecognizerSubclass.h>
|
12
14
|
|
13
15
|
#import <React/RCTConvert.h>
|
@@ -55,7 +57,7 @@
|
|
55
57
|
return CGPointMake(currentPosition.x - _initPosition.x, currentPosition.y - _initPosition.y);
|
56
58
|
}
|
57
59
|
|
58
|
-
- (void)touchesBegan:(NSSet<
|
60
|
+
- (void)touchesBegan:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
59
61
|
{
|
60
62
|
[super touchesBegan:touches withEvent:event];
|
61
63
|
[_gestureHandler.pointerTracker touchesBegan:touches withEvent:event];
|
@@ -66,7 +68,7 @@
|
|
66
68
|
[self triggerAction];
|
67
69
|
}
|
68
70
|
|
69
|
-
- (void)touchesMoved:(NSSet<
|
71
|
+
- (void)touchesMoved:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
70
72
|
{
|
71
73
|
[super touchesMoved:touches withEvent:event];
|
72
74
|
[_gestureHandler.pointerTracker touchesMoved:touches withEvent:event];
|
@@ -80,13 +82,13 @@
|
|
80
82
|
}
|
81
83
|
}
|
82
84
|
|
83
|
-
- (void)touchesEnded:(NSSet<
|
85
|
+
- (void)touchesEnded:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
84
86
|
{
|
85
87
|
[super touchesEnded:touches withEvent:event];
|
86
88
|
[_gestureHandler.pointerTracker touchesEnded:touches withEvent:event];
|
87
89
|
}
|
88
90
|
|
89
|
-
- (void)touchesCancelled:(NSSet<
|
91
|
+
- (void)touchesCancelled:(NSSet<RNGHUITouch *> *)touches withEvent:(UIEvent *)event
|
90
92
|
{
|
91
93
|
[super touchesCancelled:touches withEvent:event];
|
92
94
|
[_gestureHandler.pointerTracker touchesCancelled:touches withEvent:event];
|
@@ -101,6 +103,7 @@
|
|
101
103
|
[_gestureHandler.pointerTracker reset];
|
102
104
|
|
103
105
|
[super reset];
|
106
|
+
[_gestureHandler reset];
|
104
107
|
}
|
105
108
|
|
106
109
|
- (NSUInteger)getDuration
|
@@ -181,3 +184,20 @@
|
|
181
184
|
withDuration:[(RNBetterLongPressGestureRecognizer *)recognizer getDuration]];
|
182
185
|
}
|
183
186
|
@end
|
187
|
+
|
188
|
+
#else
|
189
|
+
|
190
|
+
@implementation RNLongPressGestureHandler
|
191
|
+
|
192
|
+
- (instancetype)initWithTag:(NSNumber *)tag
|
193
|
+
{
|
194
|
+
RCTLogWarn(@"LongPressGestureHandler is not supported on macOS");
|
195
|
+
if ((self = [super initWithTag:tag])) {
|
196
|
+
_recognizer = [NSGestureRecognizer alloc];
|
197
|
+
}
|
198
|
+
return self;
|
199
|
+
}
|
200
|
+
|
201
|
+
@end
|
202
|
+
|
203
|
+
#endif
|