-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Implement gesture relations #3664
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
Draft
m-bert
wants to merge
13
commits into
@mbert/shared-values
Choose a base branch
from
@mbert/gesture-relations
base: @mbert/shared-values
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+384
−50
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f337486
Disable coalescing on Android
m-bert 43c84e5
Basic simultaneous
m-bert c0433bf
Add Exclusvie composition
m-bert 4a81c1c
useRace
m-bert 18de5ca
Add gesture names
m-bert d906df9
Merge branch '@mbert/shared-values' into @mbert/gesture-relations
m-bert ee6c581
Merge branch '@mbert/shared-values' into @mbert/gesture-relations
m-bert b973da8
Implement DFS for gesture relations
m-bert 39d976d
Implement module method for updating relations
m-bert f622d69
Add blocksHandlers array
m-bert b83c17f
Handle Simultaneous as root
m-bert 18b1269
Change name to enum
m-bert b7ca9bb
Move DFS to other file
m-bert File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 0 additions & 3 deletions
3
packages/react-native-gesture-handler/src/v3/HostGestureDetector.tsx
This file was deleted.
Oops, something went wrong.
3 changes: 3 additions & 0 deletions
3
packages/react-native-gesture-handler/src/v3/NativeDetector/HostGestureDetector.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import RNGestureHandlerDetectorNativeComponent from '../../specs/RNGestureHandlerDetectorNativeComponent'; | ||
const HostGestureDetector = RNGestureHandlerDetectorNativeComponent; | ||
export default HostGestureDetector; |
8 changes: 4 additions & 4 deletions
8
...andler/src/v3/HostGestureDetector.web.tsx → ...ativeDetector/HostGestureDetector.web.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
115 changes: 115 additions & 0 deletions
115
packages/react-native-gesture-handler/src/v3/NativeDetector/utils.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
// This piece of magic traverses the gesture tree and populates `waitFor` and `simultaneousHandlers` | ||
// arrays for each gesture. It traverses the tree recursively using DFS. | ||
// `waitFor` and `simultaneousHandlers` are global data structures that will be populated into each gesture. | ||
// For `waitFor` we need array as order of the gestures matters. | ||
// For `simultaneousHandlers` we use Set as the order doesn't matter. | ||
|
||
import RNGestureHandlerModule from '../../RNGestureHandlerModule'; | ||
import { isComposedGesture } from '../hooks/utils'; | ||
import { ComposedGesture, ComposedGestureType, NativeGesture } from '../types'; | ||
|
||
// The tree consists of ComposedGestures and NativeGestures. NativeGestures are always leaf nodes. | ||
export const dfs = ( | ||
node: NativeGesture | ComposedGesture, | ||
simultaneousHandlers: Set<number> = new Set(), | ||
waitFor: number[] = [] | ||
) => { | ||
// If we are in the leaf node, we want to fill gesture relations arrays with current | ||
// waitFor and simultaneousHandlers. We also want to configure relations on the native side. | ||
// TODO: handle `simultaneousWithExternalGesture`, `requreExternalGestureToFail`, `blocksExternalGesture` | ||
if (!isComposedGesture(node)) { | ||
node.simultaneousHandlers.push(...simultaneousHandlers); | ||
node.waitFor.push(...waitFor); | ||
|
||
RNGestureHandlerModule.configureRelations(node.tag, { | ||
waitFor, | ||
simultaneousHandlers: Array.from(simultaneousHandlers), | ||
blocksHandlers: node.blocksHandlers || [], // TODO: handle `blocksExternalGesture` | ||
}); | ||
|
||
return; | ||
} | ||
|
||
// If we are in the composed gesture, we want to traverse its children. | ||
node.gestures.forEach((child) => { | ||
// If child is composed gesture, we have to correctly fill `waitFor` and `simultaneousHandlers`. | ||
if (isComposedGesture(child)) { | ||
// We have to update `simultaneousHandlers` before traversing the child. | ||
|
||
// If we go from a non-simultaneous gesture to a simultaneous gesture, | ||
// we add the tags of the simultaneous gesture to the `simultaneousHandlers`. | ||
// This way when we traverse the child, we already have the tags of the simultaneous gestures | ||
if ( | ||
node.type !== ComposedGestureType.Simultaneous && | ||
child.type === ComposedGestureType.Simultaneous | ||
) { | ||
child.tags.forEach((tag) => simultaneousHandlers.add(tag)); | ||
} | ||
|
||
// If we go from a simultaneous gesture to a non-simultaneous gesture, | ||
// we remove the tags of the child gestures from the `simultaneousHandlers`, | ||
// as those are not simultaneous with each other. | ||
if ( | ||
node.type === ComposedGestureType.Simultaneous && | ||
child.type !== ComposedGestureType.Simultaneous | ||
) { | ||
child.tags.forEach((tag) => simultaneousHandlers.delete(tag)); | ||
} | ||
|
||
// We will keep the current length of `waitFor` to reset it to previous state | ||
// after traversing the child. | ||
const length = waitFor.length; | ||
|
||
// We traverse the child, passing the current `waitFor` and `simultaneousHandlers`. | ||
dfs(child, simultaneousHandlers, waitFor); | ||
|
||
// After traversing the child, we need to update `waitFor` and `simultaneousHandlers` | ||
|
||
// If we go back from a simultaneous gesture to a non-simultaneous gesture, | ||
// we want to delete the tags of the simultaneous gesture from the `simultaneousHandlers` - | ||
// those gestures are not simultaneous with each other anymore. | ||
if ( | ||
child.type === ComposedGestureType.Simultaneous && | ||
node.type !== ComposedGestureType.Simultaneous | ||
) { | ||
node.tags.forEach((tag) => simultaneousHandlers.delete(tag)); | ||
} | ||
|
||
// If we go back from a non-simultaneous gesture to a simultaneous gesture, | ||
// we want to add the tags of the simultaneous gesture to the `simultaneousHandlers`, | ||
// as those gestures are simultaneous with other children of the current node. | ||
if ( | ||
child.type !== ComposedGestureType.Simultaneous && | ||
node.type === ComposedGestureType.Simultaneous | ||
) { | ||
node.tags.forEach((tag) => simultaneousHandlers.add(tag)); | ||
} | ||
|
||
// If we go back to an exclusive gesture, we want to add the tags of the child gesture to the `waitFor` array. | ||
// This will allow us to pass exclusive gesture tags to the right subtree of the current node. | ||
if (node.type === ComposedGestureType.Exclusive) { | ||
child.tags.forEach((tag) => waitFor.push(tag)); | ||
} | ||
|
||
// If we go back from an exclusive gesture to a non-exclusive gesture, we want to reset the `waitFor` array | ||
// to the previous state, siblings of the exclusive gesture are not exclusive with it. Since we use `push` method to | ||
// add tags to the `waitFor` array, we can override `length` property to reset it to the previous state. | ||
if ( | ||
child.type === ComposedGestureType.Exclusive && | ||
node.type !== ComposedGestureType.Exclusive | ||
) { | ||
waitFor.length = length; | ||
} | ||
} | ||
// This means that child is a leaf node. | ||
else { | ||
// In the leaf node, we only care about filling `waitFor` array. First we traverse the child... | ||
dfs(child, simultaneousHandlers, waitFor); | ||
|
||
// ..and when we go back we add the tag of the child to the `waitFor` array. | ||
if (node.type === ComposedGestureType.Exclusive) { | ||
waitFor.push(child.tag); | ||
} | ||
} | ||
}); | ||
}; |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.