Jea*_*ent 5 uiviewcontroller uinavigationcontroller ios react-native
我正在使用Objective-C/Swift编写的现有iOS应用程序中集成组件.
作为我的应用程序的根视图控制器,我使用了UINavigationController.
在我的应用程序的多个视图控制器之一中,我有一个按钮,可以在导航控制器中推送包含以下代码的视图控制器:
@objc class ReactNativeViewController: UIViewController {
override func viewDidLoad() {
let jsCodeLocation = NSURL(string: "http://localhost:8081/index.ios.bundle?platform=ios&dev=true")
let contactsView = RCTRootView(bundleURL: jsCodeLocation, moduleName: "MainComponent", initialProperties: nil, launchOptions: nil)
self.view.addSubview(contactsView)
contactsView.frame = self.view.bounds;
}
}
Run Code Online (Sandbox Code Playgroud)
MainComponent返回一个Navigator管理多个React-Native组件的东西:
return (
<Navigator
initialRoute={initialRoute}
renderScene={(route, navigator) => {
if (route.component) {
return <route.component navigator={navigator} {...route.passProps} />;
}
}}
navigationBar={
<Navigator.NavigationBar
routeMapper={this.NavigationBarRouteMapper}
style={styles.navBar}
/>
}
/>
);
Run Code Online (Sandbox Code Playgroud)
该工作流程正常.我唯一需要的是流行的方式ReactNativeViewController从我UINavigationController当按钮Back被击中的主要阵营本地组件.
我试过以下但没有运气:
使用单个方法创建一个本机模块,该方法popLastViewController弹出从UINavigationController显示的显示的UIViewController:
@implementation RNNavigationControllerBridge
RCT_EXPORT_MODULE()
RCT_EXPORT_METHOD(popLastViewController) {
UINavigationController *navigationController = (UINavigationController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
[navigationController popViewControllerAnimated:NO];
}
@end
Run Code Online (Sandbox Code Playgroud)按下后退按钮时调用上面的方法:
onPress={() => {
if (index === 0) {
NativeViewsManager.popLastViewController();
} else {
navigator.pop();
}
}}
Run Code Online (Sandbox Code Playgroud)但这不起作用.
有什么建议吗?
问题解决了!
RCT_EXPORT_METHOD(popLastViewController) {
dispatch_async(dispatch_get_main_queue(), ^{
UINavigationController *navigationController = (UINavigationController *)[[[[UIApplication sharedApplication] delegate] window] rootViewController];
[navigationController popViewControllerAnimated:YES];
});
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
955 次 |
| 最近记录: |