react-native-navigation的迁移库

RCCViewController.m 25KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. #import "RCCViewController.h"
  2. #import "RCCNavigationController.h"
  3. #import "RCCTabBarController.h"
  4. #import "RCCDrawerController.h"
  5. #import "RCCTheSideBarManagerViewController.h"
  6. #import "RCTRootView.h"
  7. #import "RCCManager.h"
  8. #import "RCTConvert.h"
  9. #import "RCCExternalViewControllerProtocol.h"
  10. #import "RCTHelpers.h"
  11. #import "RCCTitleViewHelper.h"
  12. NSString* const RCCViewControllerCancelReactTouchesNotification = @"RCCViewControllerCancelReactTouchesNotification";
  13. const NSInteger BLUR_STATUS_TAG = 78264801;
  14. const NSInteger BLUR_NAVBAR_TAG = 78264802;
  15. const NSInteger TRANSPARENT_NAVBAR_TAG = 78264803;
  16. @interface RCCViewController() <UIGestureRecognizerDelegate>
  17. @property (nonatomic) BOOL _hidesBottomBarWhenPushed;
  18. @property (nonatomic) BOOL _statusBarHideWithNavBar;
  19. @property (nonatomic) BOOL _statusBarHidden;
  20. @property (nonatomic) BOOL _statusBarTextColorSchemeLight;
  21. @property (nonatomic, strong) NSDictionary *originalNavBarImages;
  22. @property (nonatomic, strong) UIImageView *navBarHairlineImageView;
  23. @property (nonatomic, weak) id <UIGestureRecognizerDelegate> originalInteractivePopGestureDelegate;
  24. @end
  25. @implementation RCCViewController
  26. -(UIImageView *)navBarHairlineImageView {
  27. if (!_navBarHairlineImageView) {
  28. _navBarHairlineImageView = [self findHairlineImageViewUnder:self.navigationController.navigationBar];
  29. }
  30. return _navBarHairlineImageView;
  31. }
  32. + (UIViewController*)controllerWithLayout:(NSDictionary *)layout globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge
  33. {
  34. UIViewController* controller = nil;
  35. if (!layout) return nil;
  36. // get props
  37. if (!layout[@"props"]) return nil;
  38. if (![layout[@"props"] isKindOfClass:[NSDictionary class]]) return nil;
  39. NSDictionary *props = layout[@"props"];
  40. // get children
  41. if (!layout[@"children"]) return nil;
  42. if (![layout[@"children"] isKindOfClass:[NSArray class]]) return nil;
  43. NSArray *children = layout[@"children"];
  44. // create according to type
  45. NSString *type = layout[@"type"];
  46. if (!type) return nil;
  47. // regular view controller
  48. if ([type isEqualToString:@"ViewControllerIOS"])
  49. {
  50. controller = [[RCCViewController alloc] initWithProps:props children:children globalProps:globalProps bridge:bridge];
  51. }
  52. // navigation controller
  53. if ([type isEqualToString:@"NavigationControllerIOS"])
  54. {
  55. controller = [[RCCNavigationController alloc] initWithProps:props children:children globalProps:globalProps bridge:bridge];
  56. }
  57. // tab bar controller
  58. if ([type isEqualToString:@"TabBarControllerIOS"])
  59. {
  60. controller = [[RCCTabBarController alloc] initWithProps:props children:children globalProps:globalProps bridge:bridge];
  61. }
  62. // side menu controller
  63. if ([type isEqualToString:@"DrawerControllerIOS"])
  64. {
  65. NSString *drawerType = props[@"type"];
  66. if ([drawerType isEqualToString:@"TheSideBar"]) {
  67. controller = [[RCCTheSideBarManagerViewController alloc] initWithProps:props children:children globalProps:globalProps bridge:bridge];
  68. }
  69. else {
  70. controller = [[RCCDrawerController alloc] initWithProps:props children:children globalProps:globalProps bridge:bridge];
  71. }
  72. }
  73. // register the controller if we have an id
  74. NSString *componentId = props[@"id"];
  75. if (controller && componentId)
  76. {
  77. [[RCCManager sharedInstance] registerController:controller componentId:componentId componentType:type];
  78. }
  79. return controller;
  80. }
  81. - (instancetype)initWithProps:(NSDictionary *)props children:(NSArray *)children globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge
  82. {
  83. NSString *component = props[@"component"];
  84. if (!component) return nil;
  85. NSDictionary *passProps = props[@"passProps"];
  86. NSDictionary *navigatorStyle = props[@"style"];
  87. NSMutableDictionary *mergedProps = [NSMutableDictionary dictionaryWithDictionary:globalProps];
  88. [mergedProps addEntriesFromDictionary:passProps];
  89. RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:component initialProperties:mergedProps];
  90. if (!reactView) return nil;
  91. self = [super init];
  92. if (!self) return nil;
  93. [self commonInit:reactView navigatorStyle:navigatorStyle props:props];
  94. return self;
  95. }
  96. - (instancetype)initWithComponent:(NSString *)component passProps:(NSDictionary *)passProps navigatorStyle:(NSDictionary*)navigatorStyle globalProps:(NSDictionary *)globalProps bridge:(RCTBridge *)bridge
  97. {
  98. NSMutableDictionary *mergedProps = [NSMutableDictionary dictionaryWithDictionary:globalProps];
  99. [mergedProps addEntriesFromDictionary:passProps];
  100. RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:component initialProperties:mergedProps];
  101. if (!reactView) return nil;
  102. self = [super init];
  103. if (!self) return nil;
  104. [self commonInit:reactView navigatorStyle:navigatorStyle props:passProps];
  105. return self;
  106. }
  107. - (void)commonInit:(RCTRootView*)reactView navigatorStyle:(NSDictionary*)navigatorStyle props:(NSDictionary*)props
  108. {
  109. self.view = reactView;
  110. self.edgesForExtendedLayout = UIRectEdgeNone; // default
  111. self.automaticallyAdjustsScrollViewInsets = NO; // default
  112. self.navigatorStyle = [NSMutableDictionary dictionaryWithDictionary:navigatorStyle];
  113. [self setStyleOnInit];
  114. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onRNReload) name:RCTReloadNotification object:nil];
  115. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onCancelReactTouches) name:RCCViewControllerCancelReactTouchesNotification object:nil];
  116. // In order to support 3rd party native ViewControllers, we support passing a class name as a prop mamed `ExternalNativeScreenClass`
  117. // In this case, we create an instance and add it as a child ViewController which preserves the VC lifecycle.
  118. // In case some props are necessary in the native ViewController, the ExternalNativeScreenProps can be used to pass them
  119. [self addExternalVCIfNecessary:props];
  120. }
  121. - (void)dealloc
  122. {
  123. [[NSNotificationCenter defaultCenter] removeObserver:self];
  124. self.view = nil;
  125. }
  126. -(void)onRNReload
  127. {
  128. [[NSNotificationCenter defaultCenter] removeObserver:self];
  129. self.view = nil;
  130. }
  131. -(void)onCancelReactTouches
  132. {
  133. if ([self.view isKindOfClass:[RCTRootView class]]){
  134. [(RCTRootView*)self.view cancelTouches];
  135. }
  136. }
  137. - (void)viewWillAppear:(BOOL)animated
  138. {
  139. [super viewWillAppear:animated];
  140. [self setStyleOnAppear];
  141. }
  142. - (void)viewWillDisappear:(BOOL)animated
  143. {
  144. [super viewWillDisappear:animated];
  145. [self setStyleOnDisappear];
  146. }
  147. // most styles should be set here since when we pop a view controller that changed them
  148. // we want to reset the style to what we expect (so we need to reset on every willAppear)
  149. - (void)setStyleOnAppear
  150. {
  151. [self setStyleOnAppearForViewController:self appeared:false];
  152. }
  153. - (void)updateStyle
  154. {
  155. [self setStyleOnAppearForViewController:self appeared:true];
  156. }
  157. -(void)setStyleOnAppearForViewController:(UIViewController*)viewController appeared:(BOOL)appeared
  158. {
  159. NSString *screenBackgroundColor = self.navigatorStyle[@"screenBackgroundColor"];
  160. if (screenBackgroundColor) {
  161. UIColor *color = screenBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:screenBackgroundColor] : nil;
  162. viewController.view.backgroundColor = color;
  163. }
  164. NSString *navBarBackgroundColor = self.navigatorStyle[@"navBarBackgroundColor"];
  165. if (navBarBackgroundColor) {
  166. UIColor *color = navBarBackgroundColor != (id)[NSNull null] ? [RCTConvert UIColor:navBarBackgroundColor] : nil;
  167. viewController.navigationController.navigationBar.barTintColor = color;
  168. } else {
  169. viewController.navigationController.navigationBar.barTintColor = nil;
  170. }
  171. NSMutableDictionary *titleTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"navBarText" baseFont:[UIFont boldSystemFontOfSize:17]];
  172. [self.navigationController.navigationBar setTitleTextAttributes:titleTextAttributes];
  173. if (self.navigationItem.titleView && [self.navigationItem.titleView isKindOfClass:[RCCTitleView class]]) {
  174. RCCTitleView *titleView = (RCCTitleView *)self.navigationItem.titleView;
  175. RCCTitleViewHelper *helper = [[RCCTitleViewHelper alloc] init:viewController navigationController:viewController.navigationController title:titleView.titleLabel.text subtitle:titleView.subtitleLabel.text titleImageData:nil];
  176. [helper setup:self.navigatorStyle];
  177. }
  178. NSMutableDictionary *navButtonTextAttributes = [RCTHelpers textAttributesFromDictionary:self.navigatorStyle withPrefix:@"navBarButton"];
  179. if (navButtonTextAttributes.allKeys.count > 0) {
  180. for (UIBarButtonItem *item in viewController.navigationItem.leftBarButtonItems) {
  181. [item setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
  182. }
  183. for (UIBarButtonItem *item in viewController.navigationItem.rightBarButtonItems) {
  184. [item setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
  185. }
  186. // At the moment, this seems to be the only thing that gets the back button correctly
  187. [navButtonTextAttributes removeObjectForKey:NSForegroundColorAttributeName];
  188. [[UIBarButtonItem appearance] setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
  189. // [viewController.navigationItem.backBarButtonItem setTitleTextAttributes:navButtonTextAttributes forState:UIControlStateNormal];
  190. }
  191. NSString *navBarButtonColor = self.navigatorStyle[@"navBarButtonColor"];
  192. if (navBarButtonColor) {
  193. UIColor *color = navBarButtonColor != (id)[NSNull null] ? [RCTConvert UIColor:navBarButtonColor] : nil;
  194. viewController.navigationController.navigationBar.tintColor = color;
  195. } else
  196. {
  197. viewController.navigationController.navigationBar.tintColor = nil;
  198. }
  199. BOOL viewControllerBasedStatusBar = false;
  200. NSObject *viewControllerBasedStatusBarAppearance = [[NSBundle mainBundle] infoDictionary][@"UIViewControllerBasedStatusBarAppearance"];
  201. if (viewControllerBasedStatusBarAppearance && [viewControllerBasedStatusBarAppearance isKindOfClass:[NSNumber class]]) {
  202. viewControllerBasedStatusBar = [(NSNumber *)viewControllerBasedStatusBarAppearance boolValue];
  203. }
  204. NSString *statusBarTextColorSchemeSingleScreen = self.navigatorStyle[@"statusBarTextColorSchemeSingleScreen"];
  205. NSString *statusBarTextColorScheme = self.navigatorStyle[@"statusBarTextColorScheme"];
  206. NSString *finalColorScheme = statusBarTextColorSchemeSingleScreen ? : statusBarTextColorScheme;
  207. if (finalColorScheme && [finalColorScheme isEqualToString:@"light"]) {
  208. if (!statusBarTextColorSchemeSingleScreen) {
  209. viewController.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  210. }
  211. self._statusBarTextColorSchemeLight = true;
  212. if (!viewControllerBasedStatusBarAppearance) {
  213. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
  214. }
  215. [viewController setNeedsStatusBarAppearanceUpdate];
  216. } else {
  217. if (!statusBarTextColorSchemeSingleScreen) {
  218. viewController.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  219. }
  220. self._statusBarTextColorSchemeLight = false;
  221. if (!viewControllerBasedStatusBarAppearance) {
  222. [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault];
  223. }
  224. [viewController setNeedsStatusBarAppearanceUpdate];
  225. }
  226. NSNumber *navBarHidden = self.navigatorStyle[@"navBarHidden"];
  227. BOOL navBarHiddenBool = navBarHidden ? [navBarHidden boolValue] : NO;
  228. if (viewController.navigationController.navigationBarHidden != navBarHiddenBool) {
  229. [viewController.navigationController setNavigationBarHidden:navBarHiddenBool animated:YES];
  230. }
  231. NSNumber *navBarHideOnScroll = self.navigatorStyle[@"navBarHideOnScroll"];
  232. BOOL navBarHideOnScrollBool = navBarHideOnScroll ? [navBarHideOnScroll boolValue] : NO;
  233. if (navBarHideOnScrollBool) {
  234. viewController.navigationController.hidesBarsOnSwipe = YES;
  235. } else {
  236. viewController.navigationController.hidesBarsOnSwipe = NO;
  237. }
  238. NSNumber *statusBarBlur = self.navigatorStyle[@"statusBarBlur"];
  239. BOOL statusBarBlurBool = statusBarBlur ? [statusBarBlur boolValue] : NO;
  240. if (statusBarBlurBool && ![viewController.view viewWithTag:BLUR_STATUS_TAG]) {
  241. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  242. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  243. blur.tag = BLUR_STATUS_TAG;
  244. [viewController.view insertSubview:blur atIndex:0];
  245. }
  246. NSNumber *navBarBlur = self.navigatorStyle[@"navBarBlur"];
  247. BOOL navBarBlurBool = navBarBlur ? [navBarBlur boolValue] : NO;
  248. if (navBarBlurBool) {
  249. if (![viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG]) {
  250. [self storeOriginalNavBarImages];
  251. [viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  252. viewController.navigationController.navigationBar.shadowImage = [UIImage new];
  253. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  254. CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
  255. blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, viewController.navigationController.navigationBar.frame.size.width, viewController.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
  256. blur.userInteractionEnabled = NO;
  257. blur.tag = BLUR_NAVBAR_TAG;
  258. [viewController.navigationController.navigationBar insertSubview:blur atIndex:0];
  259. [viewController.navigationController.navigationBar sendSubviewToBack:blur];
  260. }
  261. } else {
  262. UIView *blur = [viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG];
  263. if (blur) {
  264. [blur removeFromSuperview];
  265. [viewController.navigationController.navigationBar setBackgroundImage:self.originalNavBarImages[@"bgImage"] forBarMetrics:UIBarMetricsDefault];
  266. viewController.navigationController.navigationBar.shadowImage = self.originalNavBarImages[@"shadowImage"];
  267. self.originalNavBarImages = nil;
  268. }
  269. }
  270. NSNumber *navBarTransparent = self.navigatorStyle[@"navBarTransparent"];
  271. BOOL navBarTransparentBool = navBarTransparent ? [navBarTransparent boolValue] : NO;
  272. void (^action)() = ^ {
  273. if (navBarTransparentBool)
  274. {
  275. if (![viewController.navigationController.navigationBar viewWithTag:TRANSPARENT_NAVBAR_TAG])
  276. {
  277. [self storeOriginalNavBarImages];
  278. [viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  279. viewController.navigationController.navigationBar.shadowImage = [UIImage new];
  280. UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
  281. transparentView.tag = TRANSPARENT_NAVBAR_TAG;
  282. [viewController.navigationController.navigationBar insertSubview:transparentView atIndex:0];
  283. }
  284. }
  285. else
  286. {
  287. UIView *transparentView = [viewController.navigationController.navigationBar viewWithTag:TRANSPARENT_NAVBAR_TAG];
  288. if (transparentView)
  289. {
  290. [transparentView removeFromSuperview];
  291. [viewController.navigationController.navigationBar setBackgroundImage:self.originalNavBarImages[@"bgImage"] forBarMetrics:UIBarMetricsDefault];
  292. viewController.navigationController.navigationBar.shadowImage = self.originalNavBarImages[@"shadowImage"];
  293. self.originalNavBarImages = nil;
  294. }
  295. }
  296. };
  297. if (!self.transitionCoordinator || self.transitionCoordinator.initiallyInteractive || !navBarTransparentBool || appeared) {
  298. action();
  299. } else {
  300. UIView* backgroundView = [self.navigationController.navigationBar valueForKey:@"backgroundView"];
  301. CGFloat originalAlpha = backgroundView.alpha;
  302. backgroundView.alpha = navBarTransparentBool ? 0.0 : 1.0;
  303. [self.transitionCoordinator animateAlongsideTransition:nil completion:^(id<UIViewControllerTransitionCoordinatorContext> _Nonnull context) {
  304. action();
  305. backgroundView.alpha = originalAlpha;
  306. }];
  307. }
  308. NSNumber *autoAdjustsScrollViewInsets = self.navigatorStyle[@"autoAdjustScrollViewInsets"];
  309. viewController.automaticallyAdjustsScrollViewInsets = autoAdjustsScrollViewInsets ? [autoAdjustsScrollViewInsets boolValue] : false;
  310. NSNumber *navBarTranslucent = self.navigatorStyle[@"navBarTranslucent"];
  311. BOOL navBarTranslucentBool = navBarTranslucent ? [navBarTranslucent boolValue] : NO;
  312. if (navBarTranslucentBool || navBarBlurBool) {
  313. viewController.navigationController.navigationBar.translucent = YES;
  314. } else {
  315. viewController.navigationController.navigationBar.translucent = NO;
  316. }
  317. NSNumber *extendedLayoutIncludesOpaqueBars = self.navigatorStyle[@"extendedLayoutIncludesOpaqueBars"];
  318. BOOL extendedLayoutIncludesOpaqueBarsBool = extendedLayoutIncludesOpaqueBars ? [extendedLayoutIncludesOpaqueBars boolValue] : NO;
  319. viewController.extendedLayoutIncludesOpaqueBars = extendedLayoutIncludesOpaqueBarsBool;
  320. NSNumber *drawUnderNavBar = self.navigatorStyle[@"drawUnderNavBar"];
  321. BOOL drawUnderNavBarBool = drawUnderNavBar ? [drawUnderNavBar boolValue] : NO;
  322. if (drawUnderNavBarBool) {
  323. viewController.edgesForExtendedLayout |= UIRectEdgeTop;
  324. }
  325. else {
  326. viewController.edgesForExtendedLayout &= ~UIRectEdgeTop;
  327. }
  328. NSNumber *drawUnderTabBar = self.navigatorStyle[@"drawUnderTabBar"];
  329. BOOL drawUnderTabBarBool = drawUnderTabBar ? [drawUnderTabBar boolValue] : NO;
  330. if (drawUnderTabBarBool) {
  331. viewController.edgesForExtendedLayout |= UIRectEdgeBottom;
  332. } else {
  333. viewController.edgesForExtendedLayout &= ~UIRectEdgeBottom;
  334. }
  335. NSNumber *removeNavBarBorder = self.navigatorStyle[@"navBarNoBorder"];
  336. BOOL removeNavBarBorderBool = removeNavBarBorder ? [removeNavBarBorder boolValue] : NO;
  337. if (removeNavBarBorderBool) {
  338. self.navBarHairlineImageView.hidden = YES;
  339. } else {
  340. self.navBarHairlineImageView.hidden = NO;
  341. }
  342. //Bug fix: in case there is a interactivePopGestureRecognizer, it prevents react-native from getting touch events on the left screen area that the gesture handles
  343. //overriding the delegate of the gesture prevents this from happening while keeping the gesture intact (another option was to disable it completely by demand)
  344. self.originalInteractivePopGestureDelegate = nil;
  345. if (self.navigationController != nil && self.navigationController.interactivePopGestureRecognizer != nil)
  346. {
  347. id <UIGestureRecognizerDelegate> interactivePopGestureRecognizer = self.navigationController.interactivePopGestureRecognizer.delegate;
  348. if (interactivePopGestureRecognizer != nil)
  349. {
  350. self.originalInteractivePopGestureDelegate = interactivePopGestureRecognizer;
  351. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  352. }
  353. }
  354. }
  355. -(void)storeOriginalNavBarImages {
  356. NSMutableDictionary *originalNavBarImages = [@{} mutableCopy];
  357. UIImage *bgImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
  358. if (bgImage != nil) {
  359. originalNavBarImages[@"bgImage"] = bgImage;
  360. }
  361. UIImage *shadowImage = self.navigationController.navigationBar.shadowImage;
  362. if (shadowImage != nil) {
  363. originalNavBarImages[@"shadowImage"] = shadowImage;
  364. }
  365. self.originalNavBarImages = originalNavBarImages;
  366. }
  367. -(void)setStyleOnDisappear
  368. {
  369. self.navBarHairlineImageView.hidden = NO;
  370. if (self.navigationController != nil && self.navigationController.interactivePopGestureRecognizer != nil && self.originalInteractivePopGestureDelegate != nil)
  371. {
  372. self.navigationController.interactivePopGestureRecognizer.delegate = self.originalInteractivePopGestureDelegate;
  373. self.originalInteractivePopGestureDelegate = nil;
  374. }
  375. }
  376. // only styles that can't be set on willAppear should be set here
  377. - (void)setStyleOnInit
  378. {
  379. NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"];
  380. BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO;
  381. if (tabBarHiddenBool) {
  382. self._hidesBottomBarWhenPushed = YES;
  383. } else {
  384. self._hidesBottomBarWhenPushed = NO;
  385. }
  386. NSNumber *statusBarHideWithNavBar = self.navigatorStyle[@"statusBarHideWithNavBar"];
  387. BOOL statusBarHideWithNavBarBool = statusBarHideWithNavBar ? [statusBarHideWithNavBar boolValue] : NO;
  388. if (statusBarHideWithNavBarBool) {
  389. self._statusBarHideWithNavBar = YES;
  390. } else {
  391. self._statusBarHideWithNavBar = NO;
  392. }
  393. NSNumber *statusBarHidden = self.navigatorStyle[@"statusBarHidden"];
  394. BOOL statusBarHiddenBool = statusBarHidden ? [statusBarHidden boolValue] : NO;
  395. if (statusBarHiddenBool) {
  396. self._statusBarHidden = YES;
  397. } else {
  398. self._statusBarHidden = NO;
  399. }
  400. }
  401. - (BOOL)hidesBottomBarWhenPushed
  402. {
  403. if (!self._hidesBottomBarWhenPushed) return NO;
  404. return (self.navigationController.topViewController == self);
  405. }
  406. - (BOOL)prefersStatusBarHidden
  407. {
  408. if (self._statusBarHidden) {
  409. return YES;
  410. }
  411. if (self._statusBarHideWithNavBar) {
  412. return self.navigationController.isNavigationBarHidden;
  413. } else {
  414. return NO;
  415. }
  416. }
  417. - (void)setNavBarVisibilityChange:(BOOL)animated {
  418. [self.navigationController setNavigationBarHidden:[self.navigatorStyle[@"navBarHidden"] boolValue] animated:animated];
  419. }
  420. - (UIStatusBarStyle)preferredStatusBarStyle
  421. {
  422. if (self._statusBarTextColorSchemeLight){
  423. return UIStatusBarStyleLightContent;
  424. } else {
  425. return UIStatusBarStyleDefault;
  426. }
  427. }
  428. - (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
  429. if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
  430. return (UIImageView *)view;
  431. }
  432. for (UIView *subview in view.subviews) {
  433. UIImageView *imageView = [self findHairlineImageViewUnder:subview];
  434. if (imageView) {
  435. return imageView;
  436. }
  437. }
  438. return nil;
  439. }
  440. -(void)addExternalVCIfNecessary:(NSDictionary*)props
  441. {
  442. NSString *externalScreenClass = props[@"externalNativeScreenClass"];
  443. if (externalScreenClass != nil)
  444. {
  445. Class class = NSClassFromString(externalScreenClass);
  446. if (class != NULL)
  447. {
  448. id obj = [[class alloc] init];
  449. if (obj != nil && [obj isKindOfClass:[UIViewController class]] && [obj conformsToProtocol:@protocol(RCCExternalViewControllerProtocol)])
  450. {
  451. ((id <RCCExternalViewControllerProtocol>)obj).controllerDelegate = self;
  452. [obj setProps:props[@"externalNativeScreenProps"]];
  453. UIViewController *viewController = (UIViewController*)obj;
  454. [self addChildViewController:viewController];
  455. viewController.view.frame = self.view.bounds;
  456. [self.view addSubview:viewController.view];
  457. [viewController didMoveToParentViewController:self];
  458. }
  459. else
  460. {
  461. NSLog(@"addExternalVCIfNecessary: could not create instance. Make sure that your class is a UIViewController whihc confirms to RCCExternalViewControllerProtocol");
  462. }
  463. }
  464. else
  465. {
  466. NSLog(@"addExternalVCIfNecessary: could not create class from string. Check that the proper class name wass passed in ExternalNativeScreenClass");
  467. }
  468. }
  469. }
  470. #pragma mark - NewRelic
  471. - (NSString*) customNewRelicInteractionName
  472. {
  473. NSString *interactionName = nil;
  474. if (self.view != nil && [self.view isKindOfClass:[RCTRootView class]])
  475. {
  476. NSString *moduleName = ((RCTRootView*)self.view).moduleName;
  477. if(moduleName != nil)
  478. {
  479. interactionName = [NSString stringWithFormat:@"RCCViewController: %@", moduleName];
  480. }
  481. }
  482. if (interactionName == nil)
  483. {
  484. interactionName = [NSString stringWithFormat:@"RCCViewController with title: %@", self.title];
  485. }
  486. return interactionName;
  487. }
  488. @end