Browse Source

Fix sending dismissed modal event when dismissing modal by swiping gesture (#5747)

* Fix dismissed modal event by swiping down gesture

* Fix typescript
Yogev Ben David 5 years ago
parent
commit
4cb0e98a67
No account linked to committer's email address

+ 1
- 0
lib/ios/RNNModalManager.m View File

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
 }
128
 }
128
 
129
 
129
 -(UIViewController*)topPresentedVC {
130
 -(UIViewController*)topPresentedVC {

+ 2
- 2
lib/src/events/ComponentEventsObserver.test.tsx View File

175
     expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
175
     expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
176
     expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });
176
     expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });
177
 
177
 
178
-    uut.notifyModalDismissed({ componentId: 'myCompId' });
178
+    uut.notifyModalDismissed({ componentId: 'myCompId', modalsDismissed: 1 });
179
     expect(modalDismissedFn).toHaveBeenCalledTimes(1);
179
     expect(modalDismissedFn).toHaveBeenCalledTimes(1);
180
-    expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId' })
180
+    expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId', modalsDismissed: 1 })
181
 
181
 
182
     uut.notifySearchBarUpdated({ componentId: 'myCompId', text: 'theText', isFocused: true });
182
     uut.notifySearchBarUpdated({ componentId: 'myCompId', text: 'theText', isFocused: true });
183
     expect(searchBarUpdatedFn).toHaveBeenCalledTimes(1);
183
     expect(searchBarUpdatedFn).toHaveBeenCalledTimes(1);

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

1
 #import <XCTest/XCTest.h>
1
 #import <XCTest/XCTest.h>
2
+#import <OCMock/OCMock.h>
2
 #import "RNNModalManager.h"
3
 #import "RNNModalManager.h"
3
 #import "RNNComponentViewController.h"
4
 #import "RNNComponentViewController.h"
4
 
5
 
107
 	XCTAssertTrue(_modalManager.topPresentedVC.presentViewControllerCalls == 1);
108
 	XCTAssertTrue(_modalManager.topPresentedVC.presentViewControllerCalls == 1);
108
 }
109
 }
109
 
110
 
111
+- (void)testDismissModal_ShouldInvokeDelegateDismissedModal {
112
+	id mockDelegate = [OCMockObject mockForProtocol:@protocol(RNNModalManagerDelegate)];
113
+	_modalManager.delegate = mockDelegate;
114
+	[_modalManager showModal:_vc1 animated:NO completion:nil];
115
+	
116
+	[[mockDelegate expect] dismissedModal:_vc1];
117
+	[_modalManager dismissModal:_vc1 completion:nil];
118
+	[mockDelegate verify];
119
+}
120
+
121
+- (void)testPresentationControllerDidDismiss_ShouldInvokeDelegateDismissedModal {
122
+	id mockDelegate = [OCMockObject mockForProtocol:@protocol(RNNModalManagerDelegate)];
123
+	_modalManager.delegate = mockDelegate;
124
+	
125
+	UIPresentationController* presentationController = [[UIPresentationController alloc] initWithPresentedViewController:_vc2 presentingViewController:_vc1];
126
+	
127
+	[[mockDelegate expect] dismissedModal:_vc2];
128
+	[_modalManager presentationControllerDidDismiss:presentationController];
129
+	[mockDelegate verify];
130
+}
131
+
110
 #pragma mark RNNModalManagerDelegate
132
 #pragma mark RNNModalManagerDelegate
111
 
133
 
112
 - (void)dismissedMultipleModals:(NSArray *)viewControllers {
134
 - (void)dismissedMultipleModals:(NSArray *)viewControllers {