-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Update how Gesture Handler exposes setGestureState
to the Reanimated UI runtime
#3207
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
4b6cb29
to
039e228
Compare
setGestureState
to the ui runtimesetGestureState
to the Reanimated UI runtime
Additionally, I'd like to rename |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice work overall, I like the removals 😎
08271fd
to
12c9f11
Compare
296b706
to
d5d7233
Compare
...e-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/android/src/main/jni/CMakeLists.txt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/android/src/main/jni/CMakeLists.txt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/android/src/main/jni/CMakeLists.txt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/android/src/main/jni/RNGestureHandlerModule.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/shared/RuntimeDecorator.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/shared/RuntimeDecorator.h
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/shared/RuntimeDecorator.h
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/shared/RuntimeDecorator.h
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/src/handlers/gestures/gestureStateManager.ts
Show resolved
Hide resolved
2e996c8
to
eeafcc9
Compare
eeafcc9
to
801acd8
Compare
scripts/format-cpp.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? We have format-apple
script, the only difference is path passed to glob
. Maybe it would be better to rename this script and pass path as argument?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unified the scripts in da123f7. Let me know what you think.
...e-handler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt
Show resolved
Hide resolved
...droid/paper/src/main/java/com/swmansion/gesturehandler/NativeRNGestureHandlerModuleSpec.java
Show resolved
Hide resolved
packages/react-native-gesture-handler/android/src/main/jni/RNGestureHandlerModule.cpp
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/src/handlers/gestures/gestureStateManager.ts
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/shared/RNGHRuntimeDecorator.cpp
Outdated
Show resolved
Hide resolved
} | ||
} | ||
|
||
private fun setGestureStateSync(handlerTag: Int, newState: Int) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using setGestureStateSync
in Kotlin, and setGestureStateSynchronously
in obj-c
.
This is a nitpick, but I think it'd make sense to stick to a single convention, unless there's a reason for this difference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed in 77ac470.
@@ -49,10 +58,16 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) : | |||
} | |||
|
|||
@ReactMethod | |||
override fun createGestureHandler(handlerName: String, handlerTagDouble: Double, config: ReadableMap) { | |||
override fun createGestureHandler(handlerName: String, handlerTagDouble: Double, config: ReadableMap): Boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The createGestureHandler
seems to only ever return true/1
.
Is this the case, or am I missing something?
If it is the case, can we get away with returning void
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a method returns any value in the codegen spec, the generated method is synchronous. I don't think there's a way to force codegen to generate a synchronous method that returns void.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (let's see what @tomekzaw thinks) 🎉
Description
Changes how
setGestureState
is exposed to the UI runtime. Instead of the weird conditionally adding Reanimated as a dependency on Android and the weird cast on iOS it uses_WORKLET_RUNTIME
const injected by Reanimated into the JS runtime. This allows Gesture Handler to decorate the UI runtime without direct dependencies between the libraries.The new approach relies on two methods being added to the global object:
_setGestureStateAsync
on the JS runtime_setGestureStateSync
on the UI runtimewhich allows for state manipulation also from the JS thread.
The basic example has been modified to easily test the new functionality.
Caution
This works only on the New Architecture (and breaks the old one)
Test plan
Test the expo example app and the modified basic example app