在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問(wèn)答/HTML/ React-Native中使用react-navigation,A跳轉(zhuǎn)到B時(shí)未觸

React-Native中使用react-navigation,A跳轉(zhuǎn)到B時(shí)未觸發(fā)A的componentWillUnmount?

在React-Native的項(xiàng)目中使用組件react-navigation進(jìn)行頁(yè)面路由管理,

在A組件的componentDidMount中開(kāi)啟一個(gè)定時(shí)器,并在componentWillUnmount中進(jìn)行清除。

A頁(yè)面使用this.props.navigation.navigate('B')跳轉(zhuǎn)到B頁(yè)面后,發(fā)現(xiàn)componentWillUnmount未被執(zhí)行

對(duì)于該組件的問(wèn)題網(wǎng)上有如下回答:

Navigator uses stack to manager route. When you push a new page,
current page wont unmount, if you pop from new page to the current
page, the new page will unmount. And in other scene, if you render
some child component based on some regulation like isLoading or other,
the componentWillUnmount method will also be called when they no
longer need to be rendered.

react-navigation組件中存在這樣的天然缺陷,不知各位如何應(yīng)對(duì)componentWillUnmount生命周期未調(diào)用的場(chǎng)景

回答
編輯回答
背叛者

此問(wèn)題是關(guān)于清除頁(yè)面componentDidmount中開(kāi)啟的定時(shí)器。
現(xiàn)在曲線救國(guó),使用全局單例倒計(jì)時(shí),并在唯一沒(méi)有使用倒計(jì)時(shí)的頁(yè)面清除該全局倒計(jì)時(shí)

2017年4月10日 19:41
編輯回答
慢半拍

用 navigation lifecycle 方法
https://reactnavigation.org/d...

2017年6月25日 17:46