react-native-navigation的迁移库

RCCViewController.m 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  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 *statusBarTextColorScheme = self.navigatorStyle[@"statusBarTextColorScheme"];
  190. if (statusBarTextColorScheme && [statusBarTextColorScheme isEqualToString:@"light"])
  191. {
  192. viewController.navigationController.navigationBar.barStyle = UIBarStyleBlack;
  193. self._statusBarTextColorSchemeLight = YES;
  194. }
  195. else
  196. {
  197. viewController.navigationController.navigationBar.barStyle = UIBarStyleDefault;
  198. self._statusBarTextColorSchemeLight = NO;
  199. }
  200. NSNumber *navBarHidden = self.navigatorStyle[@"navBarHidden"];
  201. BOOL navBarHiddenBool = navBarHidden ? [navBarHidden boolValue] : NO;
  202. if (viewController.navigationController.navigationBarHidden != navBarHiddenBool)
  203. {
  204. [viewController.navigationController setNavigationBarHidden:navBarHiddenBool animated:YES];
  205. }
  206. NSNumber *navBarHideOnScroll = self.navigatorStyle[@"navBarHideOnScroll"];
  207. BOOL navBarHideOnScrollBool = navBarHideOnScroll ? [navBarHideOnScroll boolValue] : NO;
  208. if (navBarHideOnScrollBool)
  209. {
  210. viewController.navigationController.hidesBarsOnSwipe = YES;
  211. }
  212. else
  213. {
  214. viewController.navigationController.hidesBarsOnSwipe = NO;
  215. }
  216. NSNumber *statusBarBlur = self.navigatorStyle[@"statusBarBlur"];
  217. BOOL statusBarBlurBool = statusBarBlur ? [statusBarBlur boolValue] : NO;
  218. if (statusBarBlurBool)
  219. {
  220. if (![viewController.view viewWithTag:BLUR_STATUS_TAG])
  221. {
  222. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  223. blur.frame = [[UIApplication sharedApplication] statusBarFrame];
  224. blur.tag = BLUR_STATUS_TAG;
  225. [viewController.view addSubview:blur];
  226. }
  227. }
  228. NSNumber *navBarBlur = self.navigatorStyle[@"navBarBlur"];
  229. BOOL navBarBlurBool = navBarBlur ? [navBarBlur boolValue] : NO;
  230. if (navBarBlurBool)
  231. {
  232. if (![viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG])
  233. {
  234. [self storeOriginalNavBarImages];
  235. [self.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  236. self.navigationController.navigationBar.shadowImage = [UIImage new];
  237. UIVisualEffectView *blur = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
  238. CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
  239. blur.frame = CGRectMake(0, -1 * statusBarFrame.size.height, self.navigationController.navigationBar.frame.size.width, self.navigationController.navigationBar.frame.size.height + statusBarFrame.size.height);
  240. blur.userInteractionEnabled = NO;
  241. blur.tag = BLUR_NAVBAR_TAG;
  242. [self.navigationController.navigationBar insertSubview:blur atIndex:0];
  243. }
  244. }
  245. else
  246. {
  247. UIView *blur = [viewController.navigationController.navigationBar viewWithTag:BLUR_NAVBAR_TAG];
  248. if (blur)
  249. {
  250. [blur removeFromSuperview];
  251. [viewController.navigationController.navigationBar setBackgroundImage:self.originalNavBarImages[@"bgImage"] forBarMetrics:UIBarMetricsDefault];
  252. viewController.navigationController.navigationBar.shadowImage = self.originalNavBarImages[@"shadowImage"];
  253. self.originalNavBarImages = nil;
  254. }
  255. }
  256. NSNumber *navBarTransparent = self.navigatorStyle[@"navBarTransparent"];
  257. BOOL navBarTransparentBool = navBarTransparent ? [navBarTransparent boolValue] : NO;
  258. if (navBarTransparentBool)
  259. {
  260. if (![viewController.navigationController.navigationBar viewWithTag:TRANSPARENT_NAVBAR_TAG])
  261. {
  262. [self storeOriginalNavBarImages];
  263. [viewController.navigationController.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
  264. viewController.navigationController.navigationBar.shadowImage = [UIImage new];
  265. UIView *transparentView = [[UIView alloc] initWithFrame:CGRectZero];
  266. transparentView.tag = TRANSPARENT_NAVBAR_TAG;
  267. [viewController.navigationController.navigationBar insertSubview:transparentView atIndex:0];
  268. }
  269. }
  270. else
  271. {
  272. UIView *transparentView = [viewController.navigationController.navigationBar viewWithTag:TRANSPARENT_NAVBAR_TAG];
  273. if (transparentView)
  274. {
  275. [transparentView removeFromSuperview];
  276. [viewController.navigationController.navigationBar setBackgroundImage:self.originalNavBarImages[@"bgImage"] forBarMetrics:UIBarMetricsDefault];
  277. viewController.navigationController.navigationBar.shadowImage = self.originalNavBarImages[@"shadowImage"];
  278. self.originalNavBarImages = nil;
  279. }
  280. }
  281. NSNumber *navBarTranslucent = self.navigatorStyle[@"navBarTranslucent"];
  282. BOOL navBarTranslucentBool = navBarTranslucent ? [navBarTranslucent boolValue] : NO;
  283. if (navBarTranslucentBool || navBarBlurBool)
  284. {
  285. viewController.navigationController.navigationBar.translucent = YES;
  286. }
  287. else
  288. {
  289. viewController.navigationController.navigationBar.translucent = NO;
  290. }
  291. NSNumber *drawUnderNavBar = self.navigatorStyle[@"drawUnderNavBar"];
  292. BOOL drawUnderNavBarBool = drawUnderNavBar ? [drawUnderNavBar boolValue] : NO;
  293. if (drawUnderNavBarBool)
  294. {
  295. viewController.edgesForExtendedLayout |= UIRectEdgeTop;
  296. }
  297. else
  298. {
  299. viewController.edgesForExtendedLayout &= ~UIRectEdgeTop;
  300. }
  301. NSNumber *drawUnderTabBar = self.navigatorStyle[@"drawUnderTabBar"];
  302. BOOL drawUnderTabBarBool = drawUnderTabBar ? [drawUnderTabBar boolValue] : NO;
  303. if (drawUnderTabBarBool)
  304. {
  305. viewController.edgesForExtendedLayout |= UIRectEdgeBottom;
  306. }
  307. else
  308. {
  309. viewController.edgesForExtendedLayout &= ~UIRectEdgeBottom;
  310. }
  311. NSNumber *removeNavBarBorder = self.navigatorStyle[@"navBarNoBorder"];
  312. BOOL removeNavBarBorderBool = removeNavBarBorder ? [removeNavBarBorder boolValue] : NO;
  313. if(removeNavBarBorderBool)
  314. {
  315. self.navBarHairlineImageView.hidden = YES;
  316. }
  317. else
  318. {
  319. self.navBarHairlineImageView.hidden = NO;
  320. }
  321. //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
  322. //overriding the delegate of the gesture prevents this from happening while keeping the gesture intact (another option was to disable it completely by demand)
  323. self.originalInteractivePopGestureDelegate = nil;
  324. if (self.navigationController != nil && self.navigationController.interactivePopGestureRecognizer != nil)
  325. {
  326. id <UIGestureRecognizerDelegate> interactivePopGestureRecognizer = self.navigationController.interactivePopGestureRecognizer.delegate;
  327. if (interactivePopGestureRecognizer != nil)
  328. {
  329. self.originalInteractivePopGestureDelegate = interactivePopGestureRecognizer;
  330. self.navigationController.interactivePopGestureRecognizer.delegate = self;
  331. }
  332. }
  333. }
  334. -(void)storeOriginalNavBarImages {
  335. NSMutableDictionary *originalNavBarImages = [@{} mutableCopy];
  336. UIImage *bgImage = [self.navigationController.navigationBar backgroundImageForBarMetrics:UIBarMetricsDefault];
  337. if (bgImage != nil)
  338. {
  339. originalNavBarImages[@"bgImage"] = bgImage;
  340. }
  341. UIImage *shadowImage = self.navigationController.navigationBar.shadowImage;
  342. if (shadowImage != nil)
  343. {
  344. originalNavBarImages[@"shadowImage"] = shadowImage;
  345. }
  346. self.originalNavBarImages = originalNavBarImages;
  347. }
  348. -(void)setStyleOnDisappear
  349. {
  350. self.navBarHairlineImageView.hidden = NO;
  351. if (self.navigationController != nil && self.navigationController.interactivePopGestureRecognizer != nil && self.originalInteractivePopGestureDelegate != nil)
  352. {
  353. self.navigationController.interactivePopGestureRecognizer.delegate = self.originalInteractivePopGestureDelegate;
  354. self.originalInteractivePopGestureDelegate = nil;
  355. }
  356. }
  357. // only styles that can't be set on willAppear should be set here
  358. - (void)setStyleOnInit
  359. {
  360. NSNumber *tabBarHidden = self.navigatorStyle[@"tabBarHidden"];
  361. BOOL tabBarHiddenBool = tabBarHidden ? [tabBarHidden boolValue] : NO;
  362. if (tabBarHiddenBool)
  363. {
  364. self._hidesBottomBarWhenPushed = YES;
  365. }
  366. else
  367. {
  368. self._hidesBottomBarWhenPushed = NO;
  369. }
  370. NSNumber *statusBarHideWithNavBar = self.navigatorStyle[@"statusBarHideWithNavBar"];
  371. BOOL statusBarHideWithNavBarBool = statusBarHideWithNavBar ? [statusBarHideWithNavBar boolValue] : NO;
  372. if (statusBarHideWithNavBarBool)
  373. {
  374. self._statusBarHideWithNavBar = YES;
  375. }
  376. else
  377. {
  378. self._statusBarHideWithNavBar = NO;
  379. }
  380. NSNumber *statusBarHidden = self.navigatorStyle[@"statusBarHidden"];
  381. BOOL statusBarHiddenBool = statusBarHidden ? [statusBarHidden boolValue] : NO;
  382. if (statusBarHiddenBool)
  383. {
  384. self._statusBarHidden = YES;
  385. }
  386. else
  387. {
  388. self._statusBarHidden = NO;
  389. }
  390. }
  391. - (BOOL)hidesBottomBarWhenPushed
  392. {
  393. if (!self._hidesBottomBarWhenPushed) return NO;
  394. return (self.navigationController.topViewController == self);
  395. }
  396. - (BOOL)prefersStatusBarHidden
  397. {
  398. if (self._statusBarHidden)
  399. {
  400. return YES;
  401. }
  402. if (self._statusBarHideWithNavBar)
  403. {
  404. return self.navigationController.isNavigationBarHidden;
  405. }
  406. else
  407. {
  408. return NO;
  409. }
  410. }
  411. - (void)setNavBarVisibilityChange:(BOOL)animated {
  412. [self.navigationController setNavigationBarHidden:[self.navigatorStyle[@"navBarHidden"] boolValue] animated:animated];
  413. }
  414. - (UIStatusBarStyle)preferredStatusBarStyle
  415. {
  416. if (self._statusBarTextColorSchemeLight)
  417. {
  418. return UIStatusBarStyleLightContent;
  419. }
  420. else
  421. {
  422. return UIStatusBarStyleDefault;
  423. }
  424. }
  425. - (UIImageView *)findHairlineImageViewUnder:(UIView *)view {
  426. if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
  427. return (UIImageView *)view;
  428. }
  429. for (UIView *subview in view.subviews) {
  430. UIImageView *imageView = [self findHairlineImageViewUnder:subview];
  431. if (imageView) {
  432. return imageView;
  433. }
  434. }
  435. return nil;
  436. }
  437. -(void)addExternalVCIfNecessary:(NSDictionary*)props
  438. {
  439. NSString *externalScreenClass = props[@"externalNativeScreenClass"];
  440. if (externalScreenClass != nil)
  441. {
  442. Class class = NSClassFromString(externalScreenClass);
  443. if (class != NULL)
  444. {
  445. id obj = [[class alloc] init];
  446. if (obj != nil && [obj isKindOfClass:[UIViewController class]] && [obj conformsToProtocol:@protocol(RCCExternalViewControllerProtocol)])
  447. {
  448. ((id <RCCExternalViewControllerProtocol>)obj).controllerDelegate = self;
  449. [obj setProps:props[@"externalNativeScreenProps"]];
  450. UIViewController *viewController = (UIViewController*)obj;
  451. [self addChildViewController:viewController];
  452. viewController.view.frame = self.view.bounds;
  453. [self.view addSubview:viewController.view];
  454. [viewController didMoveToParentViewController:self];
  455. }
  456. else
  457. {
  458. NSLog(@"addExternalVCIfNecessary: could not create instance. Make sure that your class is a UIViewController whihc confirms to RCCExternalViewControllerProtocol");
  459. }
  460. }
  461. else
  462. {
  463. NSLog(@"addExternalVCIfNecessary: could not create class from string. Check that the proper class name wass passed in ExternalNativeScreenClass");
  464. }
  465. }
  466. }
  467. #pragma mark - NewRelic
  468. - (NSString*) customNewRelicInteractionName
  469. {
  470. NSString *interactionName = nil;
  471. if (self.view != nil && [self.view isKindOfClass:[RCTRootView class]])
  472. {
  473. NSString *moduleName = ((RCTRootView*)self.view).moduleName;
  474. if(moduleName != nil)
  475. {
  476. interactionName = [NSString stringWithFormat:@"RCCViewController: %@", moduleName];
  477. }
  478. }
  479. if (interactionName == nil)
  480. {
  481. interactionName = [NSString stringWithFormat:@"RCCViewController with title: %@", self.title];
  482. }
  483. return interactionName;
  484. }
  485. @end