123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
-
- #import "RNNRootViewController.h"
- #import <React/RCTConvert.h>
- #import "RNNAnimator.h"
-
- @interface RNNRootViewController()
- @property (nonatomic, strong) NSString* componentName;
- @property (nonatomic) BOOL _statusBarHidden;
-
- @end
-
- @implementation RNNRootViewController
-
- -(instancetype)initWithName:(NSString*)name
- withOptions:(RNNNavigationOptions*)options
- withComponentId:(NSString*)componentId
- rootViewCreator:(id<RNNRootViewCreator>)creator
- eventEmitter:(RNNEventEmitter*)eventEmitter
- animator:(RNNAnimator *)animator {
- self = [super init];
- self.componentId = componentId;
- self.componentName = name;
- self.options = options;
- self.eventEmitter = eventEmitter;
- self.animator = animator;
- self.view = [creator createRootView:self.componentName rootViewId:self.componentId];
-
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(onJsReload)
- name:RCTJavaScriptWillStartLoadingNotification
- object:nil];
- self.navigationController.modalPresentationStyle = UIModalPresentationCustom;
- self.navigationController.delegate = self;
-
- return self;
- }
-
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:animated];
- [self.options applyOn:self];
- }
-
- - (void)viewDidLoad {
- [super viewDidLoad];
- }
-
- -(BOOL)isCustomTransitioned {
- return self.animator != nil;
- }
-
- - (BOOL)prefersStatusBarHidden {
- if ([self.options.statusBarHidden boolValue]) {
- return YES;
- } else if ([self.options.statusBarHideWithTopBar boolValue]) {
- return self.navigationController.isNavigationBarHidden;
- }
- return NO;
- }
-
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return self.options.supportedOrientations;
- }
-
- - (BOOL)hidesBottomBarWhenPushed
- {
- if (self.options.bottomTabs && self.options.bottomTabs.hidden) {
- return [self.options.bottomTabs.hidden boolValue];
- }
- return NO;
- }
-
- -(void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- [self.eventEmitter sendComponentDidAppear:self.componentId];
- }
-
- -(void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- [self.eventEmitter sendComponentDidDisappear:self.componentId];
- }
-
- - (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
- RNNRootViewController* vc = (RNNRootViewController*)viewController;
- if (![vc.options.backButtonTransition isEqualToString:@"custom"]){
- navigationController.delegate = nil;
- }
- }
-
- - (id<UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
- animationControllerForOperation:(UINavigationControllerOperation)operation
- fromViewController:(UIViewController*)fromVC
- toViewController:(UIViewController*)toVC {
- {
- if (operation == UINavigationControllerOperationPush) {
- return self.animator;
- } else if (operation == UINavigationControllerOperationPop) {
- return self.animator;
- } else {
- return nil;
- }
- }
- return nil;
-
- }
-
- -(void)applyTabBarItem {
- [self.options.bottomTab applyOn:self];
- }
-
- -(void)applyTopTabsOptions {
- [self.options.topTab applyOn:self];
- }
-
- /**
- * fix for #877, #878
- */
- -(void)onJsReload {
- [self cleanReactLeftovers];
- }
-
- /**
- * fix for #880
- */
- -(void)dealloc {
- [self cleanReactLeftovers];
- }
-
- -(void)cleanReactLeftovers {
- [[NSNotificationCenter defaultCenter] removeObserver:self];
- [[NSNotificationCenter defaultCenter] removeObserver:self.view];
- self.view = nil;
- }
-
- @end
|