-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Logic Detector #3689
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?
Logic Detector #3689
Conversation
5b65a19
to
81bf405
Compare
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.
Did a fist pass, but some stuff will likely change due to #3682 :/
Anyway, you have the hardest part figured out, now it's just a matter of polishing it up.
...ler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt
Outdated
Show resolved
Hide resolved
...roid/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorViewManager.kt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/src/specs/RNGestureHandlerDetectorNativeComponent.ts
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/apple/RNGestureHandlerNativeEventUtils.h
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm
Outdated
Show resolved
Hide resolved
return true; | ||
} | ||
|
||
export function invokeNullableMethod( |
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.
I'm not sure this is the way to go. Once #3682 is merged, you should be able to cleanly handle all cases in hooks it adds.
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.
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.
Are reanimated events still triggered on the UI thread this way?
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.
It were not triggered on the ui thread. It is finally solved in https://github.com/software-mansion/react-native-gesture-handler/pull/3689/commits. Thank you for your help in office.
packages/react-native-gesture-handler/src/v3/HostGestureDetector.web.tsx
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/src/v3/LogicDetector.web.tsx
Outdated
Show resolved
Hide resolved
94984b2
to
4e718b3
Compare
...ve-gesture-handler/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/src/v3/NativeDetector/NativeDetector.tsx
Outdated
Show resolved
Hide resolved
const method = !logicMethods.current.has(e.nativeEvent.handlerTag) | ||
? gesture.gestureEvents.onGestureHandlerStateChange | ||
: logicMethods.current.get(e.nativeEvent.handlerTag)?.current | ||
?.onGestureHandlerStateChange; |
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.
Any chance to extract this to a method? It repeats for every event.
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.
Okay, e6fbdba
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 can go deeper - you can change the new function to return a function which will handle the event and assign that directly to the event handler, i.e.:
onGestureHandlerStateChange={createGestureEventHandler('onGestureHandlerStateChange', e);}
instead of
onGestureHandlerStateChange={(e) => {
handleGestureEvent('onGestureHandlerStateChange', e);
}}
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.
That is a really good idea, thanks. Done in 832a039
packages/react-native-gesture-handler/src/v3/useDetectorContext.ts
Outdated
Show resolved
Hide resolved
...ler/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerDetectorView.kt
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm
Outdated
Show resolved
Hide resolved
packages/react-native-gesture-handler/apple/RNGestureHandlerDetector.mm
Outdated
Show resolved
Hide resolved
override fun getCoalescingKey() = coalescingKey | ||
|
||
override fun getEventData(): WritableMap = if (actionType == GestureHandler.ACTION_TYPE_NATIVE_DETECTOR) { | ||
override fun getEventData(): WritableMap = if (GestureHandler.usesNativeOrLogicDetector(actionType)) { |
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.
I know this is not exact place, but shouldn't we also update canCoalesce
above?
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.
Also I'm not sure about TouchEvents
, since they have touchesMove
callback (cc @j-piasecki)
case RNGestureHandlerActionTypeLogicDetector: { | ||
NSNumber *hostDetectorTag = [_registry handlerWithTag:event.handlerTag].hostDetectorTag; | ||
detectorView = [self viewForReactTag:hostDetectorTag]; | ||
// intentionally fall through to RNGestureHandlerActionTypeNativeDetector |
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.
I'm not sure if I like this approach, could we extract it to a function and then call it in both?
attachedNativeHandlers.current | ||
); | ||
attachedNativeHandlers.current.clear(); | ||
detachHandlers(newHandlerTags, attachedNativeHandlers.current); |
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.
At this point, isn't attachedNativeHandlers
empty? If so, maybe add a comment that it is intentionally empty?
useEffect(() => { | ||
return () => { | ||
detachHandlers(attachedHandlerTags.current); | ||
detachHandlers(new Set(), attachedHandlers.current); |
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.
Maybe it won't change much in the optimization, but we can create EMPTY_SET
variable and then pass it to avoid calling these constructors.
if (node) { | ||
if (Platform.OS === 'web') { | ||
setViewTag(node); | ||
} else { | ||
const tag = findNodeHandle(node); | ||
if (tag != null) { | ||
setViewTag(tag); | ||
} | ||
} | ||
} |
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.
if(!node) {
return;
}
: [props.gesture.tag], | ||
}; | ||
|
||
register(logicProps, logicMethods as RefObject<GestureEvents<unknown>>); |
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.
Is this cast necessary?
I'll be on vacation and I don't want to block this PR - I believe it will be good to go when @j-piasecki approves it :D
Description
This PR implements new component ->
LogicDetector
. It resolves the issue of attaching gestures to inner SVG components.LogicDetector
communicates with aNativeDetector
higher in the hierarchy, which will be responsible for attaching gestures.Test plan
tested on the following code