瀏覽代碼

Fix modal dismissed event emits wrong componentId (#5773)

Fix modal dismissed with swipe gesture emits wrong componentId
Yogev Ben David 5 年之前
父節點
當前提交
45eef0df1f

+ 2
- 0
lib/ios/RNNLayoutProtocol.h 查看文件

@@ -25,6 +25,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
25 25
 
26 26
 - (CGFloat)getBottomTabsHeight;
27 27
 
28
+- (UIViewController *)topMostViewController;
29
+
28 30
 - (void)mergeOptions:(RNNNavigationOptions *)options;
29 31
 
30 32
 - (RNNNavigationOptions *)resolveOptions;

+ 5
- 5
lib/ios/RNNModalManager.m 查看文件

@@ -1,7 +1,7 @@
1 1
 #import "RNNModalManager.h"
2 2
 #import "RNNComponentViewController.h"
3 3
 #import "RNNAnimationsTransitionDelegate.h"
4
-#import "RNNLayoutProtocol.h"
4
+#import "UIViewController+LayoutProtocol.h"
5 5
 
6 6
 @implementation RNNModalManager {
7 7
 	NSMutableArray* _pendingModalIdsToDismiss;
@@ -43,7 +43,7 @@
43 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,13 +118,13 @@
118 118
 }
119 119
 
120 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 125
 - (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
126 126
 	[_presentedModals removeObject:presentationController.presentedViewController];
127
-    [_delegate dismissedModal:presentationController.presentedViewController];
127
+    [_delegate dismissedModal:presentationController.presentedViewController.presentedComponentViewController];
128 128
 }
129 129
 
130 130
 -(UIViewController*)topPresentedVC {

+ 2
- 0
lib/ios/UIViewController+LayoutProtocol.h 查看文件

@@ -12,6 +12,8 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
12 12
 
13 13
 - (UIViewController *)presentedComponentViewController;
14 14
 
15
+- (UIViewController *)topMostViewController;
16
+
15 17
 - (void)mergeOptions:(RNNNavigationOptions *)options;
16 18
 
17 19
 - (void)mergeChildOptions:(RNNNavigationOptions *)options;

+ 7
- 0
lib/ios/UIViewController+LayoutProtocol.m 查看文件

@@ -87,6 +87,13 @@
87 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 97
 - (CGFloat)getTopBarHeight {
91 98
     for(UIViewController * child in [self childViewControllers]) {
92 99
         CGFloat childTopBarHeight = [child getTopBarHeight];

+ 13
- 0
playground/ios/NavigationTests/RNNModalManagerTest.m 查看文件

@@ -2,6 +2,7 @@
2 2
 #import <OCMock/OCMock.h>
3 3
 #import "RNNModalManager.h"
4 4
 #import "RNNComponentViewController.h"
5
+#import "RNNStackController.h"
5 6
 
6 7
 @interface MockViewController : UIViewController
7 8
 
@@ -129,6 +130,18 @@
129 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 145
 #pragma mark RNNModalManagerDelegate
133 146
 
134 147
 - (void)dismissedMultipleModals:(NSArray *)viewControllers {