ソースを参照

Fix large title presentation (#5984)

* Fix largeTitle animation and crash

* Create button if not exist

* Prevents largeTitle transition crash

* Fix unit tests

* Set navigationBar.prefersLargeTitles true on stack initialization

* Bump minimum deployment target to iOS 11.0

* Add unit test
Yogev Ben David 4 年 前
コミット
54b285531e
No account linked to committer's email address

+ 1
- 0
lib/ios/RNNStackController.m ファイルの表示

@@ -12,6 +12,7 @@
12 12
     self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:childViewControllers];
13 13
     _stackDelegate = [[StackControllerDelegate alloc] initWithEventEmitter:self.eventEmitter];
14 14
     self.delegate = _stackDelegate;
15
+    self.navigationBar.prefersLargeTitles = YES;
15 16
     return self;
16 17
 }
17 18
 

+ 0
- 6
lib/ios/RNNStackPresenter.m ファイルの表示

@@ -62,7 +62,6 @@
62 62
     [_topBarPresenter applyOptions:withDefault.topBar];
63 63
     
64 64
     [stack setNavigationBarBlur:[withDefault.topBar.background.blur getWithDefaultValue:NO]];
65
-    [stack setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
66 65
     [stack setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds getWithDefaultValue:NO]];
67 66
     [stack setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
68 67
 	
@@ -79,7 +78,6 @@
79 78
 - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options {
80 79
     RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
81 80
     RNNStackController* navigationController = self.stackController;
82
-    [navigationController setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
83 81
     [_topBarPresenter applyOptionsBeforePopping:options.topBar];
84 82
 }
85 83
 
@@ -119,10 +117,6 @@
119 117
         [stack setNavigationBarBlur:[options.topBar.background.blur get]];
120 118
     }
121 119
     
122
-    if (options.topBar.largeTitle.visible.hasValue) {
123
-        [stack setNavigationBarLargeTitleVisible:options.topBar.largeTitle.visible.get];
124
-    }
125
-    
126 120
     if (options.topBar.backButton.color.hasValue) {
127 121
         [stack setBackButtonColor:options.topBar.backButton.color.get];
128 122
     }

+ 7
- 5
lib/ios/TopBarPresenter.m ファイルの表示

@@ -120,20 +120,22 @@
120 120
     NSNumber* fontSize = [backButtonOptions.fontSize getWithDefaultValue:nil];
121 121
     NSString* testID = [backButtonOptions.testID getWithDefaultValue:nil];
122 122
     
123
-	UIBarButtonItem *backItem = [[UIBarButtonItem alloc] init];
124
-    backItem.accessibilityIdentifier = testID;
125
-    
126 123
     NSArray* stackChildren = self.navigationController.viewControllers;
124
+    UIViewController *lastViewControllerInStack = stackChildren.count > 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController;
125
+    UIBarButtonItem *backItem = lastViewControllerInStack.navigationItem.backBarButtonItem ?: [UIBarButtonItem new];
126
+    backItem.accessibilityIdentifier = testID;
127
+
127 128
     icon = color
128 129
     ? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
129 130
     : icon;
130 131
     [self setBackIndicatorImage:icon withColor:color];
131 132
     
132
-    UIViewController *lastViewControllerInStack = stackChildren.count > 1 ? stackChildren[stackChildren.count - 2] : self.navigationController.topViewController;
133
-
134 133
     if (showTitle) {
135 134
         backItem.title = title ? title : lastViewControllerInStack.navigationItem.title;
135
+    } else {
136
+        backItem.title = @"";
136 137
     }
138
+    
137 139
     backItem.tintColor = color;
138 140
 	
139 141
     if (fontFamily) {

+ 0
- 2
lib/ios/UINavigationController+RNNOptions.h ファイルの表示

@@ -16,8 +16,6 @@
16 16
 
17 17
 - (void)setNavigationBarClipsToBounds:(BOOL)clipsToBounds;
18 18
 
19
-- (void)setNavigationBarLargeTitleVisible:(BOOL)visible;
20
-
21 19
 - (void)setBackButtonColor:(UIColor *)color;
22 20
 
23 21
 @end

+ 0
- 10
lib/ios/UINavigationController+RNNOptions.m ファイルの表示

@@ -33,16 +33,6 @@ const NSInteger BLUR_TOPBAR_TAG = 78264802;
33 33
 	self.navigationBar.barStyle = barStyle;
34 34
 }
35 35
 
36
-- (void)setNavigationBarLargeTitleVisible:(BOOL)visible {
37
-	if (@available(iOS 11.0, *)) {
38
-		if (visible){
39
-			self.navigationBar.prefersLargeTitles = YES;
40
-		} else {
41
-			self.navigationBar.prefersLargeTitles = NO;
42
-		}
43
-	}
44
-}
45
-
46 36
 - (void)setNavigationBarBlur:(BOOL)blur {
47 37
 	if (blur && ![self.navigationBar viewWithTag:BLUR_TOPBAR_TAG]) {
48 38
 		[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];

+ 4
- 0
playground/ios/NavigationTests/RNNStackControllerTest.m ファイルの表示

@@ -38,6 +38,10 @@
38 38
 	XCTAssertNotNil(self.uut.presenter);
39 39
 }
40 40
 
41
+- (void)testInitWithLayoutInfo_shouldPreferLargeTitle {
42
+	XCTAssertTrue(self.uut.navigationBar.prefersLargeTitles);
43
+}
44
+
41 45
 - (void)testInitWithLayoutInfo_shouldSetMultipleViewControllers {
42 46
 	self.uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:[[RNNNavigationOptions alloc] initWithDict:@{}] defaultOptions:nil presenter:[[RNNComponentPresenter alloc] init] eventEmitter:nil childViewControllers:@[_vc1, _vc2]];
43 47
 	XCTAssertTrue(self.uut.viewControllers.count == 2);

+ 4
- 9
playground/ios/NavigationTests/RNNStackPresenterTest.m ファイルの表示

@@ -44,19 +44,13 @@
44 44
 	XCTAssertTrue([_boundViewController.navigationBar.standardAppearance.backgroundColor isEqual:[UIColor redColor]]);
45 45
 }
46 46
 
47
-- (void)testApplyOptionsBeforePoppingShouldSetLargeTitleForPoppingViewController {
47
+- (void)testApplyOptionsShouldSetLargeTitleVisible {
48 48
 	_options.topBar.largeTitle.visible = [[Bool alloc] initWithBOOL:YES];
49 49
 	
50
-	[self.uut applyOptionsBeforePopping:self.options];
50
+	[self.uut applyOptions:self.options];
51 51
 	XCTAssertTrue([[_boundViewController navigationBar] prefersLargeTitles]);
52 52
 }
53 53
 
54
-- (void)testApplyOptionsBeforePoppingShouldSetDefaultLargeTitleFalseForPoppingViewController {
55
-	_options.topBar.largeTitle.visible = nil;
56
-	[self.uut applyOptionsBeforePopping:self.options];
57
-	XCTAssertFalse([[_boundViewController navigationBar] prefersLargeTitles]);
58
-}
59
-
60 54
 - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withTitle {
61 55
 	Text* title = [[Text alloc] initWithValue:@"Title"];
62 56
 	self.options.topBar.backButton.title = title;
@@ -69,7 +63,8 @@
69 63
 	self.options.topBar.backButton.title = title;
70 64
 	self.options.topBar.backButton.showTitle = [[Bool alloc] initWithValue:@(0)];
71 65
 	[self.uut applyOptions:self.options];
72
-	XCTAssertNil(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title);
66
+	NSLog(@"%@", self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title);
67
+	XCTAssertTrue([self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.title isEqualToString:@""]);
73 68
 }
74 69
 
75 70
 - (void)testApplyOptions_shouldSetBackButtonOnBoundViewController_withDefaultValues {

+ 2
- 0
playground/ios/playground.xcodeproj/project.pbxproj ファイルの表示

@@ -815,6 +815,7 @@
815 815
 				DEAD_CODE_STRIPPING = NO;
816 816
 				DEVELOPMENT_TEAM = XPHGA2FMQQ;
817 817
 				INFOPLIST_FILE = playground/Info.plist;
818
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
818 819
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
819 820
 				OTHER_LDFLAGS = (
820 821
 					"$(inherited)",
@@ -838,6 +839,7 @@
838 839
 				CODE_SIGN_STYLE = Automatic;
839 840
 				DEVELOPMENT_TEAM = XPHGA2FMQQ;
840 841
 				INFOPLIST_FILE = playground/Info.plist;
842
+				IPHONEOS_DEPLOYMENT_TARGET = 11.0;
841 843
 				LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
842 844
 				OTHER_LDFLAGS = (
843 845
 					"$(inherited)",