【发布时间】:2020-06-16 08:10:48
【问题描述】:
我有两个屏幕。每个屏幕包含三个子类。是的,我正在使用每个屏幕的选项卡。
在我的第一个屏幕上说。 Main-screen 有 -> ScreenA, ScreenB, ScreenC。而我的DetailScreen 有 -> ScreenD, ScreenE, ScreenF
现在从我的ScreenA 我必须推送到ScreenD。代码在这里:
this.props.navigation.navigate('DetailScreen', {
onNavigateBack: this.refresh.bind(this)
})
refresh(commentText) {
alert('alert me')
}
在我的ScreenD 中,我只有一个按钮可以返回。并更新我的ScreenA 中的值:
this.props.navigation.state.params.onNavigateBack(this.state.commentText);
this.props.navigation.goBack();
但我总是收到如下错误:
Undefined is not an object (evaluating 'this.props.navigation.state')
任何帮助都会很棒。我的目标是在我从screen D回来时更新我的screen A
我的主屏幕:
<ScreenA navigation={this.props.navigation} tabLabel= "ScreenA" props = {this.props} tabView={this.tabView}/>
<ScreenB navigation={this.props.navigation} tabLabel= "ScreenB" props = {this.props} tabView={this.tabView}/>
<ScreenC navigation={this.props.navigation} tabLabel= "ScreenC" props = {this.props} tabView={this.tabView} goToPage={ () => this.goToPage(2) }/>
DetailScreen:
<ScreenD navigation={this.props.navigation} tabLabel= "ScreenD" props = {this.props} tabView={this.tabView}/>
<ScreenE navigation={this.props.navigation} tabLabel= "ScreenE" props = {this.props} tabView={this.tabView}/>
<ScreenF navigation={this.props.navigation} tabLabel= "ScreenF” props = {this.props} tabView={this.tabView} goToPage={ () => this.goToPage(2) }/>
我的 RootStackScreen :
import React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import ScreenA from './ScreenA';
import ScreenB from './ScreenB';
const RootStack = createStackNavigator();
const RootStackScreen = ({navigation}) => (
<RootStack.Navigator headerMode='none'>
<RootStack.Screen name="ScreenA" component={ScreenA}/>
<RootStack.Screen name="ScreenB" component={ScreenB}/>
</RootStack.Navigator>
);
export default RootStackScreen;
【问题讨论】:
-
您能否添加您的 ScreenA 或 ScreenB 之一的代码?
-
@Sennen Randika 我正在使用平面列表。没有其他的。它非常大,这就是为什么不在这里发布。
export default class MainScreen extends Component {} -
嗨@kumarbarian,你使用哪个版本的
react-navigation?如果你只有this.props.navigation.goBack();,它会返回上一个屏幕吗? -
@Yasuooooooooo 不,我收到此错误
Undefined is not an object (evaluating this.props.navigation.goBack())。` "version": "0.62.2"` -
您是否将
constructor(props) { }放入了屏幕组件中?
标签: javascript react-native react-navigation