react-native ios push 本地view
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"
#import "Base/RCTLog.h"#import "TestViewController.h"@implementation XXXRCT_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:jsCodeLocationmoduleName:@"MagicWindowTest"initialProperties:nillaunchOptions: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:jsCodeLocationmoduleName:@"MagicWindowTest"initialProperties:nillaunchOptions: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 ios push 本地view相关推荐
- React Native ios打包
开发React Native的过程成,js代码和图片资源运行在一个Debug Server上,每次更新代码之后只需要使用command+R键刷新就可以看到代码的更改,这种方式对于调试来说是非常方便的. ...
- react native ios 上架
1.申请开发者账号,去苹果开发者中心申请 2.applicationloader 集申请证书.真机调试.发布于一身,避免繁琐的官网申请过程 http://www.applicationloader.n ...
- React native ios上架
1.申请开发者账号,去苹果开发者中心申请 2.applicationloader 集申请证书.真机调试.发布于一身,避免繁琐的官网申请过程 http://kxdang.com/topic/appupl ...
- 关于react native code push的JS端配置攻略
1. 引用CodePush高阶组件,应用在项目根组件中: import CodePush from "react-native-code-push";class App exten ...
- React native ios长按显示粘贴,复制为英文改为中文
首先我们将项目用xcode打开,接下来如下图: 最后一步选择你需要显示的语言就OK了.
- react native iOS 0.68.2 No visible @interface for ‘RCTBundleURLProvider
报错:No visible @interface for 'RCTBundleURLProvider' declares the selector 'jsBundleURLForBundleRoot: ...
- 最新React Native 搭建本地Code Push服务(非常全!)
React Native如何搭建本地Code Push服务, iOS.Android项目配置问题,错误汇总等. Code Push系列之 - 发布更新 Code Push系列之 - 客户端检查更新 C ...
- iOS新知识学习之React Native开发工具集
本文整理了React Native iOS开发过程中有用的工具.服务.测试.库以及网站等. 工具 你可以选择不同的开发环境:DECO.EXPO或者你可以使用Nuclide+Atom,目前我使用EXPO ...
- android 加载静态网页,React Native:如何在WebView内加载SPA或本地静态HTML页面?
React Native:如何在WebView内加载SPA或本地静态HTML页面? React Native WebView允许你使用uri属性加载可公开访问的资源,就像程序内的一个浏览器.但是,当你 ...
- React Native 集成分享第三方登录功能分享第三方登录模块开发(iOS)
期待已久的新课上线啦!解锁React Native开发新姿势,一网打尽React Native最新与最热技术,点我Get!!! 在我们常用的App中经常会看到分享与第三方登录的功能,可以说分享与第三方 ...
最新文章
- VS新建工程或者新建项时 出现未定义标识符号
- gnuradio 初次使用
- 项目管理十大知识领域之项目进度管理
- 教程Xcode 4下编译发布与提交App到AppStore
- Java多线程的几种写法
- 2019年1月份GitHub上最热门的Java开源项目
- SPT20 协议_【笔试时间有变】关于国家电网三方协议的那些事!
- iOS_03_关键字、标识符、注释
- 中心极限定理通俗介绍
- python-pip : Depends: python-setuptools (= 0.6c1) 问题
- EE214 Lecture 14 Differential pair部分公式推导
- 机械设计(机电)_简要问答_复习笔记
- 华为云薛浩:走进视频“新时代”
- 使用pyautogui库实现简单的微信朋友圈自动点赞
- SGU 264 Travel(稳定婚姻匹配)
- 基于中国剩余定理的秘密共享方案(miracl)
- wuc-tab标签点击不了_不干胶标签专属定制
- HTTP版本之间的区别
- Java指定时间执行任务
- 零基础学浙大翁恺C语言(4):进一步的判断与循环