zehfernandes / react-native-3dcube-navigation

MIT License
283 stars 48 forks source link

Trigger transition onPress? #47

Open mmckinley8 opened 2 years ago

mmckinley8 commented 2 years ago

Is there a way to trigger the transition when the screen is press, similar to Instagram stories

zehfernandes commented 2 years ago

Yes! You can add onPress event and use the this.cube.scrollTo(index) function to go to next and prev views.

https://github.com/zehfernandes/react-native-3dcube-navigation/blob/badbcfb5fe880dc963a55e26d35307f2149cb210/examples/components/CubeHorizontal.js#L25

rahillakhani commented 2 years ago

If its a functional component

function xyz () { const pageNum =2, shouldAnimate = true; let cube = useRef(); . . . . function somFunction = () { . . . cube.current.scrollTo(pageNum, shouldAnimate); . . . }

return ( <CubeNavigationHorizontal key={0} ref={(view) => { cube.current = view; }}> . . . . . );
}