Browse Source

Apply topBar appearance options on current child navigationItem (#5994)

This commit changes how stack child options are applied on iOS 13. Until now, options were applied directly to the navigationItem of the stack which is shared between all children.
This commit applies options on the navigationItem of each child instead. This fixes issues with color transitions when popping and pushing children to the stack.
Yogev Ben David 4 years ago
parent
commit
52108484cc
No account linked to committer's email address

+ 2
- 0
lib/ios/RNNBasePresenter.h View File

39
 
39
 
40
 - (void)componentDidDisappear;
40
 - (void)componentDidDisappear;
41
 
41
 
42
+- (UINavigationItem *)currentNavigationItem;
43
+
42
 - (UIStatusBarStyle)getStatusBarStyle:(RNNNavigationOptions *)resolvedOptions;
44
 - (UIStatusBarStyle)getStatusBarStyle:(RNNNavigationOptions *)resolvedOptions;
43
 
45
 
44
 - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options;
46
 - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options;

+ 4
- 0
lib/ios/RNNBasePresenter.m View File

110
     }
110
     }
111
 }
111
 }
112
 
112
 
113
+- (UINavigationItem *)currentNavigationItem {
114
+    return self.boundViewController.getCurrentChild.navigationItem;
115
+}
116
+
113
 - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
117
 - (UIInterfaceOrientationMask)getOrientation:(RNNNavigationOptions *)options {
114
     return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
118
     return [options withDefault:[self defaultOptions]].layout.supportedOrientations;
115
 }
119
 }

+ 3
- 0
lib/ios/RNNComponentViewController.m View File

8
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo rootViewCreator:(id<RNNComponentViewCreator>)creator eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNComponentPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions {
8
 - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo rootViewCreator:(id<RNNComponentViewCreator>)creator eventEmitter:(RNNEventEmitter *)eventEmitter presenter:(RNNComponentPresenter *)presenter options:(RNNNavigationOptions *)options defaultOptions:(RNNNavigationOptions *)defaultOptions {
9
 	self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];
9
 	self = [super initWithLayoutInfo:layoutInfo creator:creator options:options defaultOptions:defaultOptions presenter:presenter eventEmitter:eventEmitter childViewControllers:nil];
10
 	self.extendedLayoutIncludesOpaqueBars = YES;
10
 	self.extendedLayoutIncludesOpaqueBars = YES;
11
+    if (@available(iOS 13.0, *)) {
12
+        self.navigationItem.standardAppearance = [UINavigationBarAppearance new];
13
+    }
11
 	return self;
14
 	return self;
12
 }
15
 }
13
 
16
 

+ 24
- 15
lib/ios/TopBarAppearancePresenter.m View File

1
 #import "TopBarAppearancePresenter.h"
1
 #import "TopBarAppearancePresenter.h"
2
 #import "RNNFontAttributesCreator.h"
2
 #import "RNNFontAttributesCreator.h"
3
+#import "UIViewController+LayoutProtocol.h"
3
 
4
 
4
 @interface TopBarAppearancePresenter ()
5
 @interface TopBarAppearancePresenter ()
5
 
6
 
6
 @end
7
 @end
7
 
8
 
8
 
9
 
9
-@implementation TopBarAppearancePresenter {
10
-    UINavigationBarAppearance* _appearance;
10
+@implementation TopBarAppearancePresenter
11
+
12
+- (void)applyOptions:(RNNTopBarOptions *)options {
13
+    [self setTranslucent:[options.background.translucent getWithDefaultValue:NO]];
14
+    [self setBackgroundColor:[options.background.color getWithDefaultValue:nil]];
15
+    [self setTitleAttributes:options.title];
16
+    [self setLargeTitleAttributes:options.largeTitle];
17
+    [self showBorder:![options.noBorder getWithDefaultValue:NO]];
18
+    [self setBackButtonOptions:options.backButton];
11
 }
19
 }
12
 
20
 
13
-- (instancetype)initWithNavigationController:(UINavigationController *)boundNavigationController {
14
-    self = [super initWithNavigationController:boundNavigationController];
15
-    _appearance = boundNavigationController.navigationBar.standardAppearance ?: [UINavigationBarAppearance new];
16
-    boundNavigationController.navigationBar.standardAppearance = _appearance;
17
-    return self;
21
+- (void)applyOptionsBeforePopping:(RNNTopBarOptions *)options {
22
+    [self setBackgroundColor:[options.background.color getWithDefaultValue:nil]];
18
 }
23
 }
19
 
24
 
20
 - (void)setTranslucent:(BOOL)translucent {
25
 - (void)setTranslucent:(BOOL)translucent {
28
 
33
 
29
 - (void)updateBackgroundAppearance {
34
 - (void)updateBackgroundAppearance {
30
     if (self.transparent) {
35
     if (self.transparent) {
31
-        [_appearance configureWithTransparentBackground];
36
+        [self.getAppearance configureWithTransparentBackground];
32
     } else if (self.backgroundColor) {
37
     } else if (self.backgroundColor) {
33
-        [_appearance setBackgroundColor:self.backgroundColor];
38
+        [self.getAppearance setBackgroundColor:self.backgroundColor];
34
     } else if (self.translucent) {
39
     } else if (self.translucent) {
35
-        [_appearance configureWithDefaultBackground];
40
+        [self.getAppearance configureWithDefaultBackground];
36
     } else {
41
     } else {
37
-        [_appearance configureWithOpaqueBackground];
42
+        [self.getAppearance configureWithOpaqueBackground];
38
     }
43
     }
39
 }
44
 }
40
 
45
 
41
 - (void)showBorder:(BOOL)showBorder {
46
 - (void)showBorder:(BOOL)showBorder {
42
     UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
47
     UIColor* shadowColor = showBorder ? [[UINavigationBarAppearance new] shadowColor] : nil;
43
-    _appearance.shadowColor = shadowColor;
48
+    self.getAppearance.shadowColor = shadowColor;
44
 }
49
 }
45
 
50
 
46
 - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
51
 - (void)setBackIndicatorImage:(UIImage *)image withColor:(UIColor *)color {
47
-    [_appearance setBackIndicatorImage:image transitionMaskImage:image];
52
+    [self.getAppearance setBackIndicatorImage:image transitionMaskImage:image];
48
 }
53
 }
49
 
54
 
50
 - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
55
 - (void)setTitleAttributes:(RNNTitleOptions *)titleOptions {
53
     NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
58
     NSNumber* fontSize = [titleOptions.fontSize getWithDefaultValue:nil];
54
     UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
59
     UIColor* fontColor = [titleOptions.color getWithDefaultValue:nil];
55
     
60
     
56
-    _appearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
61
+    self.getAppearance.titleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.titleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
57
 }
62
 }
58
 
63
 
59
 - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
64
 - (void)setLargeTitleAttributes:(RNNLargeTitleOptions *)largeTitleOptions {
62
     NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
67
     NSNumber* fontSize = [largeTitleOptions.fontSize getWithDefaultValue:nil];
63
     UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
68
     UIColor* fontColor = [largeTitleOptions.color getWithDefaultValue:nil];
64
     
69
     
65
-    _appearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:_appearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
70
+    self.getAppearance.largeTitleTextAttributes = [RNNFontAttributesCreator createFromDictionary:self.getAppearance.largeTitleTextAttributes fontFamily:fontFamily fontSize:fontSize defaultFontSize:nil fontWeight:fontWeight color:fontColor defaultColor:nil];
71
+}
72
+
73
+- (UINavigationBarAppearance *)getAppearance {
74
+    return self.currentNavigationItem.standardAppearance;
66
 }
75
 }
67
 
76
 
68
 @end
77
 @end

+ 2
- 0
lib/ios/TopBarPresenter.h View File

13
 
13
 
14
 - (BOOL)transparent;
14
 - (BOOL)transparent;
15
 
15
 
16
+- (void)setBackButtonOptions:(RNNBackButtonOptions *)backButtonOptions;
17
+
16
 @property (nonatomic) BOOL translucent;
18
 @property (nonatomic) BOOL translucent;
17
 @property (nonatomic, strong) UIColor* backgroundColor;
19
 @property (nonatomic, strong) UIColor* backgroundColor;
18
 
20
 

+ 18
- 18
playground/ios/NavigationTests/RNNRootViewControllerTest.m View File

60
 	[self.uut viewWillAppear:false];
60
 	[self.uut viewWillAppear:false];
61
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
61
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
62
 
62
 
63
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.backgroundColor isEqual:expectedColor]);
63
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.backgroundColor isEqual:expectedColor]);
64
 }
64
 }
65
 
65
 
66
 - (void)testTopBarBackgroundColorWithoutNavigationController {
66
 - (void)testTopBarBackgroundColorWithoutNavigationController {
127
 	__unused RNNStackController* nav = [self createNavigationController];
127
 	__unused RNNStackController* nav = [self createNavigationController];
128
 	[self.uut viewWillAppear:false];
128
 	[self.uut viewWillAppear:false];
129
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
129
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
130
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
130
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
131
 }
131
 }
132
 
132
 
133
 - (void)testBackgroundColor_validColor {
133
 - (void)testBackgroundColor_validColor {
149
 	self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
149
 	self.options.topBar.title.fontFamily = [[Text alloc] initWithValue:inputFont];
150
 	[self.uut viewWillAppear:false];
150
 	[self.uut viewWillAppear:false];
151
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:17];
151
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:17];
152
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
152
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
153
 }
153
 }
154
 
154
 
155
 - (void)testTopBarHideOnScroll_true {
155
 - (void)testTopBarHideOnScroll_true {
165
 	self.options.topBar.background.translucent = [[Bool alloc] initWithValue:topBarTranslucentInput];
165
 	self.options.topBar.background.translucent = [[Bool alloc] initWithValue:topBarTranslucentInput];
166
 	__unused RNNStackController* nav = [self createNavigationController];
166
 	__unused RNNStackController* nav = [self createNavigationController];
167
 	[self.uut viewWillAppear:false];
167
 	[self.uut viewWillAppear:false];
168
-	XCTAssertTrue(CGColorEqualToColor(self.uut.navigationController.navigationBar.standardAppearance.shadowColor.CGColor, [UINavigationBarAppearance new].shadowColor.CGColor));
169
-	XCTAssertTrue(CGColorEqualToColor(self.uut.navigationController.navigationBar.standardAppearance.backgroundColor.CGColor, UIColor.systemBackgroundColor.CGColor));
168
+	XCTAssertTrue(CGColorEqualToColor(self.uut.navigationItem.standardAppearance.shadowColor.CGColor, [UINavigationBarAppearance new].shadowColor.CGColor));
169
+	XCTAssertTrue(CGColorEqualToColor(self.uut.navigationItem.standardAppearance.backgroundColor.CGColor, UIColor.systemBackgroundColor.CGColor));
170
 }
170
 }
171
 
171
 
172
 - (void)testTopBarTransparent {
172
 - (void)testTopBarTransparent {
218
 	UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"];
218
 	UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"];
219
 	[self.uut viewWillAppear:false];
219
 	[self.uut viewWillAppear:false];
220
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
220
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
221
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
221
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
222
 }
222
 }
223
 
223
 
224
 - (void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withTextColor {
224
 - (void)testTopBarLargeTitleFontSize_withoutTextFontFamily_withTextColor {
231
 	[self.uut viewWillAppear:false];
231
 	[self.uut viewWillAppear:false];
232
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
232
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
233
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
233
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
234
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
235
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
234
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
235
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
236
 }
236
 }
237
 
237
 
238
 - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withTextColor {
238
 - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withTextColor {
247
 	[self.uut viewWillAppear:false];
247
 	[self.uut viewWillAppear:false];
248
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
248
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
249
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
249
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
250
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
251
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
250
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
251
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSColor"] isEqual:expectedColor]);
252
 }
252
 }
253
 
253
 
254
 - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withoutTextColor {
254
 - (void)testTopBarLargeTitleFontSize_withTextFontFamily_withoutTextColor {
259
 	__unused RNNStackController* nav = [self createNavigationController];
259
 	__unused RNNStackController* nav = [self createNavigationController];
260
 	[self.uut viewWillAppear:false];
260
 	[self.uut viewWillAppear:false];
261
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
261
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
262
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
262
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.largeTitleTextAttributes[@"NSFont"] isEqual:expectedFont]);
263
 }
263
 }
264
 
264
 
265
 
265
 
270
 	UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"];
270
 	UIFont* initialFont = self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"];
271
 	[self.uut viewWillAppear:false];
271
 	[self.uut viewWillAppear:false];
272
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
272
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
273
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
273
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
274
 }
274
 }
275
 
275
 
276
 - (void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
276
 - (void)testTopBarTextFontSize_withoutTextFontFamily_withTextColor {
283
 	[self.uut viewWillAppear:false];
283
 	[self.uut viewWillAppear:false];
284
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
284
 	UIFont* expectedFont = [UIFont fontWithDescriptor:initialFont.fontDescriptor size:topBarTextFontSizeInput.floatValue];
285
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
285
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
286
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
287
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
286
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
287
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
288
 }
288
 }
289
 
289
 
290
 - (void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
290
 - (void)testTopBarTextFontSize_withTextFontFamily_withTextColor {
298
 	[self.uut viewWillAppear:false];
298
 	[self.uut viewWillAppear:false];
299
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
299
 	UIColor* expectedColor = [UIColor colorWithRed:1 green:0 blue:0 alpha:1];
300
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
300
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
301
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
302
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
301
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
302
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSColor"] isEqual:expectedColor]);
303
 }
303
 }
304
 
304
 
305
 - (void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
305
 - (void)testTopBarTextFontSize_withTextFontFamily_withoutTextColor {
310
 	__unused RNNStackController* nav = [self createNavigationController];
310
 	__unused RNNStackController* nav = [self createNavigationController];
311
 	[self.uut viewWillAppear:false];
311
 	[self.uut viewWillAppear:false];
312
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
312
 	UIFont* expectedFont = [UIFont fontWithName:inputFont size:15];
313
-	XCTAssertTrue([self.uut.navigationController.navigationBar.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
313
+	XCTAssertTrue([self.uut.navigationItem.standardAppearance.titleTextAttributes[@"NSFont"] isEqual:expectedFont]);
314
 }
314
 }
315
 
315
 
316
 // TODO: Currently not passing
316
 // TODO: Currently not passing
468
 	self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
468
 	self.options.topBar.noBorder = [[Bool alloc] initWithValue:topBarNoBorderInput];
469
 	__unused RNNStackController* nav = [self createNavigationController];
469
 	__unused RNNStackController* nav = [self createNavigationController];
470
 	[self.uut viewWillAppear:false];
470
 	[self.uut viewWillAppear:false];
471
-	XCTAssertNil(self.uut.navigationController.navigationBar.standardAppearance.shadowColor);
471
+	XCTAssertNil(self.uut.navigationItem.standardAppearance.shadowColor);
472
 }
472
 }
473
 
473
 
474
 - (void)testTopBarNoBorderOff {
474
 - (void)testTopBarNoBorderOff {

+ 2
- 1
playground/ios/NavigationTests/RNNStackControllerTest.m View File

137
 	[_vc1 overrideOptions:_options];
137
 	[_vc1 overrideOptions:_options];
138
 	
138
 	
139
 	[self.uut popViewControllerAnimated:NO];
139
 	[self.uut popViewControllerAnimated:NO];
140
-	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.navigationBar.standardAppearance.backgroundColor);
140
+	[_vc1 viewWillAppear:YES];
141
+	XCTAssertEqual(_vc1.resolveOptions.topBar.background.color.get, self.uut.childViewControllers.lastObject.navigationItem.standardAppearance.backgroundColor);
141
 }
142
 }
142
 
143
 
143
 - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {
144
 - (void)testPopViewControllerSetDefaultTopBarBackgroundForPoppingViewController {

+ 5
- 4
playground/ios/NavigationTests/RNNStackPresenterTest.m View File

1
 #import <XCTest/XCTest.h>
1
 #import <XCTest/XCTest.h>
2
 #import <OCMock/OCMock.h>
2
 #import <OCMock/OCMock.h>
3
-#import "RNNStackPresenter.h"
3
+#import <ReactNativeNavigation/RNNStackPresenter.h>
4
 #import "UINavigationController+RNNOptions.h"
4
 #import "UINavigationController+RNNOptions.h"
5
 #import "RNNStackController.h"
5
 #import "RNNStackController.h"
6
 #import "UIImage+Utils.h"
6
 #import "UIImage+Utils.h"
7
+#import "RNNComponentViewController+Utils.h"
7
 
8
 
8
 @interface RNNStackPresenterTest : XCTestCase
9
 @interface RNNStackPresenterTest : XCTestCase
9
 
10
 
18
 - (void)setUp {
19
 - (void)setUp {
19
 	[super setUp];
20
 	[super setUp];
20
 	self.uut = [[RNNStackPresenter alloc] init];
21
 	self.uut = [[RNNStackPresenter alloc] init];
21
-	RNNStackController* stackController = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:self.uut eventEmitter:nil childViewControllers:@[[UIViewController new], [UIViewController new]]];
22
+	RNNStackController* stackController = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil presenter:self.uut eventEmitter:nil childViewControllers:@[[RNNComponentViewController createWithComponentId:@"component1"], [RNNComponentViewController createWithComponentId:@"component2"]]];
22
 	self.boundViewController = [OCMockObject partialMockForObject:stackController];
23
 	self.boundViewController = [OCMockObject partialMockForObject:stackController];
23
     [self.uut bindViewController:self.boundViewController];
24
     [self.uut bindViewController:self.boundViewController];
24
 	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
25
 	self.options = [[RNNNavigationOptions alloc] initEmptyOptions];
41
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
42
 	_options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]];
42
 	
43
 	
43
 	[self.uut applyOptionsBeforePopping:self.options];
44
 	[self.uut applyOptionsBeforePopping:self.options];
44
-	XCTAssertTrue([_boundViewController.navigationBar.standardAppearance.backgroundColor isEqual:[UIColor redColor]]);
45
+	XCTAssertTrue([_boundViewController.childViewControllers.lastObject.navigationItem.standardAppearance.backgroundColor isEqual:[UIColor redColor]]);
45
 }
46
 }
46
 
47
 
47
 - (void)testApplyOptionsShouldSetLargeTitleVisible {
48
 - (void)testApplyOptionsShouldSetLargeTitleVisible {
98
 	self.options.topBar.backButton.icon = icon;
99
 	self.options.topBar.backButton.icon = icon;
99
 	[self.uut applyOptions:self.options];
100
 	[self.uut applyOptions:self.options];
100
 	XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
101
 	XCTAssertEqual(self.boundViewController.viewControllers.firstObject.navigationItem.backBarButtonItem.tintColor, UIColor.redColor);
101
-	XCTAssertTrue([self.boundViewController.navigationBar.standardAppearance.backIndicatorImage isEqual:image]);
102
+	XCTAssertTrue([self.boundViewController.viewControllers.lastObject.navigationItem.standardAppearance.backIndicatorImage isEqual:image]);
102
 }
103
 }
103
 
104
 
104
 - (void)testBackgroundColor_validColor {
105
 - (void)testBackgroundColor_validColor {

+ 4
- 3
playground/ios/NavigationTests/TopBarAppearancePresenterTest.m View File

4
 #import "UIViewController+RNNOptions.h"
4
 #import "UIViewController+RNNOptions.h"
5
 #import <ReactNativeNavigation/RNNStackController.h>
5
 #import <ReactNativeNavigation/RNNStackController.h>
6
 #import <ReactNativeNavigation/RNNComponentViewController.h>
6
 #import <ReactNativeNavigation/RNNComponentViewController.h>
7
+#import "RNNComponentViewController+Utils.h"
7
 
8
 
8
 @interface TopBarAppearancePresenterTest : XCTestCase
9
 @interface TopBarAppearancePresenterTest : XCTestCase
9
 
10
 
17
 
18
 
18
 - (void)setUp {
19
 - (void)setUp {
19
     [super setUp];
20
     [super setUp];
20
-	_componentViewController = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil presenter:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:nil];
21
+	_componentViewController = [RNNComponentViewController createWithComponentId:@"componentId"];
21
 	_stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[_componentViewController]];
22
 	_stack = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil options:[[RNNNavigationOptions alloc] initEmptyOptions] defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] presenter:_uut eventEmitter:nil childViewControllers:@[_componentViewController]];
22
 	_uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack];
23
 	_uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack];
23
 }
24
 }
30
 	mergeOptions.topBar.title.fontSize = [Number withValue:@(21)];
31
 	mergeOptions.topBar.title.fontSize = [Number withValue:@(21)];
31
 	RNNNavigationOptions* withDefault = [mergeOptions withDefault:defaultOptions];
32
 	RNNNavigationOptions* withDefault = [mergeOptions withDefault:defaultOptions];
32
 	[_uut mergeOptions:mergeOptions.topBar withDefault:withDefault.topBar];
33
 	[_uut mergeOptions:mergeOptions.topBar withDefault:withDefault.topBar];
33
-	XCTAssertEqual(_stack.navigationBar.standardAppearance.titleTextAttributes[NSForegroundColorAttributeName], UIColor.redColor);
34
-	UIFont* font = _stack.navigationBar.standardAppearance.titleTextAttributes[NSFontAttributeName];
34
+	XCTAssertEqual(_stack.childViewControllers.lastObject.navigationItem.standardAppearance.titleTextAttributes[NSForegroundColorAttributeName], UIColor.redColor);
35
+	UIFont* font = _stack.childViewControllers.lastObject.navigationItem.standardAppearance.titleTextAttributes[NSFontAttributeName];
35
 	XCTAssertEqual(font.pointSize, 21);
36
 	XCTAssertEqual(font.pointSize, 21);
36
 }
37
 }
37
 
38
 

+ 8
- 0
playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.h View File

1
+#import <ReactNativeNavigation/ReactNativeNavigation.h>
2
+#import <ReactNativeNavigation/RNNComponentViewController.h>
3
+
4
+@interface RNNComponentViewController (Utils)
5
+
6
++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId;
7
+
8
+@end

+ 11
- 0
playground/ios/NavigationTests/utils/RNNComponentViewController+Utils.m View File

1
+#import "RNNComponentViewController+Utils.h"
2
+
3
+@implementation RNNComponentViewController (Utils)
4
+
5
++ (RNNComponentViewController *)createWithComponentId:(NSString *)componentId {
6
+	RNNLayoutInfo* layoutInfo = [[RNNLayoutInfo alloc] init];
7
+	layoutInfo.componentId = componentId;
8
+	return [[RNNComponentViewController alloc] initWithLayoutInfo:layoutInfo rootViewCreator:nil eventEmitter:nil presenter:nil options:nil defaultOptions:nil];
9
+}
10
+
11
+@end

+ 6
- 0
playground/ios/playground.xcodeproj/project.pbxproj View File

19
 		50996C6823AA477400008F89 /* RNNRootViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */; };
19
 		50996C6823AA477400008F89 /* RNNRootViewControllerTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */; };
20
 		50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; };
20
 		50996C6923AA487800008F89 /* RNNTestRootViewCreator.m in Sources */ = {isa = PBXBuildFile; fileRef = E58D263D2385888C003F36BA /* RNNTestRootViewCreator.m */; };
21
 		50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */; };
21
 		50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */; };
22
+		50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */; };
22
 		67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; };
23
 		67C681D42B662A53F29C19DA /* Pods_NavigationIOS12Tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DEE0B5D45FD34FBABC6586CF /* Pods_NavigationIOS12Tests.framework */; };
23
 		9D204F3DC4FBCD81583BF99F /* Pods_playground.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3340545EAAF11C1F146864 /* Pods_playground.framework */; };
24
 		9D204F3DC4FBCD81583BF99F /* Pods_playground.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A3340545EAAF11C1F146864 /* Pods_playground.framework */; };
24
 		E5046080227748EA00212BD8 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E504607F227748EA00212BD8 /* JavaScriptCore.framework */; };
25
 		E5046080227748EA00212BD8 /* JavaScriptCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E504607F227748EA00212BD8 /* JavaScriptCore.framework */; };
92
 		50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
93
 		50996C6123AA46DD00008F89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
93
 		50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
94
 		50996C6723AA477400008F89 /* RNNRootViewControllerTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNRootViewControllerTest.m; sourceTree = "<group>"; };
94
 		50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TopBarAppearancePresenterTest.m; sourceTree = "<group>"; };
95
 		50BCB27523F1A26600D6C8E5 /* TopBarAppearancePresenterTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = TopBarAppearancePresenterTest.m; sourceTree = "<group>"; };
96
+		50C9A8D2240FB9D000BD699F /* RNNComponentViewController+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNComponentViewController+Utils.h"; sourceTree = "<group>"; };
97
+		50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNComponentViewController+Utils.m"; sourceTree = "<group>"; };
95
 		7F8E255E2E08F6ECE7DF6FE3 /* Pods-playground.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.release.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.release.xcconfig"; sourceTree = "<group>"; };
98
 		7F8E255E2E08F6ECE7DF6FE3 /* Pods-playground.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.release.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.release.xcconfig"; sourceTree = "<group>"; };
96
 		84E32151E3A71C2B7328BCB4 /* Pods_NavigationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NavigationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
99
 		84E32151E3A71C2B7328BCB4 /* Pods_NavigationTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_NavigationTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
97
 		B484A10A046B0046B98A76B5 /* Pods-playground.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.debug.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.debug.xcconfig"; sourceTree = "<group>"; };
100
 		B484A10A046B0046B98A76B5 /* Pods-playground.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-playground.debug.xcconfig"; path = "Target Support Files/Pods-playground/Pods-playground.debug.xcconfig"; sourceTree = "<group>"; };
293
 				E58D26302385888B003F36BA /* RNNTestBase.h */,
296
 				E58D26302385888B003F36BA /* RNNTestBase.h */,
294
 				501C86B7239FE9C400E0B631 /* UIImage+Utils.h */,
297
 				501C86B7239FE9C400E0B631 /* UIImage+Utils.h */,
295
 				501C86B8239FE9C400E0B631 /* UIImage+Utils.m */,
298
 				501C86B8239FE9C400E0B631 /* UIImage+Utils.m */,
299
+				50C9A8D2240FB9D000BD699F /* RNNComponentViewController+Utils.h */,
300
+				50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */,
296
 			);
301
 			);
297
 			path = utils;
302
 			path = utils;
298
 			sourceTree = "<group>";
303
 			sourceTree = "<group>";
747
 				E58D265B2385888C003F36BA /* UIViewController+RNNOptionsTest.m in Sources */,
752
 				E58D265B2385888C003F36BA /* UIViewController+RNNOptionsTest.m in Sources */,
748
 				E58D26532385888C003F36BA /* RNNSideMenuPresenterTest.m in Sources */,
753
 				E58D26532385888C003F36BA /* RNNSideMenuPresenterTest.m in Sources */,
749
 				50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */,
754
 				50BCB27623F1A2B100D6C8E5 /* TopBarAppearancePresenterTest.m in Sources */,
755
+				50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */,
750
 				50647FE323E3196800B92025 /* RNNExternalViewControllerTests.m in Sources */,
756
 				50647FE323E3196800B92025 /* RNNExternalViewControllerTests.m in Sources */,
751
 				E58D264D2385888C003F36BA /* RNNOverlayManagerTest.m in Sources */,
757
 				E58D264D2385888C003F36BA /* RNNOverlayManagerTest.m in Sources */,
752
 				501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */,
758
 				501C86B9239FE9C400E0B631 /* UIImage+Utils.m in Sources */,