NavigatorIOS - 是否有 viewDidAppear 或 viewWillAppear 等价物? [英] NavigatorIOS - Is there a viewDidAppear or viewWillAppear equivalent?
问题描述
我正在将应用程序移植到 React-Native 以进行测试.当我弹回导航器堆栈中的上一个视图时(点击后退按钮),我想运行一些代码.是否有 viewWillAppear 方法?我在 Navigator 上看到有一个onDidFocus()"回调,这听起来可能是正确的......但在 NavigatorIOS 上似乎没有类似的东西
I'm working on porting an app to React-Native to test it out. When I pop back to a previous view in the navigator stack (hit the back button) I'd like to run some code. Is there a viewWillAppear method? I see on the Navigator there is a "onDidFocus()" callback which sounds like it might be the right thing.. but there doesn't appear to be anything like that on NavigatorIOS
推荐答案
我在UIKit中找到了一种模拟viewDidAppear和viewDidDisappear的方法,
但我不确定这是否是正确"的方式.
I find a way to simulate viewDidAppear and viewDidDisappear in UIKit,
but i'm not sure if it's a "right" way.
componentDidMount: function() {
// your code here
var currentRoute = this.props.navigator.navigationContext.currentRoute;
this.props.navigator.navigationContext.addListener('didfocus', (event) => {
//didfocus emit in componentDidMount
if (currentRoute === event.data.route) {
console.log("me didAppear");
} else {
console.log("me didDisappear, other didAppear");
}
console.log(event.data.route);
});
},
这篇关于NavigatorIOS - 是否有 viewDidAppear 或 viewWillAppear 等价物?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!