react-native-pager-view
react-native-pager-view copied to clipboard
UseRef in android does not setPage if route changes (works in IOS)
Im using expo router v.3. I’m accessing the ref via my global state manager in another component (screen header). Everything works in IOS as expected, but in android if i replace the route, the ref becomes null immediately and the page stays on the current page.
const showDialog = () => {
Alert.alert(
'Hey Ayo!',
'Are you sure you want to go back to home. You will loose all current progress.',
[
{
text: 'Cancel',
onPress: () => console.log('Cancel Pressed'),
style: 'cancel'
},
{
text: 'Go Home',
onPress: () => {
setCurrentMomentState({
selectedDate: 'none',
selectedMomentType: 'none'
});
(pagerViewRef.current as any).setPage(0);
router.replace('/(protected)/(tabs)/home');
}
}
]
);
Using a set-time around the set page call on android is a hacky solution.
I have the same issue
I have the same issue
For now the only workaround is using a setTimeout.
Hey, please provide a reproduction repository.
Or instead of using ref, please try using new usePagerView hook.