123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- //
- // RNNViewController.m
- // ReactNativeNavigation
- //
- // Created by Ran Greenberg on 21/12/2016.
- // Copyright © 2016 artal. All rights reserved.
- //
-
- #import "RNNViewController.h"
- #import "RCTRootView.h"
- #import "MMDrawerController.h"
-
- #define SCREEN @"screen"
- #define SIDE_MENU @"sideMenu"
- #define TABS @"tabs"
- #define SCREEN_KEY @"key"
- #define SIDE_MENU_LEFT @"left"
- #define SIDE_MENU_RIGHT @"right"
-
-
- @interface RNNViewController ()
- @end
-
-
- @implementation RNNViewController
-
-
- #pragma mark - Static function
-
-
- + (UIViewController*)controllerWithLayout:(NSDictionary *)layout bridge:(RCTBridge *)bridge {
-
- UIViewController *controller = nil;
- NSDictionary *screen = layout[SCREEN];
- NSArray *tabs = layout[TABS];
- NSDictionary *sideMenu = layout[SIDE_MENU];
-
- if (sideMenu) {
- NSDictionary *centerScreenDictionary;
- if (screen) {
- centerScreenDictionary = @{SCREEN: screen};
- }
- else if (tabs){
- centerScreenDictionary = @{TABS: layout[TABS]};
- }
- else {
- return nil;
- }
-
- UIViewController *centerViewController = [RNNViewController controllerWithLayout:centerScreenDictionary bridge:bridge];
- controller = [RNNViewController sideMenuWithLayout:sideMenu centerViewController:centerViewController bridge:bridge];
-
- return controller;
- }
-
- if (tabs) {
- controller = [RNNViewController tabBarWithTabsArray:tabs bridge:bridge];
- return controller;
- }
-
- if (screen) {
- NSString *screenKey = screen[SCREEN_KEY];
- if (screenKey) {
- controller = [RNNViewController navigationControllerWithScreenKey:screenKey bridge:bridge];
- }
-
- return controller;
- }
-
- return controller;
- }
-
-
- +(UIViewController*)controllerWithScreenKey:(NSString*)screenKey bridge:(RCTBridge *)bridge {
-
- UIViewController *controller = nil;
-
- RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:bridge moduleName:screenKey initialProperties:nil];
- if (!reactView) return nil;
-
- controller = [UIViewController new];
- controller.view = reactView;
-
- return controller;
- }
-
-
- +(UINavigationController*)navigationControllerWithScreenKey:(NSString*)screenKey bridge:(RCTBridge*)bridge {
-
- UINavigationController *controller = nil;
-
- UIViewController *viewController = [RNNViewController controllerWithScreenKey:screenKey bridge:bridge];
- if (!viewController) return nil;
-
- controller = [[UINavigationController alloc] initWithRootViewController:viewController];
- [controller.tabBarItem setTitle:@"tab"];
-
- return controller;
- }
-
-
- +(UIViewController*)sideMenuWithLayout:(NSDictionary*)layout centerViewController:(UIViewController*)centerViewController bridge:(RCTBridge*)bridge {
-
- UIViewController *leftViewController, *rightViewController, *sideMenuViewController = nil;
-
- NSDictionary *left = layout[SIDE_MENU_LEFT];
- if (left) {
- NSString *leftScreenKey = left[SCREEN_KEY];
- leftViewController = [RNNViewController controllerWithScreenKey:leftScreenKey bridge:bridge];
- }
-
- NSDictionary *right = layout[SIDE_MENU_RIGHT];
- if (right) {
- NSString *rightScreenKey = right[SCREEN_KEY];
- rightViewController = [RNNViewController controllerWithScreenKey:rightScreenKey bridge:bridge];
- }
-
- if (rightViewController || leftViewController) {
- sideMenuViewController = [[MMDrawerController alloc] initWithCenterViewController:centerViewController leftDrawerViewController:leftViewController rightDrawerViewController:rightViewController];
-
- // TODO: CHANGE THIS
- ((MMDrawerController*)sideMenuViewController).openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
- ((MMDrawerController*)sideMenuViewController).closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
- }
-
- return sideMenuViewController;
- }
-
- +(UITabBarController*)tabBarWithTabsArray:(NSArray*)tabsArray bridge:(RCTBridge*)bridge {
-
- UITabBarController *tabBarController = nil;
- NSMutableArray *tabsViewControllersArray = [[NSMutableArray alloc] init];
-
- for (NSDictionary *tab in tabsArray) {
- UIViewController *tabViewController = [RNNViewController controllerWithLayout:tab bridge:bridge];
- if (tabViewController) {
- [tabsViewControllersArray addObject:tabViewController];
- }
- }
- if ([tabsViewControllersArray count] > 0) {
- tabBarController = [UITabBarController new];
- tabBarController.viewControllers = tabsViewControllersArray;
- }
-
- return tabBarController;
- }
-
- -(void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- }
-
-
-
-
-
- @end
-
|