ソースを参照

RNNRootViewProtocol refactor

yogevbd 6 年 前
コミット
0aa0f22891

+ 2
- 1
lib/ios/RNNCommandsHandler.m ファイルの表示

@@ -142,9 +142,10 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
142 142
 	[self assertReady];
143 143
 	
144 144
 	UIViewController<RNNRootViewProtocol> *newVC = [_controllerFactory createLayoutAndSaveToStore:layout];
145
+	RNNNavigationOptions* options = [newVC getLeafViewController].options;
145 146
 	UIViewController *fromVC = [_store findComponentForId:componentId];
146 147
 	__weak typeof(RNNEventEmitter*) weakEventEmitter = _eventEmitter;
147
-	[_stackManager setStackRoot:newVC fromViewController:fromVC animated:newVC.options.animations.push.enable completion:^{
148
+	[_stackManager setStackRoot:newVC fromViewController:fromVC animated:options.animations.push.enable completion:^{
148 149
 		[weakEventEmitter sendOnNavigationCommandCompletion:setStackRoot params:@{@"componentId": componentId}];
149 150
 		completion();
150 151
 	} rejection:rejection];

+ 6
- 7
lib/ios/RNNControllerFactory.m ファイルの表示

@@ -1,7 +1,6 @@
1 1
 
2 2
 #import "RNNControllerFactory.h"
3 3
 #import "RNNLayoutNode.h"
4
-#import "RNNRootViewController.h"
5 4
 #import "RNNSplitViewController.h"
6 5
 #import "RNNSplitViewOptions.h"
7 6
 #import "RNNSideMenuController.h"
@@ -104,7 +103,7 @@
104 103
 		CGSize availableSize = UIApplication.sharedApplication.delegate.window.bounds.size;
105 104
 		[_bridge.uiManager setAvailableSize:availableSize forRootView:component.view];
106 105
 	}
107
-	return component;
106
+	return (UIViewController<RNNRootViewProtocol> *)component;
108 107
 }
109 108
 
110 109
 - (UIViewController<RNNRootViewProtocol> *)createExternalComponent:(RNNLayoutNode*)node {
@@ -121,7 +120,7 @@
121 120
 	[component.view addSubview:externalVC.view];
122 121
 	[externalVC didMoveToParentViewController:component];
123 122
 	
124
-	return component;
123
+	return (UIViewController<RNNRootViewProtocol> *)component;
125 124
 }
126 125
 
127 126
 
@@ -134,7 +133,7 @@
134 133
 		[controllers addObject:[self fromTree:child]];
135 134
 	}
136 135
 	[vc setViewControllers:controllers];
137
-	[vc mergeOptions:options];
136
+	[vc.getLeafViewController mergeOptions:options];
138 137
 	
139 138
 	return vc;
140 139
 }
@@ -152,7 +151,7 @@
152 151
 		[controllers addObject:childVc];
153 152
 	}
154 153
 	[vc setViewControllers:controllers];
155
-	[vc mergeOptions:options];
154
+	[vc.getLeafViewController mergeOptions:options];
156 155
 	
157 156
 	return vc;
158 157
 }
@@ -163,7 +162,7 @@
163 162
 	NSMutableArray* controllers = [NSMutableArray new];
164 163
 	for (NSDictionary *child in node.children) {
165 164
 		RNNRootViewController* childVc = (RNNRootViewController*)[self fromTree:child];
166
-		childVc.topTabsViewController = vc;
165
+//		childVc.topTabsViewController = vc;
167 166
 		[controllers addObject:childVc];
168 167
 		[_bridge.uiManager setAvailableSize:vc.contentView.bounds.size forRootView:childVc.view];
169 168
 	}
@@ -181,7 +180,7 @@
181 180
 		[childrenVCs addObject:vc];
182 181
 	}
183 182
 	RNNSideMenuController *sideMenu = [[RNNSideMenuController alloc] initWithControllers:childrenVCs];
184
-	[sideMenu mergeOptions:[self createOptions:node.data[@"options"]]];
183
+	[sideMenu.getLeafViewController mergeOptions:[self createOptions:node.data[@"options"]]];
185 184
 	return sideMenu;
186 185
 }
187 186
 

+ 13
- 10
lib/ios/RNNModalManager.m ファイルの表示

@@ -14,14 +14,15 @@
14 14
 }
15 15
 
16 16
 -(void)showModalAfterLoad:(NSDictionary*)notif {
17
-	RNNRootViewController *topVC = (RNNRootViewController*)[self topPresentedVC];
17
+	UIViewController<RNNRootViewProtocol>* topVC = (UIViewController<RNNRootViewProtocol>*)[self topPresentedVC];
18 18
 	topVC.definesPresentationContext = YES;
19
-	
20
-	if (topVC.options.animations.showModal.hasCustomAnimation) {
19
+	RNNNavigationOptions* options = topVC.getLeafViewController.options;
20
+
21
+	if (options.animations.showModal.hasCustomAnimation) {
21 22
 		self.toVC.transitioningDelegate = topVC;
22 23
 	}
23 24
 	
24
-	[topVC presentViewController:self.toVC animated:self.toVC.options.animations.showModal.enable completion:^{
25
+	[topVC presentViewController:self.toVC animated:options.animations.showModal.enable completion:^{
25 26
 		if (_completionBlock) {
26 27
 			_completionBlock();
27 28
 			_completionBlock = nil;
@@ -32,18 +33,20 @@
32 33
 
33 34
 -(void)showModal:(UIViewController *)viewController completion:(RNNTransitionCompletionBlock)completion {
34 35
 	self.toVC = (UIViewController<RNNRootViewProtocol>*)viewController;
36
+	RNNNavigationOptions* options = self.toVC.getLeafViewController.options;
37
+
35 38
 	_completionBlock = completion;
36 39
 	
37 40
     if ([self.toVC respondsToSelector:@selector(applyModalOptions)]) {
38
-        [self.toVC applyModalOptions];
41
+        [self.toVC.getLeafViewController applyModalOptions];
39 42
     }
40 43
     
41 44
     if ([self.toVC respondsToSelector:@selector(isCustomViewController)] &&
42
-        [self.toVC isCustomViewController]
45
+        [self.toVC.getLeafViewController isCustomViewController]
43 46
     ) {
44 47
 		[self showModalAfterLoad:nil];
45 48
 	} else {
46
-		[self.toVC waitForReactViewRender:self.toVC.options.animations.showModal.waitForRender perform:^{
49
+		[self.toVC.getLeafViewController waitForReactViewRender:options.animations.showModal.waitForRender perform:^{
47 50
 			[self showModalAfterLoad:nil];
48 51
 		}];
49 52
 	}
@@ -65,8 +68,8 @@
65 68
 
66 69
 -(void)removePendingNextModalIfOnTop {
67 70
 	NSString *componentId = [[_store pendingModalIdsToDismiss] lastObject];
68
-
69 71
 	UIViewController<RNNRootViewProtocol> *modalToDismiss = (UIViewController<RNNRootViewProtocol>*)[_store findComponentForId:componentId];
72
+	RNNNavigationOptions* options = modalToDismiss.getLeafViewController.options;
70 73
 
71 74
 	if(!modalToDismiss) {
72 75
 		return;
@@ -74,12 +77,12 @@
74 77
 
75 78
 	UIViewController* topPresentedVC = [self topPresentedVC];
76 79
 
77
-	if ([modalToDismiss.options.animations.showModal hasCustomAnimation]) {
80
+	if ([options.animations.showModal hasCustomAnimation]) {
78 81
 		modalToDismiss.transitioningDelegate = modalToDismiss;
79 82
 	}
80 83
 
81 84
 	if (modalToDismiss == topPresentedVC || [[topPresentedVC childViewControllers] containsObject:modalToDismiss]) {
82
-		[modalToDismiss dismissViewControllerAnimated:modalToDismiss.options.animations.dismissModal.enable completion:^{
85
+		[modalToDismiss dismissViewControllerAnimated:options.animations.dismissModal.enable completion:^{
83 86
 			[[_store pendingModalIdsToDismiss] removeObject:componentId];
84 87
 			[_store removeComponent:componentId];
85 88
 			[self removePendingNextModalIfOnTop];

+ 2
- 22
lib/ios/RNNNavigationController.m ファイルの表示

@@ -12,14 +12,6 @@
12 12
 	return self;
13 13
 }
14 14
 
15
-- (BOOL)isCustomViewController {
16
-	return [self.getLeafViewController isCustomViewController];
17
-}
18
-
19
-- (void)mergeOptions:(RNNOptions *)options {
20
-	[self.getLeafViewController mergeOptions:options];
21
-}
22
-
23 15
 - (UIStatusBarStyle)preferredStatusBarStyle {
24 16
 	return self.getLeafViewController.preferredStatusBarStyle;
25 17
 }
@@ -28,10 +20,6 @@
28 20
 	return self.getLeafViewController.modalPresentationStyle;
29 21
 }
30 22
 
31
-- (void)applyModalOptions {
32
-	[self.getLeafViewController applyModalOptions];
33
-}
34
-
35 23
 - (UIViewController *)popViewControllerAnimated:(BOOL)animated {
36 24
 	return [super popViewControllerAnimated:animated];
37 25
 }
@@ -41,25 +29,17 @@
41 29
 }
42 30
 
43 31
 - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
44
-	return [[RNNModalAnimation alloc] initWithScreenTransition:self.options.animations.showModal isDismiss:NO];
32
+	return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.showModal isDismiss:NO];
45 33
 }
46 34
 
47 35
 - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed {
48
-	return [[RNNModalAnimation alloc] initWithScreenTransition:self.options.animations.dismissModal isDismiss:YES];
49
-}
50
-
51
-- (RNNNavigationOptions *)options {
52
-	return self.getLeafViewController.options;
36
+	return [[RNNModalAnimation alloc] initWithScreenTransition:self.getLeafViewController.options.animations.dismissModal isDismiss:YES];
53 37
 }
54 38
 
55 39
 - (UIViewController *)getLeafViewController {
56 40
 	return ((UIViewController<RNNRootViewProtocol>*)self.topViewController);
57 41
 }
58 42
 
59
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
60
-	[self.getLeafViewController waitForReactViewRender:wait perform:readyBlock];
61
-}
62
-
63 43
 - (UIViewController *)childViewControllerForStatusBarStyle {
64 44
 	return self.topViewController;
65 45
 }

+ 1
- 1
lib/ios/RNNNavigationOptions.m ファイルの表示

@@ -54,7 +54,7 @@ RCT_ENUM_CONVERTER(UIModalTransitionStyle,
54 54
 	[self.layout applyOn:viewController];
55 55
 	[self applyOtherOptionsOn:viewController];
56 56
 	
57
-	[viewController optionsUpdated];
57
+	[viewController.getLeafViewController optionsUpdated];
58 58
 }
59 59
 
60 60
 - (void)applyOtherOptionsOn:(UIViewController*)viewController {

+ 3
- 0
lib/ios/RNNOverlayManager.h ファイルの表示

@@ -1,6 +1,7 @@
1 1
 #import <Foundation/Foundation.h>
2 2
 #import <UIKit/UIKit.h>
3 3
 #import "RNNStore.h"
4
+#import "RNNOverlayWindow.h"
4 5
 
5 6
 @interface RNNOverlayManager : NSObject
6 7
 
@@ -9,4 +10,6 @@
9 10
 - (void)showOverlay:(UIViewController*)viewController completion:(RNNTransitionCompletionBlock)completion;
10 11
 - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject;
11 12
 
13
+@property (nonatomic, retain) RNNOverlayWindow *overlayWindow;
14
+
12 15
 @end

+ 11
- 9
lib/ios/RNNRootViewController.h ファイルの表示

@@ -1,4 +1,3 @@
1
-
2 1
 #import <Foundation/Foundation.h>
3 2
 #import <UIKit/UIKit.h>
4 3
 #import "RNNLayoutNode.h"
@@ -6,30 +5,33 @@
6 5
 #import "RNNEventEmitter.h"
7 6
 #import "RNNNavigationOptions.h"
8 7
 #import "RNNAnimator.h"
9
-#import "RNNTopTabsViewController.h"
10
-#import "RNNRootViewProtocol.h"
11 8
 
12
-@class RNNRootViewController;
9
+typedef void (^RNNReactViewReadyCompletionBlock)(void);
13 10
 
14
-@interface RNNRootViewController : UIViewController	<RNNRootViewProtocol, UIViewControllerPreviewingDelegate, UISearchResultsUpdating, UISearchBarDelegate>
11
+@interface RNNRootViewController : UIViewController	<UIViewControllerPreviewingDelegate, UISearchResultsUpdating, UISearchBarDelegate, UINavigationControllerDelegate, UISplitViewControllerDelegate>
15 12
 
16 13
 @property (nonatomic, strong) RNNNavigationOptions* options;
17 14
 @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
18 15
 @property (nonatomic, strong) NSString* componentId;
19
-@property (nonatomic, strong) RNNTopTabsViewController* topTabsViewController;
20 16
 @property (nonatomic) id<RNNRootViewCreator> creator;
21 17
 @property (nonatomic, strong) RNNAnimator* animator;
22 18
 @property (nonatomic, strong) UIViewController* previewController;
23 19
 
24 20
 
25
--(instancetype)initWithName:(NSString*)name
21
+- (instancetype)initWithName:(NSString*)name
26 22
 				withOptions:(RNNNavigationOptions*)options
27 23
 			withComponentId:(NSString*)componentId
28 24
 			rootViewCreator:(id<RNNRootViewCreator>)creator
29 25
 			   eventEmitter:(RNNEventEmitter*)eventEmitter
30 26
 		  isExternalComponent:(BOOL)isExternalComponent;
31 27
 
32
--(void)applyTabBarItem;
33
--(void)applyTopTabsOptions;
28
+- (void)applyTabBarItem;
29
+- (void)applyTopTabsOptions;
30
+- (BOOL)isCustomViewController;
31
+- (BOOL)isCustomTransitioned;
32
+- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock;
33
+- (void)mergeOptions:(RNNOptions*)options;
34
+- (void)applyModalOptions;
35
+- (void)optionsUpdated;
34 36
 
35 37
 @end

+ 0
- 1
lib/ios/RNNRootViewController.m ファイルの表示

@@ -60,7 +60,6 @@
60 60
 -(void)viewWillAppear:(BOOL)animated{
61 61
 	[super viewWillAppear:animated];
62 62
 	[self.options applyOn:self];
63
-	[self optionsUpdated];
64 63
 }
65 64
 
66 65
 -(void)viewDidAppear:(BOOL)animated {

+ 3
- 10
lib/ios/RNNRootViewProtocol.h ファイルの表示

@@ -1,21 +1,14 @@
1 1
 #import "RNNNavigationOptions.h"
2
-typedef void (^RNNReactViewReadyCompletionBlock)(void);
2
+#import "RNNRootViewController.h"
3 3
 
4 4
 @protocol RNNRootViewProtocol <NSObject, UINavigationControllerDelegate, UIViewControllerTransitioningDelegate, UISplitViewControllerDelegate>
5 5
 
6 6
 @optional
7
-- (void)mergeOptions:(RNNOptions*)options;
8
-- (BOOL)isCustomViewController;
7
+
9 8
 - (void)performOnRotation:(void (^)(void))block;
10
-- (void)optionsUpdated;
11
-- (void)applyModalOptions;
12
-- (BOOL)isCustomTransitioned;
13
-- (RNNNavigationOptions*)options;
14 9
 
15 10
 @required
16
-- (NSString *)componentId;
17
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock;
18
-- (UIViewController<RNNRootViewProtocol> *)getLeafViewController;
11
+- (RNNRootViewController *)getLeafViewController;
19 12
 
20 13
 @end
21 14
 

+ 2
- 14
lib/ios/RNNSideMenuChildVC.m ファイルの表示

@@ -31,24 +31,12 @@
31 31
 	return self;
32 32
 }
33 33
 
34
-- (void)mergeOptions:(RNNOptions *)options {
35
-	[self.child mergeOptions:options];
36
-}
37
-
38
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
39
-	[self.child waitForReactViewRender:wait perform:readyBlock];
40
-}
41
-
42
-- (UIViewController *)getLeafViewController {
43
-	return self.child;
34
+- (RNNRootViewController *)getLeafViewController {
35
+	return [self.child getLeafViewController];
44 36
 }
45 37
 
46 38
 - (UIStatusBarStyle)preferredStatusBarStyle {
47 39
 	return self.child.preferredStatusBarStyle;
48 40
 }
49 41
 
50
-- (NSString *)componentId {
51
-	return _child.componentId;
52
-}
53
-
54 42
 @end

+ 3
- 11
lib/ios/RNNSideMenuController.m ファイルの表示

@@ -89,20 +89,12 @@
89 89
 	}
90 90
 }
91 91
 
92
-- (UIViewController *)getLeafViewController {
93
-	return self.center;
92
+- (RNNRootViewController *)getLeafViewController {
93
+	return [self.center getLeafViewController];
94 94
 }
95 95
 
96 96
 - (void)mergeOptions:(RNNOptions *)options {
97
-	[self.center mergeOptions:options];
98
-}
99
-
100
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
101
-	[self.center waitForReactViewRender:wait perform:readyBlock];
102
-}
103
-
104
-- (NSString *)componentId {
105
-	return _center.componentId;
97
+	[self.center.getLeafViewController mergeOptions:options];
106 98
 }
107 99
 
108 100
 @end

+ 0
- 6
lib/ios/RNNSplitViewController.m ファイルの表示

@@ -1,5 +1,3 @@
1
-
2
-#import "RNNRootViewController.h"
3 1
 #import "RNNSplitViewController.h"
4 2
 
5 3
 @interface RNNSplitViewController()
@@ -27,10 +25,6 @@
27 25
 -(void)viewWillAppear:(BOOL)animated{
28 26
 	[super viewWillAppear:animated];
29 27
 	[self.options applyOn:self];
30
-	[self optionsUpdated];
31
-}
32
-
33
-- (void)optionsUpdated {
34 28
 }
35 29
 
36 30
 - (UIViewController *)getLeafViewController {

+ 1
- 1
lib/ios/RNNStore.h ファイルの表示

@@ -1,7 +1,7 @@
1 1
 
2 2
 #import <Foundation/Foundation.h>
3 3
 #import <UIKit/UIKit.h>
4
-#import "RNNRootViewController.h"
4
+#import "RNNRootViewProtocol.h"
5 5
 #import "ReactNativeNavigation.h"
6 6
 
7 7
 typedef void (^RNNTransitionCompletionBlock)(void);

+ 1
- 1
lib/ios/RNNStore.m ファイルの表示

@@ -1,6 +1,6 @@
1 1
 
2 2
 #import "RNNStore.h"
3
-#import "RNNRootViewController.h"
3
+
4 4
 @interface RNNStore ()
5 5
 
6 6
 @end

+ 3
- 15
lib/ios/RNNTabBarController.m ファイルの表示

@@ -1,6 +1,6 @@
1 1
 
2 2
 #import "RNNTabBarController.h"
3
-#import "RNNRootViewController.h"
3
+
4 4
 #define kTabBarHiddenDuration 0.3
5 5
 
6 6
 @implementation RNNTabBarController {
@@ -42,23 +42,11 @@
42 42
 }
43 43
 
44 44
 - (void)mergeOptions:(RNNOptions *)options {
45
-	[((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) mergeOptions:options];
46
-}
47
-
48
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
49
-	[((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) waitForReactViewRender:wait perform:readyBlock];
50
-}
51
-
52
-- (RNNNavigationOptions *)options {
53
-	return [((UIViewController<RNNRootViewProtocol>*)self.selectedViewController) options];
45
+	[self.getLeafViewController mergeOptions:options];
54 46
 }
55 47
 
56 48
 - (UIViewController *)getLeafViewController {
57
-	return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController);
58
-}
59
-
60
-- (NSString *)componentId {
61
-	return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).componentId;
49
+	return ((UIViewController<RNNRootViewProtocol>*)self.selectedViewController).getLeafViewController;
62 50
 }
63 51
 
64 52
 - (UIStatusBarStyle)preferredStatusBarStyle {

+ 1
- 1
lib/ios/RNNTopTabOptions.m ファイルの表示

@@ -5,7 +5,7 @@
5 5
 
6 6
 - (void)applyOn:(RNNRootViewController*)viewController {
7 7
 	if (self.title) {
8
-		[viewController.topTabsViewController viewController:viewController changedTitle:self.title];
8
+//		[viewController.topTabsViewController viewController:viewController changedTitle:self.title];
9 9
 	}
10 10
 }
11 11
 

+ 0
- 9
lib/ios/RNNTopTabsViewController.m ファイルの表示

@@ -1,6 +1,5 @@
1 1
 #import "RNNTopTabsViewController.h"
2 2
 #import "RNNSegmentedControl.h"
3
-#import "RNNRootViewController.h"
4 3
 #import "ReactNativeNavigation.h"
5 4
 
6 5
 @interface RNNTopTabsViewController () {
@@ -72,16 +71,8 @@
72 71
     [super viewDidLoad];
73 72
 }
74 73
 
75
-- (NSString *)componentId {
76
-	return _currentViewController.componentId;
77
-}
78
-
79 74
 #pragma mark RNNRootViewProtocol
80 75
 
81
-- (void)waitForReactViewRender:(BOOL)wait perform:(RNNReactViewReadyCompletionBlock)readyBlock {
82
-	[_currentViewController waitForReactViewRender:wait perform:readyBlock];
83
-}
84
-
85 76
 - (UIViewController *)getLeafViewController {
86 77
 	return _currentViewController;
87 78
 }