亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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

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

LEATH 2023-07-06 17:13:50
我是 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 時,不會調用這些方法。
查看完整描述

1 回答

?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

嘗試在react-navigation中使用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/>

? }

}


查看完整回答
反對 回復 2023-07-06
  • 1 回答
  • 0 關注
  • 134 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號