[英]Navigation from the header of the bottom tab navigator in react native
[英]Trigger Class Function Call from Tab Navigator Tab Press - React Native/Navigation
我有一個TabNavigator組件,並且希望在按下Tab鍵時重置各個“ Tab屏幕”狀態。 如何在Tab鍵按下時調用類(組件)方法? 我看過tabBarOnPress,但這需要父級(TabNavigator)的函數。 我希望觸發類方法,並且我不想導出該方法。
假設您有這樣的TabNavigator
const HOME = TabNavigator({
[SCREENS.EXPLORESCREEN]: { screen: ExploreScreen },
[SCREENS.ASKSCREEN]: { screen: AskScreen },
},{
initialRouteName: SCREENS.EXPLORESCREEN
})
const PrimaryNav = StackNavigator({
[SCREENS.HOMESCREEN]: {
screen: HOME,
navigationOptions=({navigation})=>{
return{
tabBarOnPress :()=>{
if (typeof navigation.state.params.cancelState!=="undefined"){
navigation.state.params.cancelState()
}
else{
//your stuff
}
}
}
}
},
},
{
// Default config for all screens
headerMode: "screen",
initialRouteName: SCREENS.HOMESCREEN
,
}
);
ExploreScreen.js
class ExploreScreen extends Component {
componentDidMount(){
this.props.navigation.setParams({
cancelState:this.cancelState
})
}
cancelState=()=>{
//your Stuff
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.