Setting InitialPage does not work
When I set initialPage to 2 it still renders the first tab in the main view. TabBar shows that second tab is selected though. If I swipe left or right it acts as if the first tab was selected all along and tabBar corrects itself. Same thing if I just press on one of the tabs in tabView.
Am I doing something wrong or is this a bug? My React-Version is 0.48. EDIT: This does not happen on React-Native 0.47.2.
render() {
return (
<ScrollableTabView
renderTabBar={() => <DefaultTabBar />}
initialPage={2}
ref={(tabView) => { this.tabView = tabView; }}
tabBarPosition={'bottom'}
prerenderingSiblingsNumber={Infinity}
>
<Text
style={{textAlign: 'center', fontSize: 50, marginTop: '40%'}}
tabLabel='Tab #1'
key={'tab1'}
>Tab1</Text>
<Text
style={{textAlign: 'center', fontSize: 50, marginTop: '40%'}}
tabLabel='Tab #2'
key={'tab2'}
>tab2</Text>
<Text
style={{textAlign: 'center', fontSize: 50, marginTop: '40%'}}
tabLabel='Tab #3'
key={'tab3'}
>tab3</Text>
<Text
style={{textAlign: 'center', fontSize: 50, marginTop: '40%'}}
tabLabel='Tab #4'
key={'tab4'}
>Tab4</Text>
</ScrollableTabView>
);
}

https://github.com/facebook/react-native/issues/15808
+1
+1
[email protected] [email protected]
- open the source file
react-native-scrollable-tab-view/index.js - find the code in the method
componentDidMount:
this.setTimeout(() => {
InteractionManager.runAfterInteractions(() => {
if (Platform.OS === 'android') {
this.goToPage(this.props.initialPage, false);
}
});
}, 0);
- delete the code about os check
this.setTimeout(() => {
InteractionManager.runAfterInteractions(() => {
this.goToPage(this.props.initialPage, false);
});
}, 0);
reload your app , this problem will be fixed, test on ios 11.0.2
@Waltari10 is this fixed? in my case, whenever i set the initialPage to other than 0, it will move the selected tab on the tabbar to correct position, just that the tabview shown is always the first tabview. however, once you click on any tab in the tabbar, it will show the correct tabview.
@luyl I am using
[email protected] [email protected]
So the code for index.js has already changed, and I cannot find the os check happening. Is it already fixed in this version?
Agreed. This is still not working as it should be.
+1 facing the same issue on v0.8.0
any updates on this? Anyone has been working on this? Let me know where you left so I can take it from there so I don't have to repeat all what you have done and maybe I can get the fix or a PR for those ones who wants a fix now.
Try this. It worked. Ideal for changing first pages.
componentDidMount() { setTimeout(() => this.scrollableTabView.goToPage(1), 300); } ... ..... ... <ScrollableTabView ref={(ref) => { this.scrollableTabView = ref; }}
@kubilaytural setTimeout is still not working as it should be,it still stay first page a few time.
Did you try to raise the time? Will you share the code? @wenkangzhou
@kubilaytural Thanks. It`s worked for me.
InteractionManager.runAfterInteractions(() => {
requestAnimationFrame(() => {
this.scrollableTabView.goToPage(this.props.route.params.flag);
});
});