Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 17 additions & 33 deletions src/components/ReanimatedSwipeable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -256,20 +256,9 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
const leftWidth = useSharedValue<number>(0);
const rightWidth = useSharedValue<number>(0);

// used for synchronizing layout measurements between JS and UI
const rightOffset = useSharedValue<number | null>(null);

const showLeftProgress = useSharedValue<number>(0);
const showRightProgress = useSharedValue<number>(0);

const updateRightElementWidth = useCallback(() => {
'worklet';
if (rightOffset.value === null) {
rightOffset.value = rowWidth.value;
}
rightWidth.value = Math.max(0, rowWidth.value - rightOffset.value);
}, [rightOffset, rightWidth, rowWidth]);

const updateAnimatedEvent = useCallback(() => {
'worklet';

Expand Down Expand Up @@ -451,8 +440,7 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
},
openRight() {
'worklet';
// rightOffset and rowWidth are already much sooner than rightWidth
animateRow((rightOffset.value ?? 0) - rowWidth.value);
animateRow(-rightWidth.value);
},
reset() {
'worklet';
Expand All @@ -463,14 +451,13 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
},
}),
[
animateRow,
leftWidth,
rightOffset,
rowWidth,
rightWidth,
userDrag,
showLeftProgress,
appliedTranslation,
rowState,
animateRow,
]
);

Expand Down Expand Up @@ -508,22 +495,23 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
const rightElement = useCallback(
() => (
<Animated.View style={[styles.rightActions]}>
{renderRightActions?.(
showRightProgress,
appliedTranslation,
swipeableMethods
)}
<View
onLayout={({ nativeEvent }) => {
rightOffset.value = nativeEvent.layout.x;
}}
/>
style={styles.rightActionsContainer}
onLayout={({ nativeEvent }) =>
(rightWidth.value = nativeEvent.layout.width)
}>
{renderRightActions?.(
showRightProgress,
appliedTranslation,
swipeableMethods
)}
</View>
</Animated.View>
),
[
appliedTranslation,
renderRightActions,
rightOffset,
rightWidth,
showRightProgress,
swipeableMethods,
]
Expand All @@ -535,8 +523,6 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
const { velocityX } = event;
userDrag.value = event.translationX;

updateRightElementWidth();

const leftThresholdProp = leftThreshold ?? leftWidth.value / 2;
const rightThresholdProp = rightThreshold ?? rightWidth.value / 2;

Expand Down Expand Up @@ -574,7 +560,6 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
rightWidth,
rowState,
userDrag,
updateRightElementWidth,
]
);

Expand Down Expand Up @@ -603,9 +588,6 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
.enabled(enabled !== false)
.enableTrackpadTwoFingerGesture(enableTrackpadTwoFingerGesture)
.activeOffsetX([-dragOffsetFromRightEdge, dragOffsetFromLeftEdge])
.onStart(() => {
updateRightElementWidth();
})
.onUpdate(
(event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => {
userDrag.value = event.translationX;
Expand Down Expand Up @@ -650,7 +632,6 @@ const Swipeable = forwardRef<SwipeableMethods, SwipeableProps>(
onSwipeableOpenStartDrag,
rowState,
updateAnimatedEvent,
updateRightElementWidth,
userDrag,
]
);
Expand Down Expand Up @@ -705,4 +686,7 @@ const styles = StyleSheet.create({
...StyleSheet.absoluteFillObject,
flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',
},
rightActionsContainer: {
flexDirection: I18nManager.isRTL ? 'row' : 'row-reverse',
},
});
Loading