-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Update Swipeable types
#4175
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: main
Are you sure you want to change the base?
Update Swipeable types
#4175
Changes from all commits
143ef23
e842967
23de6d7
b613295
67cf888
33240ab
0401093
a33c735
80e8a75
46c9bc7
7818a44
9e75c0e
2d06c35
b2d4e5a
d01be7f
b7a3506
8879ea5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,10 @@ | ||
| import type { ForwardedRef } from 'react'; | ||
| import { useCallback, useImperativeHandle, useMemo } from 'react'; | ||
| import React, { | ||
| useCallback, | ||
| useEffect, | ||
| useImperativeHandle, | ||
| useMemo, | ||
| } from 'react'; | ||
| import type { LayoutChangeEvent } from 'react-native'; | ||
| import { I18nManager, StyleSheet, View } from 'react-native'; | ||
| import Animated, { | ||
|
|
@@ -14,9 +19,16 @@ import Animated, { | |
| withSpring, | ||
| } from 'react-native-reanimated'; | ||
|
|
||
| import { Reanimated } from '../../handlers/gestures/reanimatedWrapper'; | ||
| import { tagMessage } from '../../utils'; | ||
| import { GestureDetector } from '../../v3/detectors'; | ||
| import type { PanGestureActiveEvent } from '../../v3/hooks/gestures'; | ||
| import { usePanGesture, useTapGesture } from '../../v3/hooks/gestures'; | ||
| import { | ||
| maybeUnpackValue, | ||
| SHARED_VALUE_OFFSET, | ||
| } from '../../v3/hooks/utils/reanimatedUtils'; | ||
| import type { SharedValueOrT } from '../../v3/types'; | ||
| import type { | ||
| SwipeableMethods, | ||
| SwipeableProps, | ||
|
|
@@ -45,7 +57,7 @@ const Swipeable = (props: SwipeableProps) => { | |
| children, | ||
| enableTrackpadTwoFingerGesture = DEFAULT_ENABLE_TRACKING_TWO_FINGER_GESTURE, | ||
| dragOffsetFromLeft = DEFAULT_DRAG_OFFSET, | ||
| dragOffsetFromRight = DEFAULT_DRAG_OFFSET, | ||
| dragOffsetFromRight = -DEFAULT_DRAG_OFFSET, | ||
| friction = DEFAULT_FRICTION, | ||
| overshootFriction = DEFAULT_OVERSHOOT_FRICTION, | ||
| onSwipeableOpenStartDrag, | ||
|
|
@@ -63,6 +75,40 @@ const Swipeable = (props: SwipeableProps) => { | |
| ...remainingProps | ||
| } = props; | ||
|
|
||
| if (__DEV__) { | ||
| const checkValue = (value: SharedValueOrT<number>) => { | ||
| 'worklet'; | ||
| if (maybeUnpackValue<number>(value) > 0) { | ||
| throw new Error( | ||
| tagMessage('dragOffsetFromRight should be non-positive.') | ||
| ); | ||
| } | ||
| }; | ||
|
|
||
| checkValue(dragOffsetFromRight); | ||
|
|
||
| // eslint-disable-next-line react-hooks/rules-of-hooks | ||
| useEffect(() => { | ||
| if (!Reanimated?.isSharedValue<number>(dragOffsetFromRight)) { | ||
| return; | ||
| } | ||
|
|
||
| const listenerId = Math.random() + SHARED_VALUE_OFFSET; | ||
|
Member
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. Would it be possible to use a stable id instead of randomizing it?
Collaborator
Author
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. I've checked that and listeners are local for given |
||
|
|
||
| Reanimated?.runOnUI(() => { | ||
| 'worklet'; | ||
| dragOffsetFromRight.addListener(listenerId, checkValue); | ||
| })(); | ||
|
|
||
| return () => { | ||
| Reanimated?.runOnUI(() => { | ||
| 'worklet'; | ||
| dragOffsetFromRight.removeListener(listenerId); | ||
| })(); | ||
| }; | ||
| }, [dragOffsetFromRight, checkValue]); | ||
| } | ||
|
m-bert marked this conversation as resolved.
|
||
|
|
||
| const shouldEnableTap = useSharedValue<boolean>(false); | ||
| const rowState = useSharedValue<number>(0); | ||
|
|
||
|
|
@@ -468,9 +514,9 @@ const Swipeable = (props: SwipeableProps) => { | |
| }); | ||
|
|
||
| const panGesture = usePanGesture({ | ||
| enabled: enabled !== false, | ||
| enabled: enabled ?? true, | ||
| enableTrackpadTwoFingerGesture: enableTrackpadTwoFingerGesture, | ||
| activeOffsetX: [-dragOffsetFromRight, dragOffsetFromLeft], | ||
| activeOffsetX: [dragOffsetFromRight, dragOffsetFromLeft], | ||
| simultaneousWith, | ||
| requireToFail, | ||
| block, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.