Преглед на файлове

Fix applying merged backButton options

The backButton options are always applied. Even when one of its values has changed in mergeOptions.
This commit adds a function to apply the backButton, and should probably replace the existing rnn_setBackButtonIcon - as that function does more than just set the icon, it sets all options.
Guy Carmeli преди 5 години
родител
ревизия
aef5b2e3bd

+ 2
- 0
lib/ios/RNNBackButtonOptions.h Целия файл

@@ -9,4 +9,6 @@
9 9
 @property (nonatomic, strong) Bool* showTitle;
10 10
 @property (nonatomic, strong) Bool* visible;
11 11
 
12
+- (BOOL)hasValue;
13
+
12 14
 @end

+ 8
- 0
lib/ios/RNNBackButtonOptions.m Целия файл

@@ -15,4 +15,12 @@
15 15
 	return self;
16 16
 }
17 17
 
18
+- (BOOL)hasValue {
19
+	return self.icon.hasValue ||
20
+			self.showTitle.hasValue ||
21
+			self.color.hasValue ||
22
+			self.title.hasValue;
23
+}
24
+
25
+
18 26
 @end

+ 5
- 3
lib/ios/RNNViewControllerPresenter.m Целия файл

@@ -161,9 +161,11 @@
161 161
 		[_customTitleView removeFromSuperview];
162 162
 		_customTitleView = nil;
163 163
 	}
164
-	
165
-	if (newOptions.topBar.backButton.icon.hasValue || newOptions.topBar.backButton.showTitle.hasValue || newOptions.topBar.backButton.color.hasValue || newOptions.topBar.backButton.title.hasValue) {
166
-		[viewController rnn_setBackButtonIcon:[newOptions.topBar.backButton.icon getWithDefaultValue:nil] withColor:[newOptions.topBar.backButton.color getWithDefaultValue:nil] title:[newOptions.topBar.backButton.showTitle getWithDefaultValue:YES] ? [newOptions.topBar.backButton.title getWithDefaultValue:nil] : @""];
164
+
165
+	if (newOptions.topBar.backButton.hasValue) {
166
+		UIViewController *lastViewControllerInStack = viewController.navigationController.viewControllers.count > 1 ? viewController.navigationController.viewControllers[viewController.navigationController.viewControllers.count - 2] : viewController.navigationController.topViewController;
167
+	    RNNNavigationOptions * resolvedOptions	= (RNNNavigationOptions *) [[currentOptions overrideOptions:newOptions] withDefault:[self defaultOptions]];
168
+		[lastViewControllerInStack applyBackButton:resolvedOptions.topBar.backButton];
167 169
 	}
168 170
 }
169 171
 

+ 3
- 0
lib/ios/UIViewController+RNNOptions.h Целия файл

@@ -2,6 +2,7 @@
2 2
 
3 3
 @class RNNBottomTabOptions;
4 4
 @class RNNNavigationOptions;
5
+@class RNNBackButtonOptions;
5 6
 
6 7
 @interface UIViewController (RNNOptions)
7 8
 
@@ -41,6 +42,8 @@
41 42
 
42 43
 - (void)rnn_setBackButtonIcon:(UIImage *)icon withColor:(UIColor *)color title:(NSString *)title;
43 44
 
45
+- (void)applyBackButton:(RNNBackButtonOptions *)backButton;
46
+
44 47
 - (BOOL)isModal;
45 48
 
46 49
 @end

+ 20
- 2
lib/ios/UIViewController+RNNOptions.m Целия файл

@@ -3,6 +3,7 @@
3 3
 #import "UIImage+tint.h"
4 4
 #import "RNNBottomTabOptions.h"
5 5
 #import "RNNNavigationOptions.h"
6
+#import "RNNBackButtonOptions.h"
6 7
 
7 8
 #define kStatusBarAnimationDuration 0.35
8 9
 const NSInteger BLUR_STATUS_TAG = 78264801;
@@ -177,12 +178,12 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
177 178
 		backItem.image = color
178 179
 		? [[icon withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]
179 180
 		: icon;
180
-		
181
+
181 182
 		[self.navigationController.navigationBar setBackIndicatorImage:[UIImage new]];
182 183
 		[self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
183 184
 	}
184 185
 	
185
-	UIViewController *lastViewControllerInStack = self.navigationController.viewControllers.count > 1 ? [self.navigationController.viewControllers objectAtIndex:self.navigationController.viewControllers.count-2] : self.navigationController.topViewController;
186
+	UIViewController *lastViewControllerInStack = self.navigationController.viewControllers.count > 1 ? self.navigationController.viewControllers[self.navigationController.viewControllers.count - 2] : self.navigationController.topViewController;
186 187
 	
187 188
 	backItem.title = title ? title : lastViewControllerInStack.navigationItem.title;
188 189
 	backItem.tintColor = color;
@@ -190,4 +191,21 @@ const NSInteger BLUR_STATUS_TAG = 78264801;
190 191
 	lastViewControllerInStack.navigationItem.backBarButtonItem = backItem;
191 192
 }
192 193
 
194
+- (void)applyBackButton:(RNNBackButtonOptions *)backButton {
195
+	UIBarButtonItem *backItem = [UIBarButtonItem new];
196
+	if (backButton.icon.hasValue) {
197
+		UIColor *color = [backButton.color getWithDefaultValue:nil];
198
+		backItem.image = color ?
199
+				[[backButton.icon.get withTintColor:color] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] :
200
+				backButton.icon.get;
201
+
202
+		[self.navigationController.navigationBar setBackIndicatorImage:[UIImage new]];
203
+        [self.navigationController.navigationBar setBackIndicatorTransitionMaskImage:[UIImage new]];
204
+	}
205
+
206
+	if ([backButton.showTitle getWithDefaultValue:YES]) backItem.title = [backButton.title getWithDefaultValue:nil];
207
+	if (backButton.color.hasValue) backItem.tintColor = [backButton.color get];
208
+	self.navigationItem.backBarButtonItem = backItem;
209
+}
210
+
193 211
 @end