从 React Native 中的 Navigation Stack 显示屏幕时调用哪个方法

Which method is called when the screen is displayed from the Navigation Stack in React Native

我是 React Native 的新手,我正在使用

import {  createAppContainer } from 'react-navigation';
import { createStackNavigator } from 'react-navigation-stack'

用于从一个屏幕导航到下一个屏幕并在按下后退按钮时显示堆栈中的屏幕。


我想在从堆栈显示屏幕时聚焦 TextInput。

FirstScreen -> SecondScreen (Back Button Press)-> FirstScreen (Focus TextInput)

FirstScreen从栈中显示时调用了哪个方法?

我尝试将代码放入 ComponentDidMonunt(), ComponentWillMount(), render(), ComponentWillUnmount() 方法中,但是当从堆栈中显示 FirstScreen 时这些方法没有被调用。

在 react-navigation https://reactnavigation.org/docs/navigation-events/

中尝试 NavigationEvent

class Profile extends React.Component {
  componentDidMount() {
    this._unsubscribe = navigation.addListener('focus', () => {
      // do something
      this.emailInput.focus()
    });
  }

  componentWillUnmount() {
    this._unsubscribe();
  }

  render() {
      <View>
        <TextInput ref={ref => { this.emailInput = ref; }}/>
      <View/>
  }
}