Browse Source

Fix modal dismissed event emits wrong componentId (#5773)

Fix modal dismissed with swipe gesture emits wrong componentId
Yogev Ben David 5 years ago
parent
commit
45eef0df1f

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

25
 
25
 
26
 - (CGFloat)getBottomTabsHeight;
26
 - (CGFloat)getBottomTabsHeight;
27
 
27
 
28
+- (UIViewController *)topMostViewController;
29
+
28
 - (void)mergeOptions:(RNNNavigationOptions *)options;
30
 - (void)mergeOptions:(RNNNavigationOptions *)options;
29
 
31
 
30
 - (RNNNavigationOptions *)resolveOptions;
32
 - (RNNNavigationOptions *)resolveOptions;

+ 5
- 5
lib/ios/RNNModalManager.m View File

1
 #import "RNNModalManager.h"
1
 #import "RNNModalManager.h"
2
 #import "RNNComponentViewController.h"
2
 #import "RNNComponentViewController.h"
3
 #import "RNNAnimationsTransitionDelegate.h"
3
 #import "RNNAnimationsTransitionDelegate.h"
4
-#import "RNNLayoutProtocol.h"
4
+#import "UIViewController+LayoutProtocol.h"
5
 
5
 
6
 @implementation RNNModalManager {
6
 @implementation RNNModalManager {
7
 	NSMutableArray* _pendingModalIdsToDismiss;
7
 	NSMutableArray* _pendingModalIdsToDismiss;
43
 			completion(nil);
43
 			completion(nil);
44
 		}
44
 		}
45
 		
45
 		
46
-		[_presentedModals addObject:viewController.navigationController ? viewController.navigationController : viewController];
46
+        [self->_presentedModals addObject:[viewController topMostViewController]];
47
 	}];
47
 	}];
48
 }
48
 }
49
 
49
 
118
 }
118
 }
119
 
119
 
120
 - (void)dismissedModal:(UIViewController *)viewController {
120
 - (void)dismissedModal:(UIViewController *)viewController {
121
-	[_presentedModals removeObject:viewController.navigationController ? viewController.navigationController : viewController];
122
-	[_delegate dismissedModal:viewController];
121
+	[_presentedModals removeObject:[viewController topMostViewController]];
122
+	[_delegate dismissedModal:viewController.presentedComponentViewController];
123
 }
123
 }
124
 
124
 
125
 - (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
125
 - (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
126
 	[_presentedModals removeObject:presentationController.presentedViewController];
126
 	[_presentedModals removeObject:presentationController.presentedViewController];
127
-    [_delegate dismissedModal:presentationController.presentedViewController];
127
+    [_delegate dismissedModal:presentationController.presentedViewController.presentedComponentViewController];
128
 }
128
 }
129
 
129
 
130
 -(UIViewController*)topPresentedVC {
130
 -(UIViewController*)topPresentedVC {

+ 2
- 0
lib/ios/UIViewController+LayoutProtocol.h View File

12
 
12
 
13
 - (UIViewController *)presentedComponentViewController;
13
 - (UIViewController *)presentedComponentViewController;
14
 
14
 
15
+- (UIViewController *)topMostViewController;
16
+
15
 - (void)mergeOptions:(RNNNavigationOptions *)options;
17
 - (void)mergeOptions:(RNNNavigationOptions *)options;
16
 
18
 
17
 - (void)mergeChildOptions:(RNNNavigationOptions *)options;
19
 - (void)mergeChildOptions:(RNNNavigationOptions *)options;

+ 7
- 0
lib/ios/UIViewController+LayoutProtocol.m View File

87
     return self.getCurrentChild ? self.getCurrentChild.presentedComponentViewController : self;
87
     return self.getCurrentChild ? self.getCurrentChild.presentedComponentViewController : self;
88
 }
88
 }
89
 
89
 
90
+- (UIViewController *)topMostViewController {
91
+    if (self.parentViewController) {
92
+        return [self.parentViewController topMostViewController];
93
+    } else
94
+        return self;
95
+}
96
+
90
 - (CGFloat)getTopBarHeight {
97
 - (CGFloat)getTopBarHeight {
91
     for(UIViewController * child in [self childViewControllers]) {
98
     for(UIViewController * child in [self childViewControllers]) {
92
         CGFloat childTopBarHeight = [child getTopBarHeight];
99
         CGFloat childTopBarHeight = [child getTopBarHeight];

+ 13
- 0
playground/ios/NavigationTests/RNNModalManagerTest.m View File

2
 #import <OCMock/OCMock.h>
2
 #import <OCMock/OCMock.h>
3
 #import "RNNModalManager.h"
3
 #import "RNNModalManager.h"
4
 #import "RNNComponentViewController.h"
4
 #import "RNNComponentViewController.h"
5
+#import "RNNStackController.h"
5
 
6
 
6
 @interface MockViewController : UIViewController
7
 @interface MockViewController : UIViewController
7
 
8
 
129
 	[mockDelegate verify];
130
 	[mockDelegate verify];
130
 }
131
 }
131
 
132
 
133
+- (void)testPresentationControllerDidDismiss_ShouldInvokeDelegateDismissedModalWithPresentedChild {
134
+	id mockDelegate = [OCMockObject mockForProtocol:@protocol(RNNModalManagerDelegate)];
135
+	_modalManager.delegate = mockDelegate;
136
+	RNNStackController* nav = [[RNNStackController alloc] initWithRootViewController:_vc2];
137
+	
138
+	UIPresentationController* presentationController = [[UIPresentationController alloc] initWithPresentedViewController:nav presentingViewController:_vc1];
139
+	
140
+	[[mockDelegate expect] dismissedModal:_vc2];
141
+	[_modalManager presentationControllerDidDismiss:presentationController];
142
+	[mockDelegate verify];
143
+}
144
+
132
 #pragma mark RNNModalManagerDelegate
145
 #pragma mark RNNModalManagerDelegate
133
 
146
 
134
 - (void)dismissedMultipleModals:(NSArray *)viewControllers {
147
 - (void)dismissedMultipleModals:(NSArray *)viewControllers {