Stack screens animation and Pan Responder #9711
Unanswered
Estebank94
asked this question in
Q&A
Replies: 3 comments 7 replies
-
https://reactnavigation.org/docs/stack-navigator/#gestureenabled |
Beta Was this translation helpful? Give feedback.
1 reply
-
This is what I was able to do until now: RPReplay_Final1625239794.movThere are two main problems here:
This is the code: const HomeFeed = createStackNavigator();
const HomeFeedStack = (props: any) => {
const translateY = useRef(new Animated.Value(0)).current;
const handlePan = (evt) => {
const { nativeEvent } = evt;
console.log(nativeEvent);
translateY.setValue(Math.abs(nativeEvent.translationY));
if (Math.abs(nativeEvent.translationY) > 10) {
props.navigation.navigate(HOME_FEED_DETAILS);
}
};
const handlePanEnd = (event) => {
if (event.nativeEvent.state === State.END) {
if (Math.abs(event.nativeEvent.translationY) > 200) {
console.log('FINISH ANIMATIN');
Animated.timing(translateY, {
toValue: 812,
duration: 500,
useNativeDriver: true,
}).start();
} else {
console.log('GO BACK____');
Animated.timing(translateY, {
toValue: 0,
duration: 500,
useNativeDriver: true,
}).start(() => props.navigation.goBack());
}
}
};
const forSwipe = ({ layouts: { screen } }) => {
return {
containerStyle: {
borderRadius: 50,
},
cardStyle: {
transform: [
{
translateY: translateY.interpolate({
inputRange: [0, 812],
outputRange: [screen.height - 50, 0],
extrapolate: 'clamp',
}),
},
],
},
};
};
return (
<HomeFeed.Navigator mode="modal">
<HomeFeed.Screen
name={HOME_FEED}
children={() => (
<HomeFeedScreen
handlePan={handlePan}
handlePanEnd={handlePanEnd}
/>
)}
options={{ headerShown: false }}
/>
<HomeFeed.Screen
name={HOME_FEED_DETAILS}
children={() => <View style={{ flex: 1, backgroundColor: 'blue' }} />}
options={{ headerShown: false, cardStyleInterpolator: forSwipe }}
/>
</HomeFeed.Navigator>
);
}; |
Beta Was this translation helpful? Give feedback.
6 replies
-
Done. Thanks @satya164 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
Currently I am using
GestureRecognizer
fromreact-native-swipe-gestures
to detect when the user swipes up and call the navigate function.I was wondering if there is a way to animate the navigation of a stack screen as the user slides his finger across the screen. This way I could make the screen follow the user's finger vertically. I am guessing I could use Pan Responder but I didn't find any documentation about this.
Did anyone try making something like this?
Beta Was this translation helpful? Give feedback.
All reactions