You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.
After the v2 update, the passing of a position ref no longer works. This would be useful for animating other components according to the pager view position outside of the TabView hierarchy.
Expected behaviour
I expected a position ref passed as the position prop to TabView would give me the ability to use the TabView position in other components outside of the TabView hierarchy, as proposed in issue #781 and merged in PR #782.
Code sample
constAnimatedComponent=({ position })=>{constinterpolatedPosition=position.interpolate({inputRange: [...],outputRange: [...],});return(<Animated.Viewstyle={{someStyleProp: interpolatedPosition}}>{...}</Animated.View>);}constScreenComponent=()=>{constposition=useRef(newAnimated.Value(0));return(<TabViewposition={position}navigationState={{...}}/><AnimatedComponentposition={position.current}/>);}
Screenshots (if applicable)
What have you tried
I have clumsily hacked around the issue by pulling the position value from the renderTabBar function, as the position prop is passed there. This works but is less than ideal, especially if I have no need to replace the default TabBar.
constAnimatedComponent=({ position })=>{constinterpolatedPosition=position.interpolate({// NOTE: inputRange should match the number and indices of the routes from navigationStateinputRange: [...],outputRange: [...],});return(<Animated.Viewstyle={{someStyleProp: interpolatedPosition}}>{...}</Animated.View>);}constScreenComponent=()=>{constposition=useRef(newAnimated.Value(0));constrenderTabBar=(props)=>{position.current=props.position;return(<TabBar{...props}/>);};return(<TabViewrenderTabBar={renderTabBar}navigationState={{...}}/><AnimatedComponentposition={position.current}/>);}
Your Environment
software
version
ios & android
14.5 & 28
expo
40.0.0
react-native
0.63.2
react-native-tab-view
3.0.1
react-native-pager-view
5.1.10
node
14.17.0
npm
7.13.0
The text was updated successfully, but these errors were encountered:
I don't think a ref would work since it means you can't use it for the first render, and you won't get updated value until next render since changing a ref doesn't trigger re-render. Open to other ideas tho.
Maybe asking for a forward ref specifically was the wrong way to go about this, I just assumed since passing a position ref was a feature previously that something similar would still work. The goal is to be able to pass the position value to other components, however that can be accomplished. Maybe an optional onPositionChange function prop that can be passed to TabView and is called any time the position value changes? Then the user of this component can handle that change however they see fit.
Maybe an optional onPositionChange function prop that can be passed to TabView and is called any time the position value changes? Then the user of this component can handle that change however they see fit.
This is also problematic since it means whatever animation user is doing will be completely JS-based and unable to use native driver.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Current behaviour
After the v2 update, the passing of a
position
ref no longer works. This would be useful for animating other components according to the pager view position outside of theTabView
hierarchy.Expected behaviour
I expected a
position
ref passed as theposition
prop toTabView
would give me the ability to use theTabView
position in other components outside of theTabView
hierarchy, as proposed in issue #781 and merged in PR #782.Code sample
Screenshots (if applicable)
What have you tried
I have clumsily hacked around the issue by pulling the
position
value from therenderTabBar
function, as theposition
prop is passed there. This works but is less than ideal, especially if I have no need to replace the defaultTabBar
.Here is my workaround (copied from #781 (comment)):
Your Environment
The text was updated successfully, but these errors were encountered: