Skip to content

Commit

Permalink
Fix sending dismissed modal event when dismissing modal by swiping ge…
Browse files Browse the repository at this point in the history
…sture (#5747)

* Fix dismissed modal event by swiping down gesture

* Fix typescript
  • Loading branch information
yogevbd authored Dec 9, 2019
1 parent 0823a2c commit 4cb0e98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/ios/RNNModalManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ - (void)dismissedModal:(UIViewController *)viewController {

- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController {
[_presentedModals removeObject:presentationController.presentedViewController];
[_delegate dismissedModal:presentationController.presentedViewController];
}

-(UIViewController*)topPresentedVC {
Expand Down
4 changes: 2 additions & 2 deletions lib/src/events/ComponentEventsObserver.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ describe('ComponentEventsObserver', () => {
expect(navigationButtonPressedFn).toHaveBeenCalledTimes(1);
expect(navigationButtonPressedFn).toHaveBeenCalledWith({ buttonId: 'myButtonId', componentId: 'myCompId' });

uut.notifyModalDismissed({ componentId: 'myCompId' });
uut.notifyModalDismissed({ componentId: 'myCompId', modalsDismissed: 1 });
expect(modalDismissedFn).toHaveBeenCalledTimes(1);
expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId' })
expect(modalDismissedFn).toHaveBeenLastCalledWith({ componentId: 'myCompId', modalsDismissed: 1 })

uut.notifySearchBarUpdated({ componentId: 'myCompId', text: 'theText', isFocused: true });
expect(searchBarUpdatedFn).toHaveBeenCalledTimes(1);
Expand Down
22 changes: 22 additions & 0 deletions playground/ios/NavigationTests/RNNModalManagerTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import <XCTest/XCTest.h>
#import <OCMock/OCMock.h>
#import "RNNModalManager.h"
#import "RNNComponentViewController.h"

Expand Down Expand Up @@ -107,6 +108,27 @@ - (void)testShowModal_CallPresentViewController {
XCTAssertTrue(_modalManager.topPresentedVC.presentViewControllerCalls == 1);
}

- (void)testDismissModal_ShouldInvokeDelegateDismissedModal {
id mockDelegate = [OCMockObject mockForProtocol:@protocol(RNNModalManagerDelegate)];
_modalManager.delegate = mockDelegate;
[_modalManager showModal:_vc1 animated:NO completion:nil];

[[mockDelegate expect] dismissedModal:_vc1];
[_modalManager dismissModal:_vc1 completion:nil];
[mockDelegate verify];
}

- (void)testPresentationControllerDidDismiss_ShouldInvokeDelegateDismissedModal {
id mockDelegate = [OCMockObject mockForProtocol:@protocol(RNNModalManagerDelegate)];
_modalManager.delegate = mockDelegate;

UIPresentationController* presentationController = [[UIPresentationController alloc] initWithPresentedViewController:_vc2 presentingViewController:_vc1];

[[mockDelegate expect] dismissedModal:_vc2];
[_modalManager presentationControllerDidDismiss:presentationController];
[mockDelegate verify];
}

#pragma mark RNNModalManagerDelegate

- (void)dismissedMultipleModals:(NSArray *)viewControllers {
Expand Down

0 comments on commit 4cb0e98

Please sign in to comment.