I used createMaterialTopTabNavigator
to create footer tab, like as below:
(我使用createMaterialTopTabNavigator
创建页脚标签,如下所示:)
const TabNavigator = createMaterialTopTabNavigator(
{
HomeScreen: HomeScreen,
UserScreen: UserScreen,
},
{
initialRouteName: 'HomeScreen',
navigationOptions: {
header: null,
},
tabBarPosition: 'bottom',
tabBarComponent: FooterTabs,
},
);
and in FooterTabs
on home screen button, i have this code:
(在主屏幕上的FooterTabs
按钮中,我有以下代码:)
if (this.props.navigation.state.index === 0) {
// i want call scrollToUp function in HomeScreen component
}
i want when user is in HomeScreen and press on home button react call scrollToUp method in HomeScreen.
(我想当用户在HomeScreen中并按下Home按钮时,在HomeScreen中反应调用scrollToUp方法。)
===== resolved: I added this code to HomeScreen:
(=====已解决:我将此代码添加到HomeScreen:)
componentDidMount() {
this.props.navigation.setParams({
onFocus: this.scrollToUp,
});
}
and edit FooterTabs
like as below:
(并如下编辑FooterTabs
:)
if (this.props.navigation.state.index === 0) {
this.props.navigation.state.routes[0].params.onFocus();
}
ask by Masoud92m translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…