为什么 componentWillUnmount() 不执行?
Why does componentWillUnmount() not execute?
在一个项目中,我使用了 wix 的 RNN。我在其中有一个屏幕,我们称它为 'Screen1'。 Screen1 有一个调用 Navigation.push()
并移动到 'Screen2' 的按钮。 Screen1 在 componentWillUnmount()
中设置了警报。但是当屏幕改变时,永远不会显示警报。
export default class Screen1 extends React.Component {
componentDidMount() {
Navigation.events().bindComponent(this);
}
componentWillUnmount() {
alert("Goodbye screen1");
}
nextScreen = () => {
Navigation.push(this.props.componentId)
}
render() {
<View style={{height: '100%', width='100%'}}>
<TouchableOpacity onPress={this.nextScreen}>
<Text>Test Button</Text>
</TouchableOpacity>
</View>
}
}
我希望在移动到下一个屏幕时触发警报。但是,组件似乎仍处于挂载状态,因为未触发警报,并且 screen1
的 componentDidMount() 中有一个函数(未显示)正在从下一个屏幕执行。那么 wix 如何处理屏幕变化时的组件生命周期?
发生的情况是您的组件仍处于安装状态。您只是将另一个屏幕推到它上面。它不可见但仍然安装。
我不是 RNN 方面的专家,但我想您要找的是 componentDidDisappear 事件。
希望对您有所帮助。
在一个项目中,我使用了 wix 的 RNN。我在其中有一个屏幕,我们称它为 'Screen1'。 Screen1 有一个调用 Navigation.push()
并移动到 'Screen2' 的按钮。 Screen1 在 componentWillUnmount()
中设置了警报。但是当屏幕改变时,永远不会显示警报。
export default class Screen1 extends React.Component {
componentDidMount() {
Navigation.events().bindComponent(this);
}
componentWillUnmount() {
alert("Goodbye screen1");
}
nextScreen = () => {
Navigation.push(this.props.componentId)
}
render() {
<View style={{height: '100%', width='100%'}}>
<TouchableOpacity onPress={this.nextScreen}>
<Text>Test Button</Text>
</TouchableOpacity>
</View>
}
}
我希望在移动到下一个屏幕时触发警报。但是,组件似乎仍处于挂载状态,因为未触发警报,并且 screen1
的 componentDidMount() 中有一个函数(未显示)正在从下一个屏幕执行。那么 wix 如何处理屏幕变化时的组件生命周期?
发生的情况是您的组件仍处于安装状态。您只是将另一个屏幕推到它上面。它不可见但仍然安装。
我不是 RNN 方面的专家,但我想您要找的是 componentDidDisappear 事件。
希望对您有所帮助。