react-native-navigation的迁移库

RCCViewController.m 22KB

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