react-native ios push 本地view
2015-11-17 18:41
706 查看
IOS ViewController 切换笔记参考:http://onevcat.com/2013/10/vc-transition-in-ios7/
react-native JS端定义一个简单的button就可以了,点击调用IOS原生如下:
.h文件
#import <UIKit/UIKit.h>
#import "Base/RCTBridgeModule.h"
#import "RCTUtils.h"
#import "AppDelegate.h"
@interface XXX : NSObject <RCTBridgeModule>
@end
.m文件
#import "XXX.h"
TestViewController.h
//
// TestViewController.h
// MagicWindowTest
//
// Created by wangyanan on 15/11/17.
// Copyright © 2015年 Facebook. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TestViewController : UIViewController
@end
TestViewController.m
//
// TestViewController.m
// MagicWindowTest
//
// Created by wangyanan on 15/11/17.
// Copyright © 2015年 Facebook. All rights reserved.
//
#import "TestViewController.h"
#import "RCTRootView.h"
@interface TestViewController ()
@end
@implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect viewSize=self.view.bounds;
UIButton*loginButton=[[UIButton alloc]initWithFrame:CGRectMake(viewSize.size.width/2-50, viewSize.size.height/2, 100, 50)];
[loginButton setTitle:@"登录" forState:UIControlStateNormal];
loginButton.backgroundColor=[UIColor blueColor];
[loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:loginButton];
}
-(void) login
{
NSLog(@"login");
[self presentRegistrationViewController];
}
- (void)presentRegistrationViewController {
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localHost:8081/index.ios.bundle?platform=ios&dev=true"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MagicWindowTest"
initialProperties:nil
launchOptions:nil];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
mainViewController.view = rootView;
[self.navigationController pushViewController:mainViewController animated:true];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
这样应用程序在进入的时候是js界面,点击Button跳转到我们自定义的TestView界面,点击TestView界面的Button的时候又返回js界面
主要方法为:
1.js -- native
- (void)presentRegistrationViewController {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
TestViewController *bceRegistrationViewController = [TestViewController new];
dispatch_async(dispatch_get_main_queue(), ^{
[mainViewController presentViewController:bceRegistrationViewController animated:YES completion:nil];
});
}
2.native -- js
- (void)presentRegistrationViewController {
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localHost:8081/index.ios.bundle?platform=ios&dev=true"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MagicWindowTest"
initialProperties:nil
launchOptions:nil];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
mainViewController.view = rootView;
[self.navigationController pushViewController:mainViewController animated:true];
[self dismissViewControllerAnimated:YES completion:nil];
}
react-native JS端定义一个简单的button就可以了,点击调用IOS原生如下:
.h文件
#import <UIKit/UIKit.h>
#import "Base/RCTBridgeModule.h"
#import "RCTUtils.h"
#import "AppDelegate.h"
@interface XXX : NSObject <RCTBridgeModule>
@end
.m文件
#import "XXX.h"
#import "Base/RCTLog.h" #import "TestViewController.h" @implementation XXX RCT_EXPORT_MODULE() #pragma mark "API" RCT_EXPORT_METHOD(login:(RCTResponseSenderBlock)callback) { [self presentRegistrationViewController]; } - (void)presentRegistrationViewController { UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow]; UIViewController *mainViewController = keyWindow.rootViewController; TestViewController *bceRegistrationViewController = [TestViewController new]; dispatch_async(dispatch_get_main_queue(), ^{ [mainViewController presentViewController:bceRegistrationViewController animated:YES completion:nil]; }); } @end
TestViewController.h
//
// TestViewController.h
// MagicWindowTest
//
// Created by wangyanan on 15/11/17.
// Copyright © 2015年 Facebook. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TestViewController : UIViewController
@end
TestViewController.m
//
// TestViewController.m
// MagicWindowTest
//
// Created by wangyanan on 15/11/17.
// Copyright © 2015年 Facebook. All rights reserved.
//
#import "TestViewController.h"
#import "RCTRootView.h"
@interface TestViewController ()
@end
@implementation TestViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
CGRect viewSize=self.view.bounds;
UIButton*loginButton=[[UIButton alloc]initWithFrame:CGRectMake(viewSize.size.width/2-50, viewSize.size.height/2, 100, 50)];
[loginButton setTitle:@"登录" forState:UIControlStateNormal];
loginButton.backgroundColor=[UIColor blueColor];
[loginButton addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:loginButton];
}
-(void) login
{
NSLog(@"login");
[self presentRegistrationViewController];
}
- (void)presentRegistrationViewController {
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localHost:8081/index.ios.bundle?platform=ios&dev=true"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MagicWindowTest"
initialProperties:nil
launchOptions:nil];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
mainViewController.view = rootView;
[self.navigationController pushViewController:mainViewController animated:true];
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
这样应用程序在进入的时候是js界面,点击Button跳转到我们自定义的TestView界面,点击TestView界面的Button的时候又返回js界面
主要方法为:
1.js -- native
- (void)presentRegistrationViewController {
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
TestViewController *bceRegistrationViewController = [TestViewController new];
dispatch_async(dispatch_get_main_queue(), ^{
[mainViewController presentViewController:bceRegistrationViewController animated:YES completion:nil];
});
}
2.native -- js
- (void)presentRegistrationViewController {
NSURL *jsCodeLocation = [NSURL URLWithString:@"http://localHost:8081/index.ios.bundle?platform=ios&dev=true"];
RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation
moduleName:@"MagicWindowTest"
initialProperties:nil
launchOptions:nil];
UIWindow *keyWindow = [[UIApplication sharedApplication] keyWindow];
UIViewController *mainViewController = keyWindow.rootViewController;
mainViewController.view = rootView;
[self.navigationController pushViewController:mainViewController animated:true];
[self dismissViewControllerAnimated:YES completion:nil];
}
相关文章推荐
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 峰回路转,Firefox 浏览器即将重返 iOS 平台
- 不可修补的 iOS 漏洞可能导致 iPhone 4s 到 iPhone X 永久越狱
- iOS 12.4 系统遭黑客破解,漏洞危及数百万用户
- 每日安全资讯:NSO,一家专业入侵 iPhone 的神秘公司
- [转][源代码]Comex公布JailbreakMe 3.0源代码
- 讲解iOS开发中基本的定位功能实现
- js判断客户端是iOS还是Android等移动终端的方法
- IOS开发环境windows化攻略
- 检测iOS设备是否越狱的方法
- .net平台推送ios消息的实现方法
- 探讨Android与iOS,我们将何去何从?
- Android、iOS和Windows Phone中的推送技术详解
- IOS 改变键盘颜色代码
- 举例详解iOS开发过程中的沙盒机制与文件
- Android和IOS的浏览器中检测是否安装某个客户端的方法
- 分享一个iOS下实现基本绘画板功能的简单方法
- javascript实现阻止iOS APP中的链接打开Safari浏览器
- IOS中内存管理那些事