YRReactVC.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. //
  2. // YRReactVC.m
  3. // shiku_im
  4. //
  5. // Created by liujl on 2019/7/29.
  6. //
  7. #import "YRReactVC.h"
  8. #import "YRRnChartsAllVC.h"
  9. #import "UIDevice+extension.h"
  10. #import "AppDelegate.h"
  11. #import "YRRnBridge.h"
  12. #import "UINavigationController+popGes.h"
  13. #import <React/RCTRootView.h>
  14. #import <React/RCTBundleURLProvider.h>
  15. #import <CodePush/CodePush.h>
  16. //url:https://uu-update.ubtob.com
  17. //Production │ rKIg25bUKa6egfOwWhBgjvXOJjka4ksvOXqog │
  18. //├────────────┼───────────────────────────────────────┤
  19. //│ Staging │ if4T49oStVOr08rU6SJaPJQmFK3O4ksvOXqog │
  20. //ReactNative使用过的内存不释放,因此采用缓存机制控制内存
  21. static NSMutableDictionary * rootDic = nil;
  22. @interface YRReactVC ()<YRRnBridgeDelegate>
  23. @property(weak,nonatomic)YRRnChartsAllVC *chartVC;
  24. @end
  25. @implementation YRReactVC
  26. - (void)viewDidLoad {
  27. [super viewDidLoad];
  28. // Do any additional setup after loading the view.
  29. }
  30. -(void)createUI{
  31. [self addNotification];
  32. NSURL *jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
  33. jsCodeLocation = [CodePush bundleURL];
  34. //
  35. self.moduleName = self.moduleName?:@"UU_RN";
  36. // NSString * strUrl = @"http://10.1.80.96:8081/index.bundle?platform=ios";
  37. // jsCodeLocation = [NSURL URLWithString:strUrl] ;
  38. if (!rootDic) {
  39. rootDic = [NSMutableDictionary dictionary];
  40. RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"UU_RN"
  41. initialProperties:@{@"UU":@"UU_RN"}
  42. launchOptions:nil];
  43. [rootDic setObject:rootView forKey:self.moduleName];
  44. rootView.loadingView.hidden = NO;
  45. }else{
  46. if (!rootDic[self.moduleName]) {
  47. RCTRootView *rootView = [[RCTRootView alloc] initWithBundleURL:jsCodeLocation moduleName:@"UU_RN"
  48. initialProperties:@{@"UU":@"UU_RN"}
  49. launchOptions:nil];
  50. [rootDic setObject:rootView forKey:self.moduleName];
  51. rootView.loadingView.hidden = NO;
  52. }else{
  53. RCTRootView *rootView = (RCTRootView *)rootDic[self.moduleName];
  54. //改变该属性时ReactNative重新渲染
  55. rootView.appProperties = @{@"one":@"one"};
  56. }
  57. }
  58. self.view = (RCTRootView *)rootDic[self.moduleName];
  59. }
  60. #pragma mark -- YRRnBridgeDelegate
  61. -(void)addNotification{
  62. //返回跳入界面
  63. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(bridgeHasBeenCreated:) name:@"YRReactNativeBridgeInited" object:nil];
  64. }
  65. -(void)bridgeHasBeenCreated:(NSNotification *)notifacation{
  66. YRRnBridge *bridge = (YRRnBridge *)notifacation.object;
  67. bridge.delegate = self;
  68. }
  69. -(void)reactNativeControllerShouldBack{
  70. [self backAction];
  71. }
  72. -(void)reactNativeControllerGestureEnabled:(BOOL)enabled{
  73. self.im_interactivePopDisabled = !enabled;
  74. }
  75. -(void)reactNativeControllerShouldAutorotateParams:(NSDictionary *)params{
  76. // BOOL enable = [params[@"enable"] boolValue];
  77. //
  78. // if (enable) {
  79. //
  80. // YRRnChartsAllVC *chartVC = [YRRnChartsAllVC new];
  81. //
  82. // chartVC.params = params;
  83. //
  84. // self.chartVC = chartVC;
  85. //
  86. // [self presentViewController:chartVC animated:YES completion:nil];
  87. //
  88. // }else{
  89. //
  90. // AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  91. // //关闭横屏仅允许竖屏
  92. // appDelegate.allowRotation = NO;
  93. // //切换到竖屏
  94. // [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait];
  95. //
  96. // [self.chartVC dismissViewControllerAnimated:YES completion:nil];
  97. //
  98. // }
  99. }
  100. #pragma mark -- 旋转屏设置
  101. -(void)viewWillAppear:(BOOL)animated{
  102. [super viewWillAppear:animated];
  103. self.navigationController.navigationBar.hidden = YES;
  104. AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  105. //允许转成横屏
  106. appDelegate.allowRotation = YES;
  107. }
  108. -(void)viewDidDisappear:(BOOL)animated{
  109. [super viewDidDisappear:animated];
  110. AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
  111. //允许转成横屏
  112. appDelegate.allowRotation = NO;
  113. }
  114. -(void)dealloc{
  115. [[NSNotificationCenter defaultCenter] removeObserver:self name:@"YRReactNativeBridgeInited" object:nil];
  116. }
  117. @end