Преглед изворни кода

homogenous root view container protocol (#2455)

yogevbd пре 7 година
родитељ
комит
180f1d3bb8

+ 3
- 1
lib/ios/RNNCommandsHandler.m Прегледај датотеку

@@ -56,9 +56,11 @@
56 56
 
57 57
 -(void) push:(NSString*)containerId layout:(NSDictionary*)layout completion:(RNNTransitionCompletionBlock)completion {
58 58
 	[self assertReady];
59
-	UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
59
+	
60
+	UIViewController<RNNRootViewProtocol> *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
60 61
 	UIViewController *fromVc = [_store findContainerForId:containerId];
61 62
 	[_bridge.uiManager setAvailableSize:fromVc.view.bounds.size forRootView:newVc.view];
63
+
62 64
 	[_navigationStackManager push:newVc onTop:containerId completion:completion];
63 65
 }
64 66
 

+ 2
- 1
lib/ios/RNNControllerFactory.h Прегледај датотеку

@@ -4,6 +4,7 @@
4 4
 #import "RNNRootViewCreator.h"
5 5
 #import "RNNStore.h"
6 6
 #import "RNNEventEmitter.h"
7
+#import "RNNRootViewProtocol.h"
7 8
 
8 9
 @interface RNNControllerFactory : NSObject
9 10
 
@@ -11,6 +12,6 @@
11 12
 								 store:(RNNStore*)store
12 13
 						  eventEmitter:(RNNEventEmitter*)eventEmitter;
13 14
 
14
--(UIViewController*)createLayoutAndSaveToStore:(NSDictionary*)layout;
15
+-(UIViewController<RNNRootViewProtocol> *)createLayoutAndSaveToStore:(NSDictionary*)layout;
15 16
 
16 17
 @end

+ 10
- 10
lib/ios/RNNControllerFactory.m Прегледај датотеку

@@ -29,16 +29,16 @@
29 29
 	return self;
30 30
 }
31 31
 
32
-- (UIViewController*)createLayoutAndSaveToStore:(NSDictionary*)layout {
32
+- (UIViewController<RNNRootViewProtocol> *)createLayoutAndSaveToStore:(NSDictionary*)layout {
33 33
 	return [self fromTree:layout];
34 34
 }
35 35
 
36 36
 # pragma mark private
37 37
 
38
-- (UIViewController*)fromTree:(NSDictionary*)json {
38
+- (UIViewController<RNNRootViewProtocol> *)fromTree:(NSDictionary*)json {
39 39
 	RNNLayoutNode* node = [RNNLayoutNode create:json];
40 40
 	
41
-	UIViewController* result;
41
+	UIViewController<RNNRootViewProtocol> *result;
42 42
 	
43 43
 	if ( node.isContainer) {
44 44
 		result = [self createContainer:node];
@@ -76,7 +76,7 @@
76 76
 	return result;
77 77
 }
78 78
 
79
-- (RNNRootViewController*)createContainer:(RNNLayoutNode*)node {
79
+- (UIViewController<RNNRootViewProtocol> *)createContainer:(RNNLayoutNode*)node {
80 80
 	NSString* name = node.data[@"name"];
81 81
 	NSDictionary* customTransition = node.data[@"customTransition"];
82 82
 	RNNAnimator* animator = [[RNNAnimator alloc] initWithAnimationsDictionary:customTransition];
@@ -85,7 +85,7 @@
85 85
 	return [[RNNRootViewController alloc] initWithName:name withOptions:options withContainerId:containerId rootViewCreator:_creator eventEmitter:_eventEmitter animator:animator];
86 86
 }
87 87
 
88
-- (RNNNavigationController*)createContainerStack:(RNNLayoutNode*)node {
88
+- (UIViewController<RNNRootViewProtocol> *)createContainerStack:(RNNLayoutNode*)node {
89 89
 	RNNNavigationController* vc = [[RNNNavigationController alloc] init];
90 90
 	
91 91
 	NSMutableArray* controllers = [NSMutableArray new];
@@ -97,12 +97,12 @@
97 97
 	return vc;
98 98
 }
99 99
 
100
--(RNNTabBarController*)createTabs:(RNNLayoutNode*)node {
100
+-(UIViewController<RNNRootViewProtocol> *)createTabs:(RNNLayoutNode*)node {
101 101
 	RNNTabBarController* vc = [[RNNTabBarController alloc] init];
102 102
 	
103 103
 	NSMutableArray* controllers = [NSMutableArray new];
104 104
 	for (NSDictionary *child in node.children) {
105
-		UIViewController* childVc = [self fromTree:child];
105
+		UIViewController* childVc = (UIViewController*)[self fromTree:child];
106 106
 		RNNRootViewController* rootView = (RNNRootViewController *)childVc.childViewControllers.firstObject;
107 107
 		[rootView applyTabBarItem];
108 108
 		
@@ -113,7 +113,7 @@
113 113
 	return vc;
114 114
 }
115 115
 
116
-- (UIViewController*)createSideMenu:(RNNLayoutNode*)node {
116
+- (UIViewController<RNNRootViewProtocol> *)createSideMenu:(RNNLayoutNode*)node {
117 117
 	NSMutableArray* childrenVCs = [NSMutableArray new];
118 118
 	
119 119
 	
@@ -126,8 +126,8 @@
126 126
 }
127 127
 
128 128
 
129
-- (UIViewController*)createSideMenuChild:(RNNLayoutNode*)node type:(RNNSideMenuChildType)type {
130
-	UIViewController* child = [self fromTree:node.children[0]];
129
+- (UIViewController<RNNRootViewProtocol> *)createSideMenuChild:(RNNLayoutNode*)node type:(RNNSideMenuChildType)type {
130
+	UIViewController* child = (UIViewController*)[self fromTree:node.children[0]];
131 131
 	RNNSideMenuChildVC *sideMenuChild = [[RNNSideMenuChildVC alloc] initWithChild: child type:type];
132 132
 	
133 133
 	return sideMenuChild;

+ 2
- 1
lib/ios/RNNNavigationController.h Прегледај датотеку

@@ -1,5 +1,6 @@
1 1
 #import <UIKit/UIKit.h>
2
+#import "RNNRootViewProtocol.h"
2 3
 
3
-@interface RNNNavigationController : UINavigationController
4
+@interface RNNNavigationController : UINavigationController <RNNRootViewProtocol>
4 5
 
5 6
 @end

+ 4
- 0
lib/ios/RNNNavigationController.m Прегледај датотеку

@@ -7,4 +7,8 @@
7 7
 	return self.viewControllers.lastObject.supportedInterfaceOrientations;
8 8
 }
9 9
 
10
+- (BOOL)isAnimated {
11
+	return NO;
12
+}
13
+
10 14
 @end

+ 2
- 2
lib/ios/RNNNavigationStackManager.h Прегледај датотеку

@@ -5,12 +5,12 @@
5 5
 @interface RNNNavigationStackManager : NSObject
6 6
 
7 7
 @property (nonatomic, strong) UIViewController* fromVC;
8
-@property (nonatomic, strong) RNNRootViewController* toVC;
8
+@property (nonatomic, strong) UIViewController<RNNRootViewProtocol>* toVC;
9 9
 @property (nonatomic) int loadCount;
10 10
 -(instancetype)initWithStore:(RNNStore*)store;
11 11
 
12 12
 
13
--(void)push:(UIViewController*)newTop onTop:(NSString*)containerId completion:(RNNTransitionCompletionBlock)completion;
13
+-(void)push:(UIViewController<RNNRootViewProtocol>*)newTop onTop:(NSString*)containerId completion:(RNNTransitionCompletionBlock)completion;
14 14
 -(void)pop:(NSString*)containerId withAnimationData:(NSDictionary*)animationData;
15 15
 -(void)popTo:(NSString*)containerId;
16 16
 -(void)popToRoot:(NSString*)containerId;

+ 4
- 5
lib/ios/RNNNavigationStackManager.m Прегледај датотеку

@@ -15,19 +15,18 @@ dispatch_queue_t RCTGetUIManagerQueue(void);
15 15
 	return self;
16 16
 }
17 17
 
18
--(void)push:(UIViewController *)newTop onTop:(NSString *)containerId completion:(RNNTransitionCompletionBlock)completion {
18
+-(void)push:(UIViewController<RNNRootViewProtocol> *)newTop onTop:(NSString *)containerId completion:(RNNTransitionCompletionBlock)completion {
19 19
 	UIViewController *vc = [_store findContainerForId:containerId];
20 20
 	[self preparePush:newTop onTopVC:vc completion:completion];
21 21
 	[self waitForContentToAppearAndThen:@selector(pushAfterLoad:)];
22 22
 }
23 23
 
24
--(void)preparePush:(UIViewController *)newTop onTopVC:(UIViewController*)vc completion:(RNNTransitionCompletionBlock)completion {
25
-	self.toVC = (RNNRootViewController*)newTop;
24
+-(void)preparePush:(UIViewController<RNNRootViewProtocol> *)newTop onTopVC:(UIViewController*)vc completion:(RNNTransitionCompletionBlock)completion {
25
+	self.toVC = newTop;
26 26
 	self.fromVC = vc;
27 27
 	
28 28
 	if (self.toVC.isAnimated) {
29
-		RNNRootViewController* newTopRootView = (RNNRootViewController*)newTop;
30
-		vc.navigationController.delegate = newTopRootView;
29
+		vc.navigationController.delegate = newTop;
31 30
 	} else {
32 31
 		vc.navigationController.delegate = nil;
33 32
 		self.fromVC.navigationController.interactivePopGestureRecognizer.delegate = nil;

+ 3
- 2
lib/ios/RNNRootViewController.h Прегледај датотеку

@@ -6,8 +6,10 @@
6 6
 #import "RNNEventEmitter.h"
7 7
 #import "RNNNavigationOptions.h"
8 8
 #import "RNNAnimator.h"
9
+#import "RNNRootViewProtocol.h"
10
+
11
+@interface RNNRootViewController : UIViewController	<RNNRootViewProtocol>
9 12
 
10
-@interface RNNRootViewController : UIViewController	<UINavigationControllerDelegate>
11 13
 @property (nonatomic, strong) RNNNavigationOptions* navigationOptions;
12 14
 @property (nonatomic, strong) RNNAnimator* animator;
13 15
 @property (nonatomic, strong) RNNEventEmitter *eventEmitter;
@@ -22,7 +24,6 @@
22 24
 
23 25
 
24 26
 -(void)applyNavigationButtons;
25
--(BOOL)isAnimated;
26 27
 -(void)applyTabBarItem;
27 28
 
28 29
 @end

+ 10
- 0
lib/ios/RNNRootViewProtocol.h Прегледај датотеку

@@ -0,0 +1,10 @@
1
+
2
+@protocol RNNRootViewProtocol <NSObject, UINavigationControllerDelegate>
3
+
4
+@required
5
+
6
+- (BOOL)isAnimated;
7
+
8
+@end
9
+
10
+

+ 2
- 1
lib/ios/RNNSideMenuChildVC.h Прегледај датотеку

@@ -7,6 +7,7 @@
7 7
 //
8 8
 
9 9
 #import <UIKit/UIKit.h>
10
+#import "RNNRootViewProtocol.h"
10 11
 
11 12
 typedef NS_ENUM(NSInteger, RNNSideMenuChildType) {
12 13
 	RNNSideMenuChildTypeCenter,
@@ -15,7 +16,7 @@ typedef NS_ENUM(NSInteger, RNNSideMenuChildType) {
15 16
 };
16 17
 
17 18
 
18
-@interface RNNSideMenuChildVC : UIViewController
19
+@interface RNNSideMenuChildVC : UIViewController <RNNRootViewProtocol>
19 20
 
20 21
 @property (readonly) RNNSideMenuChildType type;
21 22
 @property (readonly) UIViewController *child;

+ 4
- 0
lib/ios/RNNSideMenuChildVC.m Прегледај датотеку

@@ -33,4 +33,8 @@
33 33
 	return self;
34 34
 }
35 35
 
36
+- (BOOL)isAnimated {
37
+	return NO;
38
+}
39
+
36 40
 @end

+ 2
- 1
lib/ios/RNNSideMenuController.h Прегледај датотеку

@@ -9,8 +9,9 @@
9 9
 #import <UIKit/UIKit.h>
10 10
 #import "RNNSideMenuChildVC.h"
11 11
 #import "MMDrawerController.h"
12
+#import "RNNRootViewProtocol.h"
12 13
 
13
-@interface RNNSideMenuController : UIViewController
14
+@interface RNNSideMenuController : UIViewController <RNNRootViewProtocol>
14 15
 
15 16
 @property (readonly) RNNSideMenuChildVC *center;
16 17
 @property (readonly) RNNSideMenuChildVC *left;

+ 4
- 0
lib/ios/RNNSideMenuController.m Прегледај датотеку

@@ -72,4 +72,8 @@
72 72
 	}
73 73
 }
74 74
 
75
+- (BOOL)isAnimated {
76
+	return NO;
77
+}
78
+
75 79
 @end

+ 2
- 1
lib/ios/RNNTabBarController.h Прегледај датотеку

@@ -1,7 +1,8 @@
1 1
 
2 2
 #import <UIKit/UIKit.h>
3
+#import "RNNRootViewProtocol.h"
3 4
 
4
-@interface RNNTabBarController : UITabBarController
5
+@interface RNNTabBarController : UITabBarController <RNNRootViewProtocol>
5 6
 
6 7
 - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated;
7 8
 - (void)setSelectedIndexByContainerID:(NSString *)containerID;

+ 4
- 0
lib/ios/RNNTabBarController.m Прегледај датотеку

@@ -33,4 +33,8 @@
33 33
 	}
34 34
 }
35 35
 
36
+- (BOOL)isAnimated {
37
+	return NO;
38
+}
39
+
36 40
 @end

+ 4
- 0
lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj Прегледај датотеку

@@ -57,6 +57,7 @@
57 57
 		268692831E5054F800E2C612 /* RNNStore.m in Sources */ = {isa = PBXBuildFile; fileRef = 268692811E5054F800E2C612 /* RNNStore.m */; };
58 58
 		26916C981E4B9E7700D13680 /* RNNReactRootViewCreator.h in Headers */ = {isa = PBXBuildFile; fileRef = 26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */; };
59 59
 		26916C991E4B9E7700D13680 /* RNNReactRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = 26916C971E4B9E7700D13680 /* RNNReactRootViewCreator.m */; };
60
+		507F44201FFA8A8800D9425B /* RNNRootViewProtocol.h in Headers */ = {isa = PBXBuildFile; fileRef = 507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */; };
60 61
 		50CB3B691FDE911400AA153B /* RNNSideMenuOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */; };
61 62
 		50CB3B6A1FDE911400AA153B /* RNNSideMenuOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */; };
62 63
 		50EB93411FE14A3E00BD8EEE /* RNNTabItemOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EB933F1FE14A3E00BD8EEE /* RNNTabItemOptions.h */; };
@@ -207,6 +208,7 @@
207 208
 		26916C941E4B9CCC00D13680 /* RNNRootViewCreator.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNRootViewCreator.h; sourceTree = "<group>"; };
208 209
 		26916C961E4B9E7700D13680 /* RNNReactRootViewCreator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNReactRootViewCreator.h; sourceTree = "<group>"; };
209 210
 		26916C971E4B9E7700D13680 /* RNNReactRootViewCreator.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNNReactRootViewCreator.m; sourceTree = "<group>"; };
211
+		507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RNNRootViewProtocol.h; sourceTree = "<group>"; };
210 212
 		50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNSideMenuOptions.h; sourceTree = "<group>"; };
211 213
 		50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSideMenuOptions.m; sourceTree = "<group>"; };
212 214
 		50EB933F1FE14A3E00BD8EEE /* RNNTabItemOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNTabItemOptions.h; sourceTree = "<group>"; };
@@ -438,6 +440,7 @@
438 440
 				A7626C001FC5796200492FB8 /* RNNTabBarOptions.m */,
439 441
 				50CB3B671FDE911400AA153B /* RNNSideMenuOptions.h */,
440 442
 				50CB3B681FDE911400AA153B /* RNNSideMenuOptions.m */,
443
+				507F441F1FFA8A8800D9425B /* RNNRootViewProtocol.h */,
441 444
 			);
442 445
 			name = Controllers;
443 446
 			sourceTree = "<group>";
@@ -607,6 +610,7 @@
607 610
 				268692821E5054F800E2C612 /* RNNStore.h in Headers */,
608 611
 				E8AEDB3C1F55A1C2000F5A6A /* RNNElementView.h in Headers */,
609 612
 				E8E518321F83B3E0000467AC /* RNNUtils.h in Headers */,
613
+				507F44201FFA8A8800D9425B /* RNNRootViewProtocol.h in Headers */,
610 614
 				263905CA1E4C6F440023D7D3 /* SidebarLuvocracyAnimation.h in Headers */,
611 615
 				263905B11E4C6F440023D7D3 /* MMDrawerController.h in Headers */,
612 616
 				50EB93411FE14A3E00BD8EEE /* RNNTabItemOptions.h in Headers */,

+ 2
- 0
lib/src/params/containers/Container.js Прегледај датотеку

@@ -5,6 +5,7 @@ class Container {
5 5
    * @property {string} name The container's registered name
6 6
    * @property {Container[]} [topTabs]
7 7
    * @property {object} [passProps] props
8
+   * @property {object} [customTransition]
8 9
    * @property {NavigationOptions} navigationOptions
9 10
    */
10 11
   constructor(params) {
@@ -14,6 +15,7 @@ class Container {
14 15
       this.topTabs = params.topTabs;
15 16
     }
16 17
     this.passProps = params.passProps;
18
+    this.customTransition = params.customTransition;
17 19
     this.navigationOptions = params.navigationOptions && new NavigationOptions(params.navigationOptions);
18 20
   }
19 21
 }