-
-
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 6 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
70 changes: 70 additions & 0 deletions
70
packages/react-native-gesture-handler/src/v3/hooks/relations/useComposedGesture.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,70 @@ | ||
import { | ||
NativeGesture, | ||
StateChangeEvent, | ||
UpdateEvent, | ||
TouchEvent, | ||
} from '../../types'; | ||
|
||
export function useComposedGesture(...gestures: NativeGesture[]) { | ||
Check failure on line 8 in packages/react-native-gesture-handler/src/v3/hooks/relations/useComposedGesture.ts
|
||
const tags = gestures.flatMap((gesture) => gesture.tag); | ||
|
||
const config = { | ||
shouldUseReanimated: gestures.some( | ||
(gesture) => gesture.config.shouldUseReanimated | ||
), | ||
dispatchesAnimatedEvents: gestures.some( | ||
(gesture) => gesture.config.dispatchesAnimatedEvents | ||
), | ||
}; | ||
|
||
const onGestureHandlerStateChange = ( | ||
event: StateChangeEvent<Record<string, unknown>> | ||
) => { | ||
for (const gesture of gestures) { | ||
if (gesture.gestureEvents.onGestureHandlerStateChange) { | ||
gesture.gestureEvents.onGestureHandlerStateChange(event); | ||
} | ||
} | ||
}; | ||
|
||
const onGestureHandlerEvent = ( | ||
event: UpdateEvent<Record<string, unknown>> | ||
) => { | ||
for (const gesture of gestures) { | ||
if (gesture.gestureEvents.onGestureHandlerEvent) { | ||
gesture.gestureEvents.onGestureHandlerEvent(event); | ||
} | ||
} | ||
}; | ||
|
||
const onGestureHandlerTouchEvent = (event: TouchEvent) => { | ||
for (const gesture of gestures) { | ||
if (gesture.gestureEvents.onGestureHandlerTouchEvent) { | ||
gesture.gestureEvents.onGestureHandlerTouchEvent(event); | ||
} | ||
} | ||
}; | ||
|
||
let onGestureHandlerAnimatedEvent; | ||
|
||
for (const gesture of gestures) { | ||
if (gesture.gestureEvents.onGestureHandlerAnimatedEvent) { | ||
onGestureHandlerAnimatedEvent = | ||
gesture.gestureEvents.onGestureHandlerAnimatedEvent; | ||
|
||
break; | ||
} | ||
} | ||
|
||
return { | ||
tag: tags, | ||
name: 'ComposedGesture', | ||
config, | ||
gestureEvents: { | ||
onGestureHandlerStateChange, | ||
onGestureHandlerEvent, | ||
onGestureHandlerAnimatedEvent, | ||
onGestureHandlerTouchEvent, | ||
}, | ||
}; | ||
} |
16 changes: 16 additions & 0 deletions
16
packages/react-native-gesture-handler/src/v3/hooks/relations/useExclusive.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,16 @@ | ||
import { NativeGesture } from '../../types'; | ||
import { useComposedGesture } from './useComposedGesture'; | ||
|
||
export function useExclusive(...gestures: NativeGesture[]) { | ||
const composedGesture = useComposedGesture(...gestures); | ||
|
||
const tags = gestures.flatMap((gesture) => gesture.tag); | ||
|
||
for (let i = 0; i < gestures.length; i++) { | ||
gestures[i].config.waitFor = tags.slice(0, i); | ||
} | ||
m-bert marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
composedGesture.name = 'ExclusiveGesture'; | ||
|
||
return composedGesture; | ||
} |
10 changes: 10 additions & 0 deletions
10
packages/react-native-gesture-handler/src/v3/hooks/relations/useRace.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,10 @@ | ||
import { NativeGesture } from '../../types'; | ||
import { useComposedGesture } from './useComposedGesture'; | ||
|
||
export function useRace(...gestures: NativeGesture[]) { | ||
const composedGesture = useComposedGesture(...gestures); | ||
|
||
composedGesture.name = 'RaceGesture'; | ||
|
||
return composedGesture; | ||
} |
20 changes: 20 additions & 0 deletions
20
packages/react-native-gesture-handler/src/v3/hooks/relations/useSimultaneous.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,20 @@ | ||
import { NativeGesture } from '../../types'; | ||
import { useComposedGesture } from './useComposedGesture'; | ||
|
||
export function useSimultaneous(...gestures: NativeGesture[]) { | ||
const composedGesture = useComposedGesture(...gestures); | ||
|
||
const tags = gestures.flatMap((gesture) => gesture.tag); | ||
|
||
for (const gesture of gestures) { | ||
const simultaneousHandlersTags = [ | ||
...tags.filter((tag) => !gesture.tag.includes(tag)), | ||
]; | ||
|
||
gesture.config.simultaneousHandlers = simultaneousHandlersTags; | ||
} | ||
|
||
composedGesture.name = 'SimultaneousGesture'; | ||
|
||
return composedGesture; | ||
} |
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
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.