| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194 |
- //
- // YRReactVC.m
- // shiku_im
- //
- // Created by liujl on 2019/7/29.
- //
- #import "YRReactVC.h"
- #import "YRRnChartsAllVC.h"
- #import "UIDevice+extension.h"
- #import "AppDelegate.h"
- #import "YRRnBridge.h"
- #import "UINavigationController+popGes.h"
- #import <React/RCTRootView.h>
- #import <React/RCTBundleURLProvider.h>
- #import <CodePush/CodePush.h>
- //url:https://uu-update.ubtob.com
- //Production │ rKIg25bUKa6egfOwWhBgjvXOJjka4ksvOXqog │
- //├────────────┼───────────────────────────────────────┤
- //│ Staging │ if4T49oStVOr08rU6SJaPJQmFK3O4ksvOXqog │
- //ReactNative使用过的内存不释放,因此采用缓存机制控制内存
- static NSMutableDictionary * rootDic = nil;
- @interface YRReactVC ()<YRRnBridgeDelegate>
- @property(weak,nonatomic)YRRnChartsAllVC *chartVC;
- @end
- @implementation YRReactVC
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- }
- -(void)createUI{
-
-
- [self addNotification];
-
- NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
-
- jsCodeLocation = [CodePush bundleURL];
- //
- self.moduleName = self.moduleName?:@"UU_RN";
-
- NSString * strUrl = @"http://10.1.80.97:8081/index.bundle?platform=ios";
- jsCodeLocation = [NSURL URLWithString:strUrl] ;
-
- if (!rootDic) {
-
- rootDic = [NSMutableDictionary dictionary];
-
-
- RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"RNApp"
- initialProperties:@{@"UU":@"UU_RN"}
- launchOptions:nil];
-
- [rootDic setObject:rootView forKey:self.moduleName];
-
- rootView.loadingView.hidden = NO;
-
-
- }else{
-
- if (!rootDic[self.moduleName]) {
-
- RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"UU_RN"
- initialProperties:@{@"UU":@"UU_RN"}
- launchOptions:nil];
-
- [rootDic setObject:rootView forKey:self.moduleName];
-
-
- rootView.loadingView.hidden = NO;
-
- }else{
-
- RCTRootView *rootView = (RCTRootView *)rootDic[self.moduleName];
- //改变该属性时ReactNative重新渲染
- rootView.appProperties = @{@"one":@"one"};
-
- }
-
- }
-
-
-
- self.view = (RCTRootView *)rootDic[self.moduleName];
-
- }
- #pragma mark -- YRRnBridgeDelegate
- -(void)addNotification{
- //返回跳入界面
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bridgeHasBeenCreated:) name:@"YRReactNativeBridgeInited" object:nil];
-
- }
- -(void)bridgeHasBeenCreated:(NSNotification *)notifacation{
-
- YRRnBridge *bridge = (YRRnBridge *)notifacation.object;
-
- bridge.delegate = self;
-
- }
- -(void)reactNativeControllerShouldBack{
-
- [self backAction];
-
- }
- -(void)reactNativeControllerGestureEnabled:(BOOL)enabled{
-
- self.im_interactivePopDisabled = !enabled;
-
- }
- -(void)reactNativeControllerShouldAutorotateParams:(NSDictionary *)params{
-
- // BOOL enable = [params[@"enable"] boolValue];
- //
- // if (enable) {
- //
- // YRRnChartsAllVC *chartVC = [YRRnChartsAllVC new];
- //
- // chartVC.params = params;
- //
- // self.chartVC = chartVC;
- //
- // [self presentViewController:chartVC animated:YES completion:nil];
- //
- // }else{
- //
- // AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- // //关闭横屏仅允许竖屏
- // appDelegate.allowRotation = NO;
- // //切换到竖屏
- // [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait];
- //
- // [self.chartVC dismissViewControllerAnimated:YES completion:nil];
- //
- // }
-
-
- }
- #pragma mark -- 旋转屏设置
- -(void)viewWillAppear:(BOOL)animated{
-
- [super viewWillAppear:animated];
-
- self.navigationController.navigationBar.hidden = YES;
-
- AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- //允许转成横屏
- appDelegate.allowRotation = YES;
-
-
-
- }
- -(void)viewDidDisappear:(BOOL)animated{
-
- [super viewDidDisappear:animated];
-
- AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
- //允许转成横屏
- appDelegate.allowRotation = NO;
-
- }
- -(void)dealloc{
-
- [[NSNotificationCenter defaultCenter] removeObserver:self name:@"YRReactNativeBridgeInited" object:nil];
-
- }
- @end
|