yogevbd 6 years ago
parent
commit
64d7888161
3 changed files with 43 additions and 31 deletions
  1. 1
    1
      e2e/ScreenStack.test.js
  2. 0
    2
      lib/ios/RNNNavigationStackManager.h
  3. 42
    28
      lib/ios/RNNNavigationStackManager.m

+ 1
- 1
e2e/ScreenStack.test.js View File

99
     await expect(elementByLabel('Stack Position: 2')).toBeVisible();
99
     await expect(elementByLabel('Stack Position: 2')).toBeVisible();
100
   });
100
   });
101
 
101
 
102
-  it(':android: push to stack with static id from SideMenu', async () => {
102
+  it('push to stack with static id from SideMenu', async () => {
103
     await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
103
     await elementById(testIDs.TAB_BASED_APP_SIDE_BUTTON).tap();
104
     await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
104
     await elementById(testIDs.SHOW_LEFT_SIDE_MENU_BUTTON).tap();
105
     await elementById(testIDs.LEFT_SIDE_MENU_PUSH_BUTTON).tap();
105
     await elementById(testIDs.LEFT_SIDE_MENU_PUSH_BUTTON).tap();

+ 0
- 2
lib/ios/RNNNavigationStackManager.h View File

4
 
4
 
5
 @interface RNNNavigationStackManager : NSObject
5
 @interface RNNNavigationStackManager : NSObject
6
 
6
 
7
-@property (nonatomic, strong) UIViewController* fromVC;
8
-@property (nonatomic, strong) RNNRootViewController* toVC;
9
 @property (nonatomic) int loadCount;
7
 @property (nonatomic) int loadCount;
10
 -(instancetype)initWithStore:(RNNStore*)store;
8
 -(instancetype)initWithStore:(RNNStore*)store;
11
 
9
 

+ 42
- 28
lib/ios/RNNNavigationStackManager.m View File

2
 #import "RNNRootViewController.h"
2
 #import "RNNRootViewController.h"
3
 #import "RNNAnimator.h"
3
 #import "RNNAnimator.h"
4
 #import "RNNErrorHandler.h"
4
 #import "RNNErrorHandler.h"
5
-
5
+#import "RNNNavigationController.h"
6
 
6
 
7
 dispatch_queue_t RCTGetUIManagerQueue(void);
7
 dispatch_queue_t RCTGetUIManagerQueue(void);
8
+@interface RNNNavigationStackManager()
9
+@property (nonatomic, strong) RNNNavigationController* nvc;
10
+@property (nonatomic, strong) RNNRootViewController* toVC;
11
+@end
12
+
8
 @implementation RNNNavigationStackManager {
13
 @implementation RNNNavigationStackManager {
9
 	RNNStore *_store;
14
 	RNNStore *_store;
10
 	RNNTransitionCompletionBlock _completionBlock;
15
 	RNNTransitionCompletionBlock _completionBlock;
17
 }
22
 }
18
 
23
 
19
 -(void)push:(UIViewController<RNNRootViewProtocol> *)newTop onTop:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
24
 -(void)push:(UIViewController<RNNRootViewProtocol> *)newTop onTop:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
20
-	UIViewController *vc = [_store findComponentForId:componentId];
21
-	[self preparePush:newTop onTopVC:vc completion:completion];
22
-	[self assertNavigationControllerExist:vc reject:rejection];
25
+	RNNNavigationController *nvc = [self getComponentStack:componentId];
26
+	[self assertNavigationControllerExist:nvc reject:rejection];
27
+	[self preparePush:newTop onTopVC:nvc completion:completion];
23
 	if ([newTop isCustomViewController]) {
28
 	if ([newTop isCustomViewController]) {
24
 		[self pushAfterLoad:nil];
29
 		[self pushAfterLoad:nil];
25
 	} else {
30
 	} else {
27
 	}
32
 	}
28
 }
33
 }
29
 
34
 
30
--(void)preparePush:(UIViewController<RNNRootViewProtocol> *)newTop onTopVC:(UIViewController*)vc completion:(RNNTransitionCompletionBlock)completion {
35
+-(void)preparePush:(UIViewController<RNNRootViewProtocol> *)newTop onTopVC:(RNNNavigationController*)nvc completion:(RNNTransitionCompletionBlock)completion {
31
 	self.toVC = (RNNRootViewController*)newTop;
36
 	self.toVC = (RNNRootViewController*)newTop;
32
-	self.fromVC = vc;
37
+	self.nvc = nvc;
33
 	
38
 	
34
 	
39
 	
35
 	if (self.toVC.options.animations.push.hasCustomAnimation || self.toVC.isCustomTransitioned) {
40
 	if (self.toVC.options.animations.push.hasCustomAnimation || self.toVC.isCustomTransitioned) {
36
-		vc.navigationController.delegate = newTop;
41
+		nvc.delegate = newTop;
37
 	} else {
42
 	} else {
38
-		vc.navigationController.delegate = nil;
39
-		self.fromVC.navigationController.interactivePopGestureRecognizer.delegate = nil;
43
+		nvc.delegate = nil;
44
+		nvc.interactivePopGestureRecognizer.delegate = nil;
40
 	}
45
 	}
41
 	
46
 	
42
 	_completionBlock = completion;
47
 	_completionBlock = completion;
59
 		}
64
 		}
60
 	}];
65
 	}];
61
 	
66
 	
62
-	[[self.fromVC navigationController] pushViewController:self.toVC animated:self.toVC.options.animations.push.enable];
67
+	[self.nvc pushViewController:self.toVC animated:self.toVC.options.animations.push.enable];
63
 	[CATransaction commit];
68
 	[CATransaction commit];
64
 	
69
 	
65
 	self.toVC = nil;
70
 	self.toVC = nil;
66
-	self.fromVC.navigationController.interactivePopGestureRecognizer.delegate = nil;
67
-	self.fromVC = nil;
71
+	self.nvc.interactivePopGestureRecognizer.delegate = nil;
72
+	self.nvc = nil;
68
 }
73
 }
69
 
74
 
70
 -(void)pop:(NSString *)componentId withTransitionOptions:(RNNAnimationOptions *)transitionOptions rejection:(RCTPromiseRejectBlock)rejection {
75
 -(void)pop:(NSString *)componentId withTransitionOptions:(RNNAnimationOptions *)transitionOptions rejection:(RCTPromiseRejectBlock)rejection {
71
 	RNNRootViewController* vc = (RNNRootViewController*)[_store findComponentForId:componentId];
76
 	RNNRootViewController* vc = (RNNRootViewController*)[_store findComponentForId:componentId];
72
-	[self assertNavigationControllerExist:vc reject:rejection];
73
-	UINavigationController* nvc = [vc navigationController];
77
+	UINavigationController* nvc = [self getComponentStack:componentId];
78
+	[self assertNavigationControllerExist:nvc reject:rejection];
79
+	
74
 	if ([nvc topViewController] == vc) {
80
 	if ([nvc topViewController] == vc) {
75
 		if (vc.options.animations.pop) {
81
 		if (vc.options.animations.pop) {
76
 			nvc.delegate = vc;
82
 			nvc.delegate = vc;
89
 
95
 
90
 -(void)popTo:(NSString*)componentId rejection:(RCTPromiseRejectBlock)rejection {
96
 -(void)popTo:(NSString*)componentId rejection:(RCTPromiseRejectBlock)rejection {
91
 	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
97
 	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
92
-	[self assertNavigationControllerExist:vc reject:rejection];
93
-	if (vc) {
94
-		UINavigationController *nvc = [vc navigationController];
95
-		if(nvc) {
96
-			NSArray *poppedVCs = [nvc popToViewController:vc animated:vc.options.animations.pop.enable];
97
-			[self removePopedViewControllers:poppedVCs];
98
-		}
98
+	RNNNavigationController *nvc = [self getComponentStack:componentId];
99
+	[self assertNavigationControllerExist:nvc reject:rejection];
100
+	
101
+	if (vc && nvc) {
102
+		NSArray *poppedVCs = [nvc popToViewController:vc animated:vc.options.animations.pop.enable];
103
+		[self removePopedViewControllers:poppedVCs];
99
 	}
104
 	}
100
 }
105
 }
101
 
106
 
102
 -(void)popToRoot:(NSString*)componentId rejection:(RCTPromiseRejectBlock)rejection {
107
 -(void)popToRoot:(NSString*)componentId rejection:(RCTPromiseRejectBlock)rejection {
103
 	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
108
 	RNNRootViewController *vc = (RNNRootViewController*)[_store findComponentForId:componentId];
104
-	[self assertNavigationControllerExist:vc reject:rejection];
105
-	UINavigationController* nvc = [vc navigationController];
109
+	RNNNavigationController *nvc = [self getComponentStack:componentId];
110
+	[self assertNavigationControllerExist:nvc reject:rejection];
106
 	NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:vc.options.animations.pop.enable];
111
 	NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:vc.options.animations.pop.enable];
107
 	[self removePopedViewControllers:poppedVCs];
112
 	[self removePopedViewControllers:poppedVCs];
108
 }
113
 }
109
 
114
 
110
 -(void)setStackRoot:(UIViewController<RNNRootViewProtocol> *)newRoot fromComponent:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
115
 -(void)setStackRoot:(UIViewController<RNNRootViewProtocol> *)newRoot fromComponent:(NSString *)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RCTPromiseRejectBlock)rejection {
111
-	UIViewController* vc = [_store findComponentForId:componentId];
112
-	[self assertNavigationControllerExist:vc reject:rejection];
113
-	UINavigationController* nvc = [vc navigationController];
116
+	RNNNavigationController* nvc = [self getComponentStack:componentId];
117
+
118
+	[self assertNavigationControllerExist:nvc reject:rejection];
114
 	
119
 	
115
 	[CATransaction begin];
120
 	[CATransaction begin];
116
 	[CATransaction setCompletionBlock:^{
121
 	[CATransaction setCompletionBlock:^{
124
 	[CATransaction commit];
129
 	[CATransaction commit];
125
 }
130
 }
126
 
131
 
127
-- (void)assertNavigationControllerExist:(UIViewController *)viewController reject:(RCTPromiseRejectBlock)reject {
128
-	if (!viewController.navigationController) {
132
+- (void)assertNavigationControllerExist:(UINavigationController *)viewController reject:(RCTPromiseRejectBlock)reject {
133
+	if (![viewController isKindOfClass:[UINavigationController class]]) {
129
 		_completionBlock = nil;
134
 		_completionBlock = nil;
130
 		[RNNErrorHandler reject:reject withErrorCode:RNNCommandErrorCodeNoStack errorDescription:[NSString stringWithFormat:@"%@ should be called from a stack child component", [RNNErrorHandler getCallerFunctionName]]];
135
 		[RNNErrorHandler reject:reject withErrorCode:RNNCommandErrorCodeNoStack errorDescription:[NSString stringWithFormat:@"%@ should be called from a stack child component", [RNNErrorHandler getCallerFunctionName]]];
131
 	}
136
 	}
132
 }
137
 }
133
 
138
 
139
+- (RNNNavigationController*)getComponentStack:(NSString *)componentId {
140
+	UIViewController* component = [_store findComponentForId:componentId];
141
+	if ([component isKindOfClass:[UINavigationController class]]) {
142
+		return (RNNNavigationController*)component;
143
+	} else {
144
+		return (RNNNavigationController*)component.navigationController;
145
+	}
146
+}
147
+
134
 -(void)removePopedViewControllers:(NSArray*)viewControllers {
148
 -(void)removePopedViewControllers:(NSArray*)viewControllers {
135
 	for (UIViewController *popedVC in viewControllers) {
149
 	for (UIViewController *popedVC in viewControllers) {
136
 		[_store removeComponentByViewControllerInstance:popedVC];
150
 		[_store removeComponentByViewControllerInstance:popedVC];