簡體   English   中英

在 React Native 中從導航堆棧顯示屏幕時調用哪個方法

[英]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/> } }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM