如何在反应导航上更改屏幕状态

时间:2020-07-10 13:38:45

标签: react-native expo react-navigation

我需要使用导航器上的侦听器更改组件的状态

function TabOneNavigator({navigation}) { 
  
  React.useEffect(() => {
    const unsubscribe = navigation.addListener('tabPress', e => {

      if(global.webview.startUrl != global.webview.props.source.uri){
        //here i need use this method resetWebViewToInitialUrl() from component
      }
    });

    return unsubscribe;
  }, [navigation]);

  return (
    <TabOneStack.Navigator>
      <TabOneStack.Screen
        name="Perfil"
        component={TabOneScreen}
        options={{ headerTitle: 'IzyJob' }}
      />
    </TabOneStack.Navigator>
  );
}

这是我的组成部分

export default class App extends React.Component {

  this.state = {
    key: 1,
    url: 'https://www.google.com'
  };
  
  resetWebViewToInitialUrl = () => {
    this.setState({
      key: this.state.key + 1
    });
  };

  render() {
    return <WebView 
    key={ this.state.key }
    ref={(ref) => { global.webview = ref; }}
    source={{ uri: this.state.url }} 
    onNavigationStateChange={this._onNavigationStateChange.bind(this)}
    style={{ marginTop: 0 }} />;
  }
}

我尝试使用道具,但我不知道导航中的道具如何,我尝试使用全局道具,但不起作用

谢谢

0 个答案:

没有答案