rn 跳转至html5,ReactNative-从RN端跳转到原生界面
//實現跳轉
//可以做一次封裝,這里只是展示功能
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.nav.navigationBarHidden = NO;
[app.nav pushViewController:vc animated:YES];
可以這么做的前提就是在app初始化的時候,rootviewcontroller需要設置為一個導航控制器:
在AppDelegate.m的
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
中添加或者修改:
RCTRootView *rootView =
[[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"AwesomeProject"
initialProperties:nil
launchOptions:launchOptions];
//已有的RN界面/模塊
rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
SomeViewController *rootViewController = [SomeViewController new];//某個視圖控制器
rootViewController.view = rootView;
self.nav = [[UINavigationController alloc]initWithRootViewController:rootViewController];
self.window.rootViewController = self.nav;
self.nav.navigationBarHidden = YES;
RN界面可以看做是屬于NavigateController管理的rootVC的View,
這樣可以做到原生部分與RN生成的部分相互之間沒有額外的干擾,相互跳轉不會產生問題,當然,在這種情況下,跳轉到原生部分后,開發時的那些Command快捷鍵就失效了,安卓的情況也是類似,只不過跳轉使用的可能是另一個Activity,鍵盤響應不一樣。
這樣在RN端 調用某個原生插件的時候,就可以實現跳轉了,例如:
[[SCApp loginManager]
login:localUserId
token:localToken
completion:^(NSError *error) {
if(sessionInfo&&sessionInfo[@"toId"]){
SCSession *session = [SCSession session:sessionInfo[@"toId"] type: SCSession TypeP2P];
//初始化SessionViewCongtroller
SCSession ViewController *vc = [[SCSession ViewController alloc] initWithSession:session];
//實現跳轉
AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];
app.nav.navigationBarHidden = NO;
[app.nav pushViewController:vc animated:YES];
}else{
UIAlertView *uav = [[UIAlertView alloc]initWithTitle:@"提示" message:@"用戶會話已過期" delegate:nil cancelButtonTitle:@"忽略" otherButtonTitles:nil, nil];
[uav show];
}
}];
總結
以上是生活随笔為你收集整理的rn 跳转至html5,ReactNative-从RN端跳转到原生界面的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy维度交换_数据分析-gt;基本
- 下一篇: 计算尖峰电流的目的_入门必看!负荷计算的