Skip to content

Commit 8114937

Browse files
authoredFeb 28, 2021
Fix back button doesn't pop on iOS 12 (wix#6995)
On iOS 12 and below, `navigationBar:shouldPopItem` behave differently than the following iOS versions, Thus it should have its own specific implementation. Closes wix#6993
1 parent d4aa63d commit 8114937

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed
 
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#import <Foundation/Foundation.h>
2+
3+
@interface RNNNavigationBarDelegateHandler : NSObject
4+
5+
- (void)popViewControllerAnimated:(BOOL)animated;
6+
7+
- (BOOL)navigationController:(UINavigationController *)navigationController
8+
shouldPopItem:(BOOL)shouldPopItem;
9+
10+
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item;
11+
12+
@end
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#import "RNNNavigationBarDelegateHandler.h"
2+
3+
@implementation RNNNavigationBarDelegateHandler {
4+
BOOL _isPopping;
5+
}
6+
7+
- (void)popViewControllerAnimated:(BOOL)animated {
8+
_isPopping = YES;
9+
}
10+
11+
- (BOOL)navigationController:(UINavigationController *)navigationController
12+
shouldPopItem:(BOOL)shouldPopItem {
13+
if (@available(iOS 13.0, *)) {
14+
return shouldPopItem;
15+
} else {
16+
if (_isPopping) {
17+
return YES;
18+
} else if (shouldPopItem) {
19+
[navigationController popViewControllerAnimated:YES];
20+
_isPopping = NO;
21+
return YES;
22+
} else {
23+
return NO;
24+
}
25+
}
26+
}
27+
28+
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item {
29+
_isPopping = NO;
30+
}
31+
32+
@end

‎lib/ios/RNNStackController.m

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
#import "RNNStackController.h"
22
#import "RNNComponentViewController.h"
3+
#import "RNNNavigationBarDelegateHandler.h"
34
#import "StackControllerDelegate.h"
45
#import "UIViewController+Utils.h"
56

67
@implementation RNNStackController {
78
UIViewController *_presentedViewController;
89
StackControllerDelegate *_stackDelegate;
10+
RNNNavigationBarDelegateHandler *_navigationBarDelegateHandler;
911
}
1012

1113
- (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
@@ -25,6 +27,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo
2527
_stackDelegate = [[StackControllerDelegate alloc] initWithEventEmitter:self.eventEmitter];
2628
self.delegate = _stackDelegate;
2729
self.navigationBar.prefersLargeTitles = YES;
30+
_navigationBarDelegateHandler = RNNNavigationBarDelegateHandler.new;
2831
return self;
2932
}
3033

@@ -41,6 +44,7 @@ - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewControlle
4144
}
4245

4346
- (UIViewController *)popViewControllerAnimated:(BOOL)animated {
47+
[_navigationBarDelegateHandler popViewControllerAnimated:animated];
4448
[self prepareForPop];
4549
return [super popViewControllerAnimated:animated];
4650
}
@@ -53,7 +57,12 @@ - (BOOL)navigationBar:(UINavigationBar *)navigationBar shouldPopItem:(UINavigati
5357
buttonId:[self.getCurrentChild.options.topBar.backButton.identifier
5458
withDefault:@"RNN.back"]];
5559
}
56-
return shouldPopItem;
60+
61+
return [_navigationBarDelegateHandler navigationController:self shouldPopItem:shouldPopItem];
62+
}
63+
64+
- (void)navigationBar:(UINavigationBar *)navigationBar didPopItem:(UINavigationItem *)item {
65+
[_navigationBarDelegateHandler navigationBar:navigationBar didPopItem:item];
5766
}
5867

5968
- (void)prepareForPop {

‎lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj

+8
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@
178178
504189582506144D004A6BC7 /* RNNSetRootAnimator.m in Sources */ = {isa = PBXBuildFile; fileRef = 504189562506144D004A6BC7 /* RNNSetRootAnimator.m */; };
179179
5041DC3E2417BBBA0033312F /* BottomTabsBasePresenter.h in Headers */ = {isa = PBXBuildFile; fileRef = 5041DC3C2417BBBA0033312F /* BottomTabsBasePresenter.h */; };
180180
5041DC3F2417BBBA0033312F /* BottomTabsBasePresenter.m in Sources */ = {isa = PBXBuildFile; fileRef = 5041DC3D2417BBBA0033312F /* BottomTabsBasePresenter.m */; };
181+
5042FC9725EBABED0087F562 /* RNNNavigationBarDelegateHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 5042FC9525EBABED0087F562 /* RNNNavigationBarDelegateHandler.h */; };
182+
5042FC9825EBABED0087F562 /* RNNNavigationBarDelegateHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 5042FC9625EBABED0087F562 /* RNNNavigationBarDelegateHandler.m */; };
181183
50451D052042DAEB00695F00 /* RNNPushAnimation.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D032042DAEB00695F00 /* RNNPushAnimation.h */; };
182184
50451D062042DAEB00695F00 /* RNNPushAnimation.m in Sources */ = {isa = PBXBuildFile; fileRef = 50451D042042DAEB00695F00 /* RNNPushAnimation.m */; };
183185
50451D092042E20600695F00 /* RNNAnimationsOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50451D072042E20600695F00 /* RNNAnimationsOptions.h */; };
@@ -700,6 +702,8 @@
700702
504189562506144D004A6BC7 /* RNNSetRootAnimator.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNSetRootAnimator.m; sourceTree = "<group>"; };
701703
5041DC3C2417BBBA0033312F /* BottomTabsBasePresenter.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = BottomTabsBasePresenter.h; sourceTree = "<group>"; };
702704
5041DC3D2417BBBA0033312F /* BottomTabsBasePresenter.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = BottomTabsBasePresenter.m; sourceTree = "<group>"; };
705+
5042FC9525EBABED0087F562 /* RNNNavigationBarDelegateHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNNavigationBarDelegateHandler.h; sourceTree = "<group>"; };
706+
5042FC9625EBABED0087F562 /* RNNNavigationBarDelegateHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNNavigationBarDelegateHandler.m; sourceTree = "<group>"; };
703707
50451D032042DAEB00695F00 /* RNNPushAnimation.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNPushAnimation.h; sourceTree = "<group>"; };
704708
50451D042042DAEB00695F00 /* RNNPushAnimation.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNPushAnimation.m; sourceTree = "<group>"; };
705709
50451D072042E20600695F00 /* RNNAnimationsOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNAnimationsOptions.h; sourceTree = "<group>"; };
@@ -1543,6 +1547,8 @@
15431547
50BAFE482399403200798674 /* Child View Controllers */,
15441548
50570BE82063E09B006A1B5C /* RNNTitleViewHelper.h */,
15451549
50570BE92063E09B006A1B5C /* RNNTitleViewHelper.m */,
1550+
5042FC9525EBABED0087F562 /* RNNNavigationBarDelegateHandler.h */,
1551+
5042FC9625EBABED0087F562 /* RNNNavigationBarDelegateHandler.m */,
15461552
503A8FEB25DD397400BB6A74 /* RNNIconCreator.h */,
15471553
503A8FEC25DD397400BB6A74 /* RNNIconCreator.m */,
15481554
503A90BB25DD550600BB6A74 /* RNNIconDrawer.h */,
@@ -1873,6 +1879,7 @@
18731879
50495939216E5750006D2B81 /* Bool.h in Headers */,
18741880
50C085EB259143F200B0502C /* RNNButtonsParser.h in Headers */,
18751881
7B1126A31E2D2B6C00F9B03B /* RNNSplashScreen.h in Headers */,
1882+
5042FC9725EBABED0087F562 /* RNNNavigationBarDelegateHandler.h in Headers */,
18761883
5038A3D2216E364C009280BC /* Text.h in Headers */,
18771884
261F0E641E6EC94900989DE2 /* RNNModalManager.h in Headers */,
18781885
50344D2823A03DB4004B6A7C /* BottomTabsAttachMode.h in Headers */,
@@ -2197,6 +2204,7 @@
21972204
503A8A1A23BCB2ED0094D1C4 /* RNNReactButtonView.m in Sources */,
21982205
50570BEB2063E09B006A1B5C /* RNNTitleViewHelper.m in Sources */,
21992206
263905E71E4CAC950023D7D3 /* RNNSideMenuChildVC.m in Sources */,
2207+
5042FC9825EBABED0087F562 /* RNNNavigationBarDelegateHandler.m in Sources */,
22002208
5082CC3423CDC3B800FD2B6A /* HorizontalTranslationTransition.m in Sources */,
22012209
50495957216F6B3D006D2B81 /* DictionaryParser.m in Sources */,
22022210
503A8A0223BB7B810094D1C4 /* ElementAnimator.m in Sources */,

0 commit comments

Comments
 (0)
Failed to load comments.