-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Typed gesture hooks #3706
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
Merged
Merged
Typed gesture hooks #3706
Changes from 106 commits
Commits
Show all changes
113 commits
Select commit
Hold shift + click to select a range
daa017c
Separate Reanimated from JS in NativeDetector
m-bert 1e17cf8
Separate Reanimated on Android
m-bert 08d1e2b
Separate Reanimated on iOS
m-bert 256f707
Reorganize structure
m-bert 19fd985
Create ceparate hooks for Reanimated
m-bert 133319b
Add checks in useGesture
m-bert e50f6cc
use isAnimatedEvent
m-bert b3ef022
Extract handlers in separate function
m-bert 952fbe1
Pass correct touch event callback
m-bert ec9eaa7
Merge branch 'next' into @mbert/extract-reanimated-handlers
m-bert 60a56e6
Merge branch 'next' into @mbert/extract-reanimated-handlers
m-bert fda23cc
Fix crash when onUpdate is Animated.Event
m-bert e46554b
Unify lateinit
m-bert 13f3af4
Rename EventTarget on Android
m-bert d7a2b1a
Rename EventTarget on iOS
m-bert 1b04d3c
Add reset for animated and reanimated events flags
m-bert b8df015
Rename getter for event handlers
m-bert 93343da
Correctly handle disableReanimated
m-bert d1d3efb
Unpack nativeEvent
m-bert 03a1e64
Bring back hooks
m-bert cc1313a
Use old name
m-bert dac39cf
Disable coalescing on Android
m-bert 51b5a86
Implement DFS for gesture relations
m-bert 92b4a3a
Implement module method for updating relations
m-bert e73ee57
Add blocksHandlers array
m-bert 432aee0
Handle Simultaneous as root
m-bert b09d746
Change name to enum
m-bert db5d261
Move DFS to other file
m-bert 43212af
Do not traverse single gestures
m-bert 4ec26c0
Handle external relations
m-bert fa599af
Use operation block
m-bert 42fc8c2
Move flushOperations into JS
m-bert f62a6df
Add exports for type
m-bert 504feae
Add composed handler
m-bert 122613f
Merge branch 'next' into @mbert/extract-reanimated-handlers
m-bert 246f096
Merge branch '@mbert/extract-reanimated-handlers' into @mbert/relatio…
m-bert e229d84
Rename dfs
m-bert fac31e2
Split utils
m-bert 53ce245
Merge branch 'next' into @mbert/extract-reanimated-handlers
m-bert fb88c8c
Change hook eslint rule to warning
m-bert 8e5f07e
Extract choosing handler type into function
m-bert feaa167
Rename event handlers
m-bert 3f2ea8c
Improve error message
m-bert 4022b96
Move for loop inside function
m-bert 8d9fc49
Merge branch '@mbert/extract-reanimated-handlers' into @mbert/relatio…
m-bert 2dc44b8
Do not drop relataions on config change
m-bert fab60e5
Rename method
m-bert 31c0e8b
Merge branch '@mbert/extract-reanimated-handlers' into @mbert/relatio…
m-bert 832ffb0
Rename files to camelCase
m-bert bea99ab
Merge branch 'next' into @mbert/relations-v2
m-bert fb8c8e3
Rename files to camelCase
m-bert 192556e
Remove todo
m-bert 7c7876b
Make simultaneousWithExternalGesture symmetric
m-bert 3e2b661
Fix crash with animated
m-bert 8cd19ff
Add todo
m-bert 74ec173
Type config
m-bert 5c560e8
Split types and handler data
m-bert 619aed9
Use enums
m-bert b12824b
Use named type
m-bert 4ad7f5b
Extract dfs call to utils
m-bert a6f1ecb
Pass composed type as argument
m-bert 761e22a
Move function to global scope
m-bert 648f862
Update comment
m-bert ce2de67
Assign instead of only push
m-bert ec85bb5
Add warning about the same gesture passed multiple times
m-bert d6abf0d
Merge branch '@mbert/relations-v2' into @mbert/properly-type-config
m-bert 2e99481
Do not store set in variable
m-bert adfada7
Change warning to error
m-bert 7ab9b3b
Use warn about multiple animated events
m-bert c2c88cc
Do not add repeating tags with external relations into simultaneous h…
m-bert 4baf2cb
Do not mark gesture as simultaneous with itself
m-bert db2e974
Handle external simultaneous composition
m-bert 6fe39a5
Remove todo
m-bert 1429ecd
Update types
m-bert 81677c7
Change dfs name
m-bert 759d022
Prepare external relations in useGesture
m-bert 7c001fe
Rename types
m-bert c3d63cc
Mark otherHandlers as possibly undefined
m-bert 3aa7e96
Merge branch '@mbert/relations-v2' into @mbert/properly-type-config
m-bert d20025b
Add default parameters to Gesture type
m-bert 100e1aa
useTap
m-bert 944cada
Make NativeDetector generic
m-bert b3e37e7
Merge branch 'next' into @mbert/properly-type-config
m-bert df1a0f5
Merge branch '@mbert/properly-type-config' into @mbert/gesture-hooks
m-bert a9392eb
useFling
m-bert 72118e7
useLongPress
m-bert 0688821
Small tap improvements
m-bert d3a7c32
usePinch
m-bert bc3f1e5
useRotation
m-bert 3d3198c
Change interface to type
m-bert 2d746d3
useHover
m-bert ed4af90
useManual
m-bert 7871cc6
useNative
m-bert 28455b3
usePan
m-bert c21c055
Rename types
m-bert 0bf03e1
Add common props to HandlerData
m-bert 37f392e
Long press default behavior
m-bert d3ad70f
Pan props validation
m-bert d69d9c4
Merge branch 'next' into @mbert/properly-type-config
m-bert 14a72f1
Merge branch '@mbert/properly-type-config' into @mbert/gesture-hooks
m-bert e609fe4
Merge branch 'next' into @mbert/gesture-hooks
m-bert 60b4655
Merge branch 'next' into @mbert/gesture-hooks
m-bert d2ff3a4
Remove unnecexxary export keywords
m-bert c10d2e2
Add ts-ignore explanations in NativeDetector
m-bert e2ab449
Switch order in type name
m-bert d77bd44
Update types
m-bert 4b406a8
Fix NativeViewGestureHandler name
m-bert 68dd1e6
Fix types
m-bert 7f33ffc
Merge branch 'next' into @mbert/gesture-hooks
m-bert 78a8f1a
Change type name to only T
m-bert 5d0ef4d
Add cloneConfig to other gestures
m-bert dc472e1
Rename Props to Properties
m-bert b496adf
Merge branch 'next' into @mbert/gesture-hooks
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
26 changes: 26 additions & 0 deletions
26
packages/react-native-gesture-handler/src/v3/hooks/gestures/index.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,26 @@ | ||
export type { TapGestureConfig } from './useTap'; | ||
export { useTap } from './useTap'; | ||
|
||
export type { FlingGestureConfig } from './useFling'; | ||
export { useFling } from './useFling'; | ||
|
||
export type { LongPressGestureConfig } from './useLongPress'; | ||
export { useLongPress } from './useLongPress'; | ||
|
||
export type { PinchGestureConfig } from './usePinch'; | ||
export { usePinch } from './usePinch'; | ||
|
||
export type { RotationGestureConfig } from './useRotation'; | ||
export { useRotation } from './useRotation'; | ||
|
||
export type { HoverGestureConfig } from './useHover'; | ||
export { useHover } from './useHover'; | ||
|
||
export type { ManualGestureConfig } from './useManual'; | ||
export { useManual } from './useManual'; | ||
|
||
export type { NativeViewGestureConfig } from './useNative'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can change to |
||
export { useNative } from './useNative'; | ||
|
||
export type { PanGestureConfig } from './usePan'; | ||
export { usePan } from './usePan'; |
51 changes: 51 additions & 0 deletions
51
packages/react-native-gesture-handler/src/v3/hooks/gestures/useFling.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,51 @@ | ||
import { | ||
BaseGestureConfig, | ||
ExcludeInternalConfigProps, | ||
SingleGestureName, | ||
} from '../../types'; | ||
import { useGesture } from '../useGesture'; | ||
import { cloneConfig } from '../utils'; | ||
|
||
type FlingGestureProps = { | ||
j-piasecki marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
/** | ||
* Expressed allowed direction of movement. It's possible to pass one or many | ||
* directions in one parameter: | ||
* | ||
* ```js | ||
* direction={Directions.RIGHT | Directions.LEFT} | ||
* ``` | ||
* | ||
* or | ||
* | ||
* ```js | ||
* direction={Directions.DOWN} | ||
* ``` | ||
*/ | ||
direction?: number; | ||
|
||
/** | ||
* Determine exact number of points required to handle the fling gesture. | ||
*/ | ||
numberOfPointers?: number; | ||
}; | ||
|
||
type FlingHandlerData = { | ||
x: number; | ||
y: number; | ||
absoluteX: number; | ||
absoluteY: number; | ||
}; | ||
|
||
type FlingGestureInternalConfig = BaseGestureConfig< | ||
FlingHandlerData, | ||
FlingGestureProps | ||
>; | ||
|
||
export type FlingGestureConfig = | ||
ExcludeInternalConfigProps<FlingGestureInternalConfig>; | ||
|
||
export function useFling(config: FlingGestureConfig) { | ||
const flingConfig = cloneConfig<FlingHandlerData, FlingGestureProps>(config); | ||
|
||
return useGesture(SingleGestureName.Fling, flingConfig); | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/react-native-gesture-handler/src/v3/hooks/gestures/useHover.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,44 @@ | ||
import { StylusData } from '../../../handlers/gestureHandlerCommon'; | ||
import { HoverEffect } from '../../../handlers/gestures/hoverGesture'; | ||
import { | ||
BaseGestureConfig, | ||
ExcludeInternalConfigProps, | ||
SingleGestureName, | ||
} from '../../types'; | ||
import { useGesture } from '../useGesture'; | ||
import { cloneConfig } from '../utils'; | ||
|
||
type HoverGestureProps = { | ||
/** | ||
* Visual effect applied to the view while the view is hovered. The possible values are: | ||
* | ||
* - `HoverEffect.None` | ||
* - `HoverEffect.Lift` | ||
* - `HoverEffect.Highlight` | ||
* | ||
* Defaults to `HoverEffect.None` | ||
*/ | ||
hoverEffect?: HoverEffect; | ||
}; | ||
|
||
type HoverHandlerData = { | ||
x: number; | ||
y: number; | ||
absoluteX: number; | ||
absoluteY: number; | ||
stylusData: StylusData; | ||
}; | ||
|
||
type HoverGestureInternalConfig = BaseGestureConfig< | ||
HoverHandlerData, | ||
HoverGestureProps | ||
>; | ||
|
||
export type HoverGestureConfig = | ||
ExcludeInternalConfigProps<HoverGestureInternalConfig>; | ||
|
||
export function useHover(config: HoverGestureConfig) { | ||
const hoverConfig = cloneConfig<HoverHandlerData, HoverGestureProps>(config); | ||
|
||
return useGesture(SingleGestureName.Hover, hoverConfig); | ||
} |
75 changes: 75 additions & 0 deletions
75
packages/react-native-gesture-handler/src/v3/hooks/gestures/useLongPress.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,75 @@ | ||
import { | ||
BaseGestureConfig, | ||
ExcludeInternalConfigProps, | ||
SingleGestureName, | ||
} from '../../types'; | ||
import { useGesture } from '../useGesture'; | ||
import { remapProps } from '../utils'; | ||
|
||
type LongPressGestureProps = { | ||
/** | ||
* Minimum time, expressed in milliseconds, that a finger must remain pressed on | ||
* the corresponding view. The default value is 500. | ||
*/ | ||
minDuration?: number; | ||
|
||
/** | ||
* Maximum distance, expressed in points, that defines how far the finger is | ||
* allowed to travel during a long press gesture. If the finger travels | ||
* further than the defined distance and the handler hasn't yet activated, it | ||
* will fail to recognize the gesture. The default value is 10. | ||
*/ | ||
maxDistance?: number; | ||
|
||
/** | ||
* Determine exact number of points required to handle the long press gesture. | ||
*/ | ||
numberOfPointers?: number; | ||
}; | ||
|
||
type LongPressGestureInternalProps = { | ||
minDurationMs?: number; | ||
maxDist?: number; | ||
numberOfPointers?: number; | ||
}; | ||
|
||
type LongPressHandlerData = { | ||
x: number; | ||
y: number; | ||
absoluteX: number; | ||
absoluteY: number; | ||
duration: number; | ||
}; | ||
|
||
export type LongPressGestureConfig = ExcludeInternalConfigProps< | ||
BaseGestureConfig<LongPressHandlerData, LongPressGestureProps> | ||
>; | ||
|
||
type LongPressGestureInternalConfig = BaseGestureConfig< | ||
LongPressHandlerData, | ||
LongPressGestureInternalProps | ||
>; | ||
|
||
const LongPressPropsMapping = new Map< | ||
keyof LongPressGestureProps, | ||
keyof LongPressGestureInternalProps | ||
>([ | ||
['minDuration', 'minDurationMs'], | ||
['maxDistance', 'maxDist'], | ||
]); | ||
|
||
export function useLongPress(config: LongPressGestureConfig) { | ||
const longPressConfig = remapProps< | ||
LongPressGestureConfig, | ||
LongPressGestureInternalConfig | ||
>(config, LongPressPropsMapping); | ||
|
||
if (longPressConfig.shouldCancelWhenOutside === undefined) { | ||
longPressConfig.shouldCancelWhenOutside = true; | ||
} | ||
|
||
return useGesture<LongPressHandlerData, LongPressGestureInternalProps>( | ||
SingleGestureName.LongPress, | ||
longPressConfig | ||
); | ||
} |
26 changes: 26 additions & 0 deletions
26
packages/react-native-gesture-handler/src/v3/hooks/gestures/useManual.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,26 @@ | ||
import { | ||
BaseGestureConfig, | ||
ExcludeInternalConfigProps, | ||
SingleGestureName, | ||
} from '../../types'; | ||
import { useGesture } from '../useGesture'; | ||
import { cloneConfig } from '../utils'; | ||
|
||
type ManualGestureProps = Record<string, never>; | ||
type ManualHandlerData = Record<string, never>; | ||
|
||
type ManualGestureInternalConfig = BaseGestureConfig< | ||
ManualHandlerData, | ||
ManualGestureProps | ||
>; | ||
|
||
export type ManualGestureConfig = | ||
ExcludeInternalConfigProps<ManualGestureInternalConfig>; | ||
|
||
export function useManual(config: ManualGestureConfig) { | ||
const manualConfig = cloneConfig<ManualHandlerData, ManualGestureProps>( | ||
config | ||
); | ||
|
||
return useGesture(SingleGestureName.Manual, manualConfig); | ||
} |
44 changes: 44 additions & 0 deletions
44
packages/react-native-gesture-handler/src/v3/hooks/gestures/useNative.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,44 @@ | ||
import { | ||
BaseGestureConfig, | ||
ExcludeInternalConfigProps, | ||
SingleGestureName, | ||
} from '../../types'; | ||
import { useGesture } from '../useGesture'; | ||
import { cloneConfig } from '../utils'; | ||
|
||
type NativeViewGestureProps = { | ||
/** | ||
* Android only. | ||
* | ||
* Determines whether the handler should check for an existing touch event on | ||
* instantiation. | ||
*/ | ||
shouldActivateOnStart?: boolean; | ||
|
||
/** | ||
* When `true`, cancels all other gesture handlers when this | ||
* `NativeViewGestureHandler` receives an `ACTIVE` state event. | ||
*/ | ||
disallowInterruption?: boolean; | ||
}; | ||
|
||
type NativeViewHandlerData = { | ||
pointerInside: boolean; | ||
}; | ||
|
||
type NativeViewGestureInternalConfig = BaseGestureConfig< | ||
NativeViewHandlerData, | ||
NativeViewGestureProps | ||
>; | ||
|
||
export type NativeViewGestureConfig = | ||
ExcludeInternalConfigProps<NativeViewGestureInternalConfig>; | ||
|
||
export function useNative(config: NativeViewGestureConfig) { | ||
const nativeConfig = cloneConfig< | ||
NativeViewHandlerData, | ||
NativeViewGestureProps | ||
>(config); | ||
|
||
return useGesture(SingleGestureName.Native, nativeConfig); | ||
} |
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.