-
-
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
- (facebook::react::RNGestureHandlerDetectorEventEmitter::OnGestureHandlerEvent)getNativeEvent; | ||
|
||
- (facebook::react::RNGestureHandlerDetectorEventEmitter::OnGestureHandlerLogicEvent)getNativeLogicEvent: | ||
(NSNumber *)childTag; | ||
@end | ||
|
||
@interface RNGestureHandlerStateChange (NativeEvent) | ||
|
||
- (facebook::react::RNGestureHandlerDetectorEventEmitter::OnGestureHandlerStateChange)getNativeEvent; | ||
|
||
- (facebook::react::RNGestureHandlerDetectorEventEmitter::OnGestureHandlerLogicStateChange)getNativeLogicEvent: | ||
(NSNumber *)childTag; |
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.
Then, you wouldn't need getNativeLogicEvent
here
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 pretty sure that this and below comment were supposed to be in reverse order
packages/react-native-gesture-handler/apple/RNGestureHandlerManager.mm
Outdated
Show resolved
Hide resolved
@@ -105,4 +105,68 @@ export function deepEqual(obj1: any, obj2: any) { | |||
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.
const attachedNativeHandlerTags = | ||
logicChildren.current.get(key)?.attachedNativeHandlerTags; | ||
if (attachedHandlerTags && attachedNativeHandlerTags) { | ||
detachHandlers( |
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.
Why detach when shouldKeepLogicChild
is true?
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.
Overhauled detaching in 593c44f
packages/react-native-gesture-handler/src/v3/LogicDetector.web.tsx
Outdated
Show resolved
Hide resolved
94984b2
to
4e718b3
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.
Good job! I think some type changes might conflict with #3700, but it shouldn't be a big deal 😅
@@ -31,9 +31,13 @@ open class GestureHandler { | |||
var tag = 0 | |||
var view: View? = null | |||
private set | |||
|
|||
// parent view is used for logicDetector |
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.
// parent view is used for logicDetector | |
// Parent view is used for Logic Detector. |
Could also be lowercase, but I think camelCase in that case seems off.
export function useDetectorContext() { | ||
const ctx = useContext(DetectorContext); | ||
if (!ctx) { | ||
throw new Error('Logic detector must be under a Native Detector'); | ||
} | ||
return ctx; | ||
} | ||
|
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.
Can we have this in separate file?
@@ -187,3 +187,31 @@ export function hash(str: string) { | |||
} | |||
return h >>> 0; | |||
} | |||
|
|||
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 don't like this name, we already have this in web implementation and it is quite confusing. I think it would be better to rename it right now while we remember what it does. Also a comment with explanation would be great.
@@ -48,3 +76,23 @@ export type CallbackHandlers = Omit< | |||
export type AnimatedEvent = ((...args: any[]) => void) & { | |||
_argMapping: (Animated.Mapping | null)[]; | |||
}; | |||
|
|||
export interface LogicChildrenProps { |
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 about this Props
suffix, but that's not strong opinion.
this.delegate.init(viewRef, this); | ||
} | ||
|
||
public detach() { | ||
if (this.state === State.ACTIVE) { | ||
this.cancel(); | ||
this.cancelTouches(); |
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.
Why?
[self attachHandlers:child.handlerTags | ||
actionType:RNGestureHandlerActionTypeLogicDetector | ||
viewTag:child.viewTag | ||
attachedHandlers:logicChildren[child.viewTag]]; | ||
} |
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's no overlap between newProps.handlerTags
and newProps.logicChildren
, right?
logicChildren?: Set<LogicChildrenProps>; | ||
} | ||
|
||
export interface LogicChildrenProps { |
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 the idea of having 2 types named the same. Though it is not a strong opinion, I'd add something, for example Web
suffix.
And same as in types.ts
, I'm not fond of adding Props
suffix in this case.
const logicChildrenToDelete: Set<number> = new Set(); | ||
|
||
for (const key of logicChildren.current.keys()) { | ||
logicChildrenToDelete.add(key); | ||
} |
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.
Can't we just do
const logicChildrenToDelete: Set<number> = new Set(); | |
for (const key of logicChildren.current.keys()) { | |
logicChildrenToDelete.add(key); | |
} | |
const logicChildrenToDelete: Set<number> = new Set(logicChildren.current.keys()); |
?
}); | ||
|
||
logicChildrenToDelete.forEach((childTag) => { | ||
if (attachedHandlerTags && attachedNativeHandlerTags) { |
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 get this condition. As far as I remember attachedNativeHandlerTags
was used for Native
gestures, so why do we want only them to be detached?
logicChildren.current.get(childTag)!, | ||
logicChildren.current.get(childTag)! |
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 get the idea, but it seems quite confusing why they're the same, could we add a little comment?
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