react-native-gesture-handler 2.14.1 → 2.16.0-rc.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 +3 -24
- package/android/build.gradle +1 -1
- package/android/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java +55 -0
- package/android/src/main/java/com/swmansion/gesturehandler/RNGestureHandlerPackage.kt +69 -4
- package/android/src/main/java/com/swmansion/gesturehandler/core/FlingGestureHandler.kt +4 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +69 -0
- package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +37 -21
- 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/react/RNGestureHandlerModule.kt +61 -24
- package/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerRootHelper.kt +3 -2
- 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/{ios → apple}/Handlers/RNFlingHandler.m +29 -8
- package/{ios → apple}/Handlers/RNForceTouchHandler.m +28 -8
- package/{ios → apple}/Handlers/RNHoverHandler.m +28 -2
- package/{ios → apple}/Handlers/RNLongPressHandler.m +27 -5
- package/{ios → apple}/Handlers/RNManualHandler.m +25 -4
- package/{ios → apple}/Handlers/RNNativeViewHandler.mm +51 -13
- package/{ios → apple}/Handlers/RNPanHandler.m +106 -16
- package/apple/Handlers/RNPinchHandler.m +175 -0
- package/apple/Handlers/RNRotationHandler.m +169 -0
- package/{ios → apple}/Handlers/RNTapHandler.m +98 -26
- package/apple/RNGHUIKit.h +27 -0
- package/{ios → apple}/RNGestureHandler.h +12 -3
- package/{ios → apple}/RNGestureHandler.m +68 -7
- 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 +19 -10
- package/{ios → apple}/RNGestureHandlerEvents.m +29 -11
- package/{ios → apple}/RNGestureHandlerManager.h +7 -2
- package/{ios → apple}/RNGestureHandlerManager.mm +78 -17
- package/apple/RNGestureHandlerModule.h +19 -0
- package/{ios → apple}/RNGestureHandlerModule.mm +69 -69
- package/{ios → apple}/RNGestureHandlerPointerTracker.h +5 -5
- package/{ios → apple}/RNGestureHandlerPointerTracker.m +19 -14
- package/apple/RNGestureHandlerPointerType.h +8 -0
- 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/PointerType.js +16 -0
- package/lib/commonjs/PointerType.js.map +1 -0
- 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/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/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/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 +16 -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 +19 -4
- 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 -24
- package/lib/commonjs/web/interfaces.js.map +1 -1
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.js +3 -3
- package/lib/commonjs/web/tools/GestureHandlerOrchestrator.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 +40 -10
- package/lib/commonjs/web/tools/PointerEventManager.js.map +1 -1
- package/lib/commonjs/web/tools/TouchEventManager.js +3 -2
- package/lib/commonjs/web/tools/TouchEventManager.js.map +1 -1
- package/lib/commonjs/web/utils.js +6 -0
- package/lib/commonjs/web/utils.js.map +1 -1
- package/lib/module/PointerType.js +9 -0
- package/lib/module/PointerType.js.map +1 -0
- 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/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/getShadowNodeFromRef.js +19 -2
- package/lib/module/getShadowNodeFromRef.js.map +1 -1
- package/lib/module/handlers/createHandler.js +6 -1
- package/lib/module/handlers/createHandler.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 +2 -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 +18 -4
- 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 -20
- package/lib/module/web/interfaces.js.map +1 -1
- package/lib/module/web/tools/GestureHandlerOrchestrator.js +2 -2
- package/lib/module/web/tools/GestureHandlerOrchestrator.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 +41 -12
- package/lib/module/web/tools/PointerEventManager.js.map +1 -1
- package/lib/module/web/tools/TouchEventManager.js +2 -2
- package/lib/module/web/tools/TouchEventManager.js.map +1 -1
- package/lib/module/web/utils.js +2 -0
- package/lib/module/web/utils.js.map +1 -1
- package/lib/typescript/PointerType.d.ts +6 -0
- 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/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/getShadowNodeFromRef.d.ts +1 -1
- 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 +6 -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 +2 -0
- package/lib/typescript/specs/NativeRNGestureHandlerModule.d.ts +14 -0
- package/lib/typescript/web/handlers/GestureHandler.d.ts +4 -1
- package/lib/typescript/web/interfaces.d.ts +10 -14
- 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/lib/typescript/web/utils.d.ts +2 -0
- package/package.json +14 -11
- package/src/PointerType.ts +6 -0
- package/src/RNGestureHandlerModule.ts +4 -49
- package/src/RNGestureHandlerModule.windows.ts +18 -100
- package/src/components/DrawerLayout.tsx +15 -0
- 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/getShadowNodeFromRef.ts +28 -6
- package/src/handlers/createHandler.tsx +6 -0
- package/src/handlers/gestureHandlerCommon.ts +7 -0
- package/src/handlers/gestures/GestureDetector.tsx +16 -2
- package/src/handlers/gestures/gesture.ts +6 -0
- package/src/index.ts +2 -0
- package/src/specs/NativeRNGestureHandlerModule.ts +26 -0
- package/src/web/handlers/FlingGestureHandler.ts +4 -0
- package/src/web/handlers/GestureHandler.ts +20 -2
- 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 +12 -17
- package/src/web/tools/GestureHandlerDelegate.ts +3 -0
- package/src/web/tools/GestureHandlerOrchestrator.ts +2 -2
- package/src/web/tools/GestureHandlerWebDelegate.ts +39 -0
- package/src/web/tools/NodeManager.ts +5 -1
- package/src/web/tools/PointerEventManager.ts +46 -10
- package/src/web/tools/TouchEventManager.ts +2 -8
- package/src/web/utils.ts +9 -0
- package/ios/Handlers/RNPinchHandler.m +0 -95
- package/ios/Handlers/RNRotationHandler.m +0 -93
- 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}/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
@@ -1,8 +1,5 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
|
-
new_arch_enabled = ENV['RCT_NEW_ARCH_ENABLED'] == '1'
|
4
|
-
apple_platform = new_arch_enabled ? '11.0' : '9.0'
|
5
|
-
|
6
3
|
Pod::Spec.new do |s|
|
7
4
|
# NPM package specification
|
8
5
|
package = JSON.parse(File.read(File.join(File.dirname(__FILE__), "package.json")))
|
@@ -14,31 +11,13 @@ Pod::Spec.new do |s|
|
|
14
11
|
s.license = "MIT"
|
15
12
|
s.author = { package["author"]["name"] => package["author"]["email"] }
|
16
13
|
s.source = { :git => "https://github.com/software-mansion/react-native-gesture-handler", :tag => "#{s.version}" }
|
17
|
-
s.source_files = "
|
14
|
+
s.source_files = "apple/**/*.{h,m,mm}"
|
18
15
|
s.requires_arc = true
|
19
|
-
s.platforms = { ios:
|
16
|
+
s.platforms = { ios: '11.0', tvos: '11.0', osx: '10.15', visionos: '1.0' }
|
20
17
|
|
21
18
|
if defined?(install_modules_dependencies()) != nil
|
22
19
|
install_modules_dependencies(s);
|
23
20
|
else
|
24
|
-
|
25
|
-
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
26
|
-
|
27
|
-
s.pod_target_xcconfig = {
|
28
|
-
'HEADER_SEARCH_PATHS' => '"$(PODS_ROOT)/boost" "$(PODS_ROOT)/boost-for-react-native" "$(PODS_ROOT)/RCT-Folly"',
|
29
|
-
'CLANG_CXX_LANGUAGE_STANDARD' => 'c++17',
|
30
|
-
}
|
31
|
-
s.compiler_flags = folly_compiler_flags + ' -DRCT_NEW_ARCH_ENABLED'
|
32
|
-
|
33
|
-
s.dependency "React"
|
34
|
-
s.dependency "React-RCTFabric" # This is for fabric component
|
35
|
-
s.dependency "React-Codegen"
|
36
|
-
s.dependency "RCT-Folly"
|
37
|
-
s.dependency "RCTRequired"
|
38
|
-
s.dependency "RCTTypeSafety"
|
39
|
-
s.dependency "ReactCommon/turbomodule/core"
|
40
|
-
else
|
41
|
-
s.dependency "React-Core"
|
42
|
-
end
|
21
|
+
s.dependency "React-Core"
|
43
22
|
end
|
44
23
|
end
|
package/android/build.gradle
CHANGED
@@ -136,7 +136,7 @@ android {
|
|
136
136
|
var appProject = rootProject.allprojects.find {it.plugins.hasPlugin('com.android.application')}
|
137
137
|
externalNativeBuild {
|
138
138
|
cmake {
|
139
|
-
cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++
|
139
|
+
cppFlags "-O2", "-frtti", "-fexceptions", "-Wall", "-Werror", "-std=c++20", "-DANDROID"
|
140
140
|
arguments "-DAPP_BUILD_DIR=${appProject.buildDir}",
|
141
141
|
"-DREACT_NATIVE_DIR=${REACT_NATIVE_DIR}",
|
142
142
|
"-DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}",
|
@@ -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,34 @@
|
|
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.annotations.ReactModuleList
|
10
|
+
import com.facebook.react.module.model.ReactModuleInfo
|
11
|
+
import com.facebook.react.module.model.ReactModuleInfoProvider
|
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
|
-
|
12
|
-
|
13
|
-
|
17
|
+
@ReactModuleList(
|
18
|
+
nativeModules = [
|
19
|
+
RNGestureHandlerModule::class
|
20
|
+
]
|
21
|
+
)
|
22
|
+
class RNGestureHandlerPackage : TurboReactPackage(), ViewManagerOnDemandReactPackage {
|
23
|
+
private val viewManagers: Map<String, ModuleSpec> by lazy {
|
24
|
+
mapOf(
|
25
|
+
RNGestureHandlerRootViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
26
|
+
RNGestureHandlerRootViewManager()
|
27
|
+
},
|
28
|
+
RNGestureHandlerButtonViewManager.REACT_CLASS to ModuleSpec.viewManagerSpec {
|
29
|
+
RNGestureHandlerButtonViewManager()
|
30
|
+
}
|
31
|
+
)
|
14
32
|
}
|
15
33
|
|
16
34
|
override fun createViewManagers(reactContext: ReactApplicationContext) =
|
@@ -18,4 +36,51 @@ class RNGestureHandlerPackage : ReactPackage {
|
|
18
36
|
RNGestureHandlerRootViewManager(),
|
19
37
|
RNGestureHandlerButtonViewManager()
|
20
38
|
)
|
39
|
+
|
40
|
+
override fun getViewManagerNames(reactContext: ReactApplicationContext?) =
|
41
|
+
viewManagers.keys.toList()
|
42
|
+
|
43
|
+
override fun getViewManagers(reactContext: ReactApplicationContext?): MutableList<ModuleSpec> =
|
44
|
+
viewManagers.values.toMutableList()
|
45
|
+
|
46
|
+
override fun createViewManager(
|
47
|
+
reactContext: ReactApplicationContext?,
|
48
|
+
viewManagerName: String?
|
49
|
+
) = viewManagers[viewManagerName]?.provider?.get() as? ViewManager<*, *>
|
50
|
+
|
51
|
+
override fun getModule(name: String, reactContext: ReactApplicationContext): NativeModule? {
|
52
|
+
return if (name == RNGestureHandlerModule.NAME) {
|
53
|
+
RNGestureHandlerModule(reactContext)
|
54
|
+
} else {
|
55
|
+
null
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
override fun getReactModuleInfoProvider(): ReactModuleInfoProvider {
|
60
|
+
try {
|
61
|
+
val reactModuleInfoProviderClass =
|
62
|
+
Class.forName("com.swmansion.gesturehandler.RNGestureHandlerPackage$\$ReactModuleInfoProvider")
|
63
|
+
return reactModuleInfoProviderClass.newInstance() as ReactModuleInfoProvider
|
64
|
+
} catch (e: ClassNotFoundException) {
|
65
|
+
return ReactModuleInfoProvider {
|
66
|
+
val reactModule: ReactModule = RNGestureHandlerModule::class.java.getAnnotation(ReactModule::class.java)!!
|
67
|
+
|
68
|
+
mutableMapOf(
|
69
|
+
RNGestureHandlerModule.NAME to ReactModuleInfo(
|
70
|
+
reactModule.name,
|
71
|
+
RNGestureHandlerModule::class.java.name,
|
72
|
+
reactModule.canOverrideExistingModule,
|
73
|
+
reactModule.needsEagerInit,
|
74
|
+
reactModule.hasConstants,
|
75
|
+
reactModule.isCxxModule,
|
76
|
+
true
|
77
|
+
)
|
78
|
+
)
|
79
|
+
}
|
80
|
+
} catch (e: InstantiationException) {
|
81
|
+
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
82
|
+
} catch (e: IllegalAccessException) {
|
83
|
+
throw RuntimeException("No ReactModuleInfoProvider for RNGestureHandlerPackage$\$ReactModuleInfoProvider", e)
|
84
|
+
}
|
85
|
+
}
|
21
86
|
}
|
@@ -67,6 +67,10 @@ class FlingGestureHandler : GestureHandler<FlingGestureHandler>() {
|
|
67
67
|
}
|
68
68
|
|
69
69
|
override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
|
70
|
+
if (!shouldActivateWithMouse(sourceEvent)) {
|
71
|
+
return
|
72
|
+
}
|
73
|
+
|
70
74
|
val state = state
|
71
75
|
if (state == STATE_UNDETERMINED) {
|
72
76
|
startFling(sourceEvent)
|
@@ -5,6 +5,7 @@ import android.content.Context
|
|
5
5
|
import android.content.ContextWrapper
|
6
6
|
import android.graphics.PointF
|
7
7
|
import android.graphics.Rect
|
8
|
+
import android.os.Build
|
8
9
|
import android.view.MotionEvent
|
9
10
|
import android.view.MotionEvent.PointerCoords
|
10
11
|
import android.view.MotionEvent.PointerProperties
|
@@ -67,6 +68,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
67
68
|
protected var orchestrator: GestureHandlerOrchestrator? = null
|
68
69
|
private var onTouchEventListener: OnTouchEventListener? = null
|
69
70
|
private var interactionController: GestureHandlerInteractionController? = null
|
71
|
+
var pointerType: Int = POINTER_TYPE_OTHER
|
72
|
+
private set
|
73
|
+
|
74
|
+
protected var mouseButton = 0
|
70
75
|
|
71
76
|
@Suppress("UNCHECKED_CAST")
|
72
77
|
protected fun self(): ConcreteGestureHandlerT = this as ConcreteGestureHandlerT
|
@@ -159,6 +164,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
159
164
|
fun setInteractionController(controller: GestureHandlerInteractionController?): ConcreteGestureHandlerT =
|
160
165
|
applySelf { interactionController = controller }
|
161
166
|
|
167
|
+
fun setMouseButton(mouseButton: Int) = apply {
|
168
|
+
this.mouseButton = mouseButton
|
169
|
+
}
|
170
|
+
|
162
171
|
fun prepare(view: View?, orchestrator: GestureHandlerOrchestrator?) {
|
163
172
|
check(!(this.view != null || this.orchestrator != null)) { "Already prepared or hasn't been reset" }
|
164
173
|
Arrays.fill(trackedPointerIDs, -1)
|
@@ -371,6 +380,11 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
371
380
|
lastAbsolutePositionY = GestureUtils.getLastPointerY(adaptedTransformedEvent, true)
|
372
381
|
lastEventOffsetX = adaptedTransformedEvent.rawX - adaptedTransformedEvent.x
|
373
382
|
lastEventOffsetY = adaptedTransformedEvent.rawY - adaptedTransformedEvent.y
|
383
|
+
|
384
|
+
if (sourceEvent.action == MotionEvent.ACTION_DOWN || sourceEvent.action == MotionEvent.ACTION_HOVER_ENTER || sourceEvent.action == MotionEvent.ACTION_HOVER_MOVE) {
|
385
|
+
setPointerType(sourceEvent)
|
386
|
+
}
|
387
|
+
|
374
388
|
if (sourceEvent.action == MotionEvent.ACTION_HOVER_ENTER ||
|
375
389
|
sourceEvent.action == MotionEvent.ACTION_HOVER_MOVE ||
|
376
390
|
sourceEvent.action == MotionEvent.ACTION_HOVER_EXIT
|
@@ -688,6 +702,46 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
688
702
|
protected open fun onReset() {}
|
689
703
|
protected open fun onCancel() {}
|
690
704
|
|
705
|
+
private fun isButtonInConfig(clickedButton: Int): Boolean {
|
706
|
+
if (mouseButton == 0) {
|
707
|
+
return clickedButton == MotionEvent.BUTTON_PRIMARY
|
708
|
+
}
|
709
|
+
|
710
|
+
return clickedButton and mouseButton != 0
|
711
|
+
}
|
712
|
+
|
713
|
+
protected fun shouldActivateWithMouse(sourceEvent: MotionEvent): Boolean {
|
714
|
+
// While using mouse, we get both sets of events, for example ACTION_DOWN and ACTION_BUTTON_PRESS. That's why we want to take actions to only one of them.
|
715
|
+
// On API >= 23, we will use events with infix BUTTON, otherwise we use standard action events (like ACTION_DOWN).
|
716
|
+
|
717
|
+
with(sourceEvent) {
|
718
|
+
// To use actionButton, we need API >= 23.
|
719
|
+
if (getToolType(0) == MotionEvent.TOOL_TYPE_MOUSE && Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
720
|
+
// While using mouse, we want to ignore default events for touch.
|
721
|
+
if (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_POINTER_UP || action == MotionEvent.ACTION_POINTER_DOWN) {
|
722
|
+
return@shouldActivateWithMouse false
|
723
|
+
}
|
724
|
+
|
725
|
+
// We don't want to do anything if wrong button was clicked. If we received event for BUTTON, we have to use actionButton to get which one was clicked.
|
726
|
+
if (action != MotionEvent.ACTION_MOVE && !isButtonInConfig(actionButton)) {
|
727
|
+
return@shouldActivateWithMouse false
|
728
|
+
}
|
729
|
+
|
730
|
+
// When we receive ACTION_MOVE, we have to check buttonState field.
|
731
|
+
if (action == MotionEvent.ACTION_MOVE && !isButtonInConfig(buttonState)) {
|
732
|
+
return@shouldActivateWithMouse false
|
733
|
+
}
|
734
|
+
} else if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
735
|
+
// We do not fully support mouse below API 23, so we will ignore BUTTON events.
|
736
|
+
if (action == MotionEvent.ACTION_BUTTON_PRESS || action == MotionEvent.ACTION_BUTTON_RELEASE) {
|
737
|
+
return@shouldActivateWithMouse false
|
738
|
+
}
|
739
|
+
}
|
740
|
+
}
|
741
|
+
|
742
|
+
return true
|
743
|
+
}
|
744
|
+
|
691
745
|
/**
|
692
746
|
* Transforms a point in the coordinate space of the wrapperView (GestureHandlerRootView) to
|
693
747
|
* coordinate space of the view the gesture is attached to.
|
@@ -721,6 +775,17 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
721
775
|
isWithinBounds = false
|
722
776
|
}
|
723
777
|
|
778
|
+
private fun setPointerType(event: MotionEvent) {
|
779
|
+
val pointerIndex = event.actionIndex
|
780
|
+
|
781
|
+
pointerType = when (event.getToolType(pointerIndex)) {
|
782
|
+
MotionEvent.TOOL_TYPE_FINGER -> POINTER_TYPE_TOUCH
|
783
|
+
MotionEvent.TOOL_TYPE_STYLUS -> POINTER_TYPE_STYLUS
|
784
|
+
MotionEvent.TOOL_TYPE_MOUSE -> POINTER_TYPE_MOUSE
|
785
|
+
else -> POINTER_TYPE_OTHER
|
786
|
+
}
|
787
|
+
}
|
788
|
+
|
724
789
|
fun setOnTouchEventListener(listener: OnTouchEventListener?): GestureHandler<*> {
|
725
790
|
onTouchEventListener = listener
|
726
791
|
return this
|
@@ -763,6 +828,10 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
|
|
763
828
|
const val ACTION_TYPE_NATIVE_ANIMATED_EVENT = 2
|
764
829
|
const val ACTION_TYPE_JS_FUNCTION_OLD_API = 3
|
765
830
|
const val ACTION_TYPE_JS_FUNCTION_NEW_API = 4
|
831
|
+
const val POINTER_TYPE_TOUCH = 0
|
832
|
+
const val POINTER_TYPE_STYLUS = 1
|
833
|
+
const val POINTER_TYPE_MOUSE = 2
|
834
|
+
const val POINTER_TYPE_OTHER = 3
|
766
835
|
private const val MAX_POINTERS_COUNT = 12
|
767
836
|
private lateinit var pointerProps: Array<PointerProperties?>
|
768
837
|
private lateinit var pointerCoords: Array<PointerCoords?>
|
package/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt
CHANGED
@@ -101,27 +101,33 @@ class GestureHandlerOrchestrator(
|
|
101
101
|
fun onHandlerStateChange(handler: GestureHandler<*>, newState: Int, prevState: Int) {
|
102
102
|
handlingChangeSemaphore += 1
|
103
103
|
if (isFinished(newState)) {
|
104
|
+
// We have to loop through copy in order to avoid modifying collection
|
105
|
+
// while iterating over its elements
|
106
|
+
val currentlyAwaitingHandlers = awaitingHandlers.toList()
|
107
|
+
|
104
108
|
// if there were handlers awaiting completion of this handler, we can trigger active state
|
105
|
-
for (otherHandler in
|
106
|
-
if (shouldHandlerWaitForOther(otherHandler, handler)) {
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
// gesture has failed recognition, we may try activating
|
123
|
-
tryActivate(otherHandler)
|
109
|
+
for (otherHandler in currentlyAwaitingHandlers) {
|
110
|
+
if (!shouldHandlerWaitForOther(otherHandler, handler)) {
|
111
|
+
continue
|
112
|
+
}
|
113
|
+
|
114
|
+
if (newState == GestureHandler.STATE_END) {
|
115
|
+
// gesture has ended, we need to kill the awaiting handler
|
116
|
+
otherHandler.cancel()
|
117
|
+
if (otherHandler.state == GestureHandler.STATE_END) {
|
118
|
+
// Handle edge case, where discrete gestures end immediately after activation thus
|
119
|
+
// their state is set to END and when the gesture they are waiting for activates they
|
120
|
+
// should be cancelled, however `cancel` was never sent as gestures were already in the END state.
|
121
|
+
// Send synthetic BEGAN -> CANCELLED to properly handle JS logic
|
122
|
+
otherHandler.dispatchStateChange(
|
123
|
+
GestureHandler.STATE_CANCELLED,
|
124
|
+
GestureHandler.STATE_BEGAN
|
125
|
+
)
|
124
126
|
}
|
127
|
+
otherHandler.isAwaiting = false
|
128
|
+
} else {
|
129
|
+
// gesture has failed recognition, we may try activating
|
130
|
+
tryActivate(otherHandler)
|
125
131
|
}
|
126
132
|
}
|
127
133
|
cleanupAwaitingHandlers()
|
@@ -174,9 +180,19 @@ class GestureHandlerOrchestrator(
|
|
174
180
|
}
|
175
181
|
cleanupAwaitingHandlers()
|
176
182
|
|
177
|
-
//
|
178
|
-
//
|
183
|
+
// At this point the waiting handler is allowed to activate, so we need to send BEGAN -> ACTIVE event
|
184
|
+
// as it wasn't sent before. If handler has finished recognizing the gesture before it was allowed to
|
185
|
+
// activate, we also need to send ACTIVE -> END and END -> UNDETERMINED events, as it was blocked from
|
186
|
+
// sending events while waiting.
|
187
|
+
// There is one catch though - if the handler failed or was cancelled while waiting, relevant event has
|
188
|
+
// already been sent. The following chain would result in artificially activating that handler after the
|
189
|
+
// failure logic was ran and we don't want to do that.
|
190
|
+
if (currentState == GestureHandler.STATE_FAILED || currentState == GestureHandler.STATE_CANCELLED) {
|
191
|
+
return
|
192
|
+
}
|
193
|
+
|
179
194
|
handler.dispatchStateChange(GestureHandler.STATE_ACTIVE, GestureHandler.STATE_BEGAN)
|
195
|
+
|
180
196
|
if (currentState != GestureHandler.STATE_ACTIVE) {
|
181
197
|
handler.dispatchStateChange(GestureHandler.STATE_END, GestureHandler.STATE_ACTIVE)
|
182
198
|
if (currentState != GestureHandler.STATE_END) {
|
@@ -38,6 +38,10 @@ class LongPressGestureHandler(context: Context) : GestureHandler<LongPressGestur
|
|
38
38
|
}
|
39
39
|
|
40
40
|
override fun onHandle(event: MotionEvent, sourceEvent: MotionEvent) {
|
41
|
+
if (!shouldActivateWithMouse(sourceEvent)) {
|
42
|
+
return
|
43
|
+
}
|
44
|
+
|
41
45
|
if (state == STATE_UNDETERMINED) {
|
42
46
|
previousTime = SystemClock.uptimeMillis()
|
43
47
|
startTime = previousTime
|
@@ -51,7 +55,7 @@ class LongPressGestureHandler(context: Context) : GestureHandler<LongPressGestur
|
|
51
55
|
activate()
|
52
56
|
}
|
53
57
|
}
|
54
|
-
if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) {
|
58
|
+
if (sourceEvent.actionMasked == MotionEvent.ACTION_UP || sourceEvent.actionMasked == MotionEvent.ACTION_BUTTON_RELEASE) {
|
55
59
|
handler?.let {
|
56
60
|
it.removeCallbacksAndMessages(null)
|
57
61
|
handler = null
|
@@ -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
|
}
|
@@ -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
|
@@ -47,9 +47,9 @@ 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>> {
|
54
54
|
abstract val type: Class<T>
|
55
55
|
abstract val name: String
|
@@ -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,15 +334,21 @@ 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
|
-
@ReactMethod
|
337
339
|
@Suppress("UNCHECKED_CAST")
|
338
|
-
fun <T : GestureHandler<T>>
|
340
|
+
private fun <T : GestureHandler<T>> createGestureHandlerHelper(
|
339
341
|
handlerName: String,
|
340
342
|
handlerTag: Int,
|
341
343
|
config: ReadableMap,
|
342
344
|
) {
|
345
|
+
|
346
|
+
if (registry.getHandler(handlerTag) !== null) {
|
347
|
+
throw IllegalStateException(
|
348
|
+
"Handler with tag $handlerTag already exists. Please ensure that no Gesture instance is used across multiple GestureDetectors."
|
349
|
+
)
|
350
|
+
}
|
351
|
+
|
343
352
|
for (handlerFactory in handlerFactories as Array<HandlerFactory<T>>) {
|
344
353
|
if (handlerFactory.name == handlerName) {
|
345
354
|
val handler = handlerFactory.create(reactApplicationContext).apply {
|
@@ -356,7 +365,21 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
356
365
|
}
|
357
366
|
|
358
367
|
@ReactMethod
|
359
|
-
fun
|
368
|
+
override fun createGestureHandler(
|
369
|
+
handlerName: String,
|
370
|
+
handlerTagDouble: Double,
|
371
|
+
config: ReadableMap,
|
372
|
+
) {
|
373
|
+
val handlerTag = handlerTagDouble.toInt()
|
374
|
+
|
375
|
+
createGestureHandlerHelper(handlerName, handlerTag, config)
|
376
|
+
}
|
377
|
+
|
378
|
+
@ReactMethod
|
379
|
+
override fun attachGestureHandler(handlerTagDouble: Double, viewTagDouble: Double, actionTypeDouble: Double) {
|
380
|
+
val handlerTag = handlerTagDouble.toInt()
|
381
|
+
val viewTag = viewTagDouble.toInt()
|
382
|
+
val actionType = actionTypeDouble.toInt()
|
360
383
|
// We don't have to handle view flattening in any special way since handlers are stored as
|
361
384
|
// a map: viewTag -> [handler]. If the view with attached handlers was to be flattened
|
362
385
|
// then that viewTag simply wouldn't be visited when traversing the view hierarchy in the
|
@@ -366,9 +389,8 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
366
389
|
}
|
367
390
|
}
|
368
391
|
|
369
|
-
@ReactMethod
|
370
392
|
@Suppress("UNCHECKED_CAST")
|
371
|
-
fun <T : GestureHandler<T>>
|
393
|
+
private fun <T : GestureHandler<T>> updateGestureHandlerHelper(handlerTag: Int, config: ReadableMap) {
|
372
394
|
val handler = registry.getHandler(handlerTag) as T?
|
373
395
|
if (handler != null) {
|
374
396
|
val factory = findFactoryForHandler(handler)
|
@@ -381,19 +403,32 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
381
403
|
}
|
382
404
|
|
383
405
|
@ReactMethod
|
384
|
-
fun
|
406
|
+
override fun updateGestureHandler(handlerTagDouble: Double, config: ReadableMap) {
|
407
|
+
val handlerTag = handlerTagDouble.toInt()
|
408
|
+
|
409
|
+
updateGestureHandlerHelper(handlerTag, config)
|
410
|
+
}
|
411
|
+
|
412
|
+
@ReactMethod
|
413
|
+
override fun dropGestureHandler(handlerTagDouble: Double) {
|
414
|
+
val handlerTag = handlerTagDouble.toInt()
|
385
415
|
interactionManager.dropRelationsForHandlerWithTag(handlerTag)
|
386
416
|
registry.dropHandler(handlerTag)
|
387
417
|
}
|
388
418
|
|
389
419
|
@ReactMethod
|
390
|
-
fun handleSetJSResponder(
|
420
|
+
override fun handleSetJSResponder(viewTagDouble: Double, blockNativeResponder: Boolean) {
|
421
|
+
val viewTag = viewTagDouble.toInt()
|
391
422
|
val rootView = findRootHelperForViewAncestor(viewTag)
|
392
423
|
rootView?.handleSetJSResponder(viewTag, blockNativeResponder)
|
393
424
|
}
|
394
425
|
|
395
426
|
@ReactMethod
|
396
|
-
fun handleClearJSResponder() {
|
427
|
+
override fun handleClearJSResponder() {
|
428
|
+
}
|
429
|
+
|
430
|
+
@ReactMethod
|
431
|
+
override fun flushOperations() {
|
397
432
|
}
|
398
433
|
|
399
434
|
override fun setGestureHandlerState(handlerTag: Int, newState: Int) {
|
@@ -409,16 +444,18 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
409
444
|
}
|
410
445
|
|
411
446
|
@ReactMethod(isBlockingSynchronousMethod = true)
|
412
|
-
fun install(): Boolean {
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
447
|
+
override fun install(): Boolean {
|
448
|
+
reactApplicationContext.runOnJSQueueThread {
|
449
|
+
try {
|
450
|
+
SoLoader.loadLibrary("gesturehandler")
|
451
|
+
val jsContext = reactApplicationContext.javaScriptContextHolder!!
|
452
|
+
decorateRuntime(jsContext.get())
|
453
|
+
} catch (exception: Exception) {
|
454
|
+
Log.w("[RNGestureHandler]", "Could not install JSI bindings.")
|
455
|
+
}
|
421
456
|
}
|
457
|
+
|
458
|
+
return true
|
422
459
|
}
|
423
460
|
|
424
461
|
private external fun decorateRuntime(jsiPtr: Long)
|
@@ -442,7 +479,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
442
479
|
)
|
443
480
|
}
|
444
481
|
|
445
|
-
override fun
|
482
|
+
override fun invalidate() {
|
446
483
|
registry.dropAllHandlers()
|
447
484
|
interactionManager.reset()
|
448
485
|
synchronized(roots) {
|
@@ -455,7 +492,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
455
492
|
}
|
456
493
|
}
|
457
494
|
}
|
458
|
-
super.
|
495
|
+
super.invalidate()
|
459
496
|
}
|
460
497
|
|
461
498
|
fun registerRootHelper(root: RNGestureHandlerRootHelper) {
|
@@ -611,7 +648,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) :
|
|
611
648
|
}
|
612
649
|
|
613
650
|
companion object {
|
614
|
-
const val
|
651
|
+
const val NAME = "RNGestureHandlerModule"
|
615
652
|
private const val KEY_SHOULD_CANCEL_WHEN_OUTSIDE = "shouldCancelWhenOutside"
|
616
653
|
private const val KEY_ENABLED = "enabled"
|
617
654
|
private const val KEY_NEEDS_POINTER_DATA = "needsPointerData"
|