Skip to content
Source
Sign inSign up
pingdotgg/t3code

fix(mobile): dragging routes to reorder no longer snaps back #22435

ClosedRVZO6(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/22435/headopened View on GitHub

Showing 1 changed file with 9 additions and 13 deletions.

x
0 of 1 viewed, 1 left
9 additions and 13 deletionsapps/mobile/src/features/settings/components/SettingsDragHandle.tsxModified
View file
@@ -20,22 +20,18 @@
const onEnd = useEffectEvent((translation: number, cancelled: boolean) =>
props.onEnd(translation, cancelled),
);
- const [gesture] = useState(() => {
- let translation = 0;
- return Gesture.Pan()
+ // Gesture callbacks become worklets that each copy their closure, so state
+ // shared between them through a local variable never updates; the final
+ // event carries the translation instead.
+ const [gesture] = useState(() =>
+ Gesture.Pan()
.minDistance(0)
.shouldCancelWhenOutside(false)
.runOnJS(true)
- .onStart(() => {
- translation = 0;
- onStart();
- })
- .onUpdate((event) => {
- translation = event.translationY;
- onMove(event.translationY);
- })
- .onFinalize((_, success) => onEnd(translation, !success));
- });
+ .onStart(() => onStart())
+ .onUpdate((event) => onMove(event.translationY))
+ .onFinalize((event, success) => onEnd(event.translationY, !success)),
+ );
return (