dns*_*son 9 objective-c ios react-native
我有一个现有的应用程序,我正在努力为其中的一部分集成React-Native.我无法理解如何"退出"react-native并返回原生视图.
这是一些代码:
// Main objective-c code that bootstraps the react-native view. This view is loaded as a modal view.
MainViewController.m:
- (void)viewDidLoad {
[super viewDidLoad];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"IndexApp" initialProperties:props launchOptions:nil];
rootView.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height-49);
[self.view addSubview:rootView];
}
Run Code Online (Sandbox Code Playgroud)
我最初的反应意见如下:
render() {
return (
<Navigator
style={styles.container}
...
Run Code Online (Sandbox Code Playgroud)
我在导航器上有一个右导航按钮,我想"关闭"反应视图和底层MainViewController本机视图.
我已经尝试从反应视图回调MainViewController,但没有用:
RCT_EXPORT_METHOD(dismiss:(NSString *)name location:(NSString *)location)
{
NSLog(@"dismiss...");
// these don't do anything
//[self dismissViewControllerAnimated:YES completion:nil];
//[self.navigationController popViewControllerAnimated:YES];
// anything with _rootView doesn't do anything, i.e. _rootView removeFromSuperview];
}
Run Code Online (Sandbox Code Playgroud)
任何有关"退出"反应本机视图并返回本机视图的方法的帮助将不胜感激.
注意:这不起作用 - 我将其留在这里作为不起作用的示例。请查看我的其他答案以了解可行的方法。
如果你以这种方式呈现 MainViewController ,popViewController:应该可以工作
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle?platform=ios&dev=true"];
RCTRootView *reactView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"SimpleApp"
initialProperties:nil
launchOptions:nil];
MainViewController *rootViewController = [MainViewController new];
rootViewController.view = reactView;
[[self navigationController] pushViewController:rootViewController animated:YES];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1938 次 |
| 最近记录: |