$ git show liquid-swipe
Liquid swipe
Onboarding where the next page pours in from the edge as a bulging liquid shape.
Inspired by Liquid SwipeFrom William Candillon’s “Can it be done in React Native?” series. The code here is a simplified rewrite for Reanimated 4 and 3.
import { scheduleOnRN } from 'react-native-worklets';
const AnimatedPath = Animated.createAnimatedComponent(Path);
const x = useSharedValue(0), y = useSharedValue(height / 2);
const pan = Gesture.Pan()
.onUpdate(e => { x.value = Math.max(0, -e.translationX); y.value = e.absoluteY; })
.onEnd(e => {
const done = x.value > width / 3 || e.velocityX < -500;
x.value = withSpring(done ? width * 1.6 : 0, {}, fin => { if (fin && done) scheduleOnRN(next); });
});
const props = useAnimatedProps(() => {
const edge = Math.max(0, width - x.value * 0.5); // how far the flat edge moved
const bulge = Math.min(x.value * 0.6, 160); // how far the bump sticks out
const r = 40 + x.value * 0.5; // bump height
const top = y.value - r, bottom = y.value + r;
return {
d: 'M ' + width + ' 0 L ' + edge + ' 0 L ' + edge + ' ' + top +
' C ' + edge + ' ' + (y.value - r / 2) + ' ' + (edge - bulge) + ' ' + (y.value - r / 2) + ' ' + (edge - bulge) + ' ' + y.value +
' C ' + (edge - bulge) + ' ' + (y.value + r / 2) + ' ' + edge + ' ' + (y.value + r / 2) + ' ' + edge + ' ' + bottom +
' L ' + edge + ' ' + height + ' L ' + width + ' ' + height + ' Z',
};
});
// <Svg style={StyleSheet.absoluteFill}><AnimatedPath fill={nextColor} animatedProps={props} /></Svg>