i have a main screen that contains 2 Tabs in which every one renders different result. At the end of the the first tabs, i have two buttons that : First Button --> redirect to First Tab year 1 (the default tab) Second Button --> redirect to First Tab Version Two year 2 So, basically the buttons redirect to different Tab every time selected . I need to only change the tab not the whole screen. here is the code that i used and it's working fine for the default Tab but i don't know how to implement the buttons so that it redirects to different tabs with changing the main screen ... Any help ?
Main screen :
<Tabs>
<Tab heading="First Tab">
<FirstTab text={key} />
</Tab>
<Tab heading="Second Tab">
<SecondTab/>
</Tab>
</Tabs>
the First Tab (the default one)
<ScrollView>
...
<View style={{flexDirection: 'row'}}>
<Button active>
<Text>
year 1
</Text>
</Button>
<Button>
<Text> year 2 </Text>
</Button>
</View>
</View>
</ScrollView>
Here is an image that explains what i need to do :
I also tried this method: Implementing Footer Tabs in Native React using Native Base and the code i used is :
<Tabs>
<Tab>
<Content>{this.renderSelectedTab()} </Content>
</Tab>
<Tab>
<SecondTab/>
</Tab>
</Tabs>
<View style={{flexDirection: 'row'}}>
<Button active={this.selectedTab==='2016'}
onPress={() => this.state.setState({selectedTab: '2016'})}>
<Text> 2016 </Text>
</Button>
<Button active={this.state.selectedTab==='2015'}
onPress={() => this.setState({selectedTab: '2015'})} >
<Text> 2015 </Text>
</Button>
</View>
..
renderSelectedTab () {
console.log("this.state.selectedTab", this.selectedTab )
switch (this.state.selectedTab) {
case '2016':
return (<Tab2016 />);
break;
case '2015':
return (<Tab2015 />);
break;
default:
return (<Tab2016 />);
}
}
If i use this.selectedTab instead of this.state.selectedTab it runs fine but i get in the console : and it runs directly the default value and the buttons don't work