Sfoglia il codice sorgente

Propagate new defaultOptions to presenters (#5404)

When defaultOptions are set after setRoot has been called presenters need to receive the default options as well,
otherwise the outdated default options are regarded.
Fixes #5395
Guy Carmeli 5 anni fa
parent
commit
338b0961f9
No account linked to committer's email address

+ 2
- 2
e2e/Options.test.js Vedi File

@@ -56,9 +56,9 @@ describe('Options', () => {
56 56
     await elementById(TestIDs.HIDE_TOPBAR_DEFAULT_OPTIONS).tap();
57 57
     await expect(elementById(TestIDs.TOP_BAR)).toBeVisible();
58 58
     await elementById(TestIDs.PUSH_BTN).tap();
59
-    await expect(elementById(TestIDs.TOP_BAR)).toBeNotVisible();
59
+    await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeNotVisible();
60 60
     await elementById(TestIDs.PUSH_BTN).tap();
61
-    await expect(elementById(TestIDs.TOP_BAR)).toBeNotVisible();
61
+    await expect(elementById(TestIDs.PUSHED_SCREEN_HEADER)).toBeNotVisible();
62 62
   });
63 63
 
64 64
   it('default options should not override static options', async () => {

+ 4
- 0
lib/ios/RNNBasePresenter.h Vedi File

@@ -8,10 +8,14 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void);
8 8
 
9 9
 @property(nonatomic, strong) NSString *boundComponentId;
10 10
 
11
+@property(nonatomic, strong) RNNNavigationOptions * defaultOptions;
12
+
11 13
 - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions;
12 14
 
13 15
 - (void)bindViewController:(UIViewController *)boundViewController;
14 16
 
17
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions;
18
+
15 19
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions;
16 20
 
17 21
 - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options;

+ 4
- 1
lib/ios/RNNBasePresenter.m Vedi File

@@ -8,7 +8,6 @@
8 8
 
9 9
 @interface RNNBasePresenter ()
10 10
 @property(nonatomic, strong) RNNDotIndicatorPresenter* dotIndicatorPresenter;
11
-@property(nonatomic, strong) RNNNavigationOptions* defaultOptions;
12 11
 @end
13 12
 @implementation RNNBasePresenter
14 13
 
@@ -24,6 +23,10 @@
24 23
     _boundViewController = boundViewController;
25 24
 }
26 25
 
26
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
27
+    _defaultOptions = defaultOptions;
28
+}
29
+
27 30
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
28 31
 
29 32
 }

+ 3
- 6
lib/ios/RNNCommandsHandler.m Vedi File

@@ -1,15 +1,12 @@
1 1
 #import "RNNCommandsHandler.h"
2
-#import "RNNNavigationOptions.h"
3 2
 #import "RNNRootViewController.h"
4
-#import "RNNSplitViewController.h"
5
-#import "RNNElementFinder.h"
6
-#import "React/RCTUIManager.h"
7 3
 #import "RNNErrorHandler.h"
8 4
 #import "RNNDefaultOptionsHelper.h"
9 5
 #import "UIViewController+RNNOptions.h"
10 6
 #import "React/RCTI18nUtil.h"
11 7
 #import "UIViewController+LayoutProtocol.h"
12 8
 #import "RNNLayoutManager.h"
9
+#import "UIViewController+Utils.h"
13 10
 
14 11
 static NSString* const setRoot	= @"setRoot";
15 12
 static NSString* const setStackRoot	= @"setStackRoot";
@@ -86,7 +83,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
86 83
 - (void)mergeOptions:(NSString*)componentId options:(NSDictionary*)mergeOptions completion:(RNNTransitionCompletionBlock)completion {
87 84
 	[self assertReady];
88 85
 	
89
-	UIViewController<RNNLayoutProtocol>* vc = (UIViewController<RNNLayoutProtocol>*)[RNNLayoutManager findComponentForId:componentId];
86
+	UIViewController<RNNLayoutProtocol>* vc = [RNNLayoutManager findComponentForId:componentId];
90 87
 	RNNNavigationOptions* newOptions = [[RNNNavigationOptions alloc] initWithDict:mergeOptions];
91 88
 	if ([vc conformsToProtocol:@protocol(RNNLayoutProtocol)] || [vc isKindOfClass:[RNNRootViewController class]]) {
92 89
 		[CATransaction begin];
@@ -106,7 +103,7 @@ static NSString* const setDefaultOptions	= @"setDefaultOptions";
106 103
 	
107 104
 	UIViewController *rootViewController = UIApplication.sharedApplication.delegate.window.rootViewController;
108 105
 	[RNNDefaultOptionsHelper recrusivelySetDefaultOptions:defaultOptions onRootViewController:rootViewController];
109
-	
106
+
110 107
 	completion();
111 108
 }
112 109
 

+ 5
- 1
lib/ios/RNNNavigationController.m Vedi File

@@ -1,11 +1,15 @@
1 1
 #import "RNNNavigationController.h"
2 2
 #import "RNNRootViewController.h"
3
-#import "InteractivePopGestureDelegate.h"
4 3
 
5 4
 const NSInteger TOP_BAR_TRANSPARENT_TAG = 78264803;
6 5
 
7 6
 @implementation RNNNavigationController
8 7
 
8
+-(void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
9
+	[super setDefaultOptions:defaultOptions];
10
+	[self.presenter setDefaultOptions:defaultOptions];
11
+}
12
+
9 13
 - (void)viewDidLayoutSubviews {
10 14
 	[super viewDidLayoutSubviews];
11 15
 	[self.presenter applyOptionsOnViewDidLayoutSubviews:self.resolveOptions];

+ 22
- 25
lib/ios/RNNNavigationControllerPresenter.m Vedi File

@@ -1,9 +1,7 @@
1 1
 #import "RNNNavigationControllerPresenter.h"
2 2
 #import "UINavigationController+RNNOptions.h"
3 3
 #import "RNNNavigationController.h"
4
-#import <React/RCTConvert.h>
5 4
 #import "RNNCustomTitleView.h"
6
-#import "UIViewController+LayoutProtocol.h"
7 5
 
8 6
 @interface RNNNavigationControllerPresenter() {
9 7
 	RNNReactComponentRegistry* _componentRegistry;
@@ -25,44 +23,43 @@
25 23
 	[super applyOptions:options];
26 24
 	
27 25
 	RNNNavigationController* navigationController = self.boundViewController;
26
+	RNNNavigationOptions * withDefault = [options withDefault:[self defaultOptions]];
28 27
 	
29 28
 	self.interactivePopGestureDelegate = [InteractivePopGestureDelegate new];
30 29
 	self.interactivePopGestureDelegate.navigationController = navigationController;
31 30
 	self.interactivePopGestureDelegate.originalDelegate = navigationController.interactivePopGestureRecognizer.delegate;
32 31
 	navigationController.interactivePopGestureRecognizer.delegate = self.interactivePopGestureDelegate;
33 32
 	
34
-	[navigationController rnn_setInteractivePopGestureEnabled:[options.popGesture getWithDefaultValue:YES]];
35
-	[navigationController rnn_setRootBackgroundImage:[options.rootBackgroundImage getWithDefaultValue:nil]];
36
-	[navigationController rnn_setNavigationBarTestID:[options.topBar.testID getWithDefaultValue:nil]];
37
-	[navigationController rnn_setNavigationBarVisible:[options.topBar.visible getWithDefaultValue:YES] animated:[options.topBar.animate getWithDefaultValue:YES]];
38
-	[navigationController rnn_hideBarsOnScroll:[options.topBar.hideOnScroll getWithDefaultValue:NO]];
39
-	[navigationController rnn_setNavigationBarNoBorder:[options.topBar.noBorder getWithDefaultValue:NO]];
40
-	[navigationController rnn_setBarStyle:[RCTConvert UIBarStyle:[options.topBar.barStyle getWithDefaultValue:@"default"]]];
41
-	[navigationController rnn_setNavigationBarTranslucent:[options.topBar.background.translucent getWithDefaultValue:NO]];
42
-	[navigationController rnn_setNavigationBarClipsToBounds:[options.topBar.background.clipToBounds getWithDefaultValue:NO]];
43
-	[navigationController rnn_setNavigationBarBlur:[options.topBar.background.blur getWithDefaultValue:NO]];
44
-	[navigationController setTopBarBackgroundColor:[options.topBar.background.color getWithDefaultValue:nil]];
45
-	[navigationController rnn_setNavigationBarLargeTitleVisible:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
46
-	[navigationController rnn_setNavigationBarLargeTitleFontFamily:[options.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[options.topBar.largeTitle.color getWithDefaultValue:nil]];
47
-	[navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:nil] color:[options.topBar.title.color getWithDefaultValue:nil]];
48
-	[navigationController rnn_setBackButtonColor:[options.topBar.backButton.color getWithDefaultValue:nil]];
49
-}
50
-
51
-- (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
52
-	[super applyOptionsOnWillMoveToParentViewController:options];
33
+	[navigationController rnn_setInteractivePopGestureEnabled:[withDefault.popGesture getWithDefaultValue:YES]];
34
+	[navigationController rnn_setRootBackgroundImage:[withDefault.rootBackgroundImage getWithDefaultValue:nil]];
35
+	[navigationController rnn_setNavigationBarTestID:[withDefault.topBar.testID getWithDefaultValue:nil]];
36
+	[navigationController rnn_setNavigationBarVisible:[withDefault.topBar.visible getWithDefaultValue:YES] animated:[withDefault.topBar.animate getWithDefaultValue:YES]];
37
+	[navigationController rnn_hideBarsOnScroll:[withDefault.topBar.hideOnScroll getWithDefaultValue:NO]];
38
+	[navigationController rnn_setNavigationBarNoBorder:[withDefault.topBar.noBorder getWithDefaultValue:NO]];
39
+	[navigationController rnn_setBarStyle:[RCTConvert UIBarStyle:[withDefault.topBar.barStyle getWithDefaultValue:@"default"]]];
40
+	[navigationController rnn_setNavigationBarTranslucent:[withDefault.topBar.background.translucent getWithDefaultValue:NO]];
41
+	[navigationController rnn_setNavigationBarClipsToBounds:[withDefault.topBar.background.clipToBounds getWithDefaultValue:NO]];
42
+	[navigationController rnn_setNavigationBarBlur:[withDefault.topBar.background.blur getWithDefaultValue:NO]];
43
+	[navigationController setTopBarBackgroundColor:[withDefault.topBar.background.color getWithDefaultValue:nil]];
44
+	[navigationController rnn_setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
45
+	[navigationController rnn_setNavigationBarLargeTitleFontFamily:[withDefault.topBar.largeTitle.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.largeTitle.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.largeTitle.color getWithDefaultValue:nil]];
46
+	[navigationController rnn_setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:nil]];
47
+	[navigationController rnn_setBackButtonColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil]];
53 48
 }
54 49
 
55 50
 - (void)applyOptionsOnViewDidLayoutSubviews:(RNNNavigationOptions *)options {
56
-	if (options.topBar.background.component.name.hasValue) {
51
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
52
+	if (withDefault.topBar.background.component.name.hasValue) {
57 53
 		[self presentBackgroundComponent];
58 54
 	}
59 55
 }
60 56
 
61 57
 - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options {
58
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
62 59
 	RNNNavigationController* navigationController = self.boundViewController;
63
-	[navigationController setTopBarBackgroundColor:[options.topBar.background.color getWithDefaultValue:nil]];
64
-	[navigationController rnn_setNavigationBarFontFamily:[options.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[options.topBar.title.fontSize getWithDefaultValue:nil] color:[options.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
65
-	[navigationController rnn_setNavigationBarLargeTitleVisible:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
60
+	[navigationController setTopBarBackgroundColor:[withDefault.topBar.background.color getWithDefaultValue:nil]];
61
+	[navigationController rnn_setNavigationBarFontFamily:[withDefault.topBar.title.fontFamily getWithDefaultValue:nil] fontSize:[withDefault.topBar.title.fontSize getWithDefaultValue:nil] color:[withDefault.topBar.title.color getWithDefaultValue:[UIColor blackColor]]];
62
+	[navigationController rnn_setNavigationBarLargeTitleVisible:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
66 63
 }
67 64
 
68 65
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {

+ 4
- 0
lib/ios/RNNRootViewController.m Vedi File

@@ -27,6 +27,10 @@
27 27
 	[viewController didMoveToParentViewController:self];
28 28
 }
29 29
 
30
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
31
+	[_presenter setDefaultOptions:defaultOptions];
32
+}
33
+
30 34
 - (void)mergeOptions:(RNNNavigationOptions *)options {
31 35
 	[_presenter mergeOptions:options currentOptions:self.options];
32 36
 	[self.parentViewController mergeOptions:options];

+ 4
- 0
lib/ios/RNNSideMenuController.m Vedi File

@@ -34,6 +34,10 @@
34 34
 	return self;
35 35
 }
36 36
 
37
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
38
+	[self.presenter setDefaultOptions:defaultOptions];
39
+}
40
+
37 41
 - (void)setAnimationType:(NSString *)animationType {
38 42
 	MMDrawerControllerDrawerVisualStateBlock animationTypeStateBlock = nil;
39 43
 	if ([animationType isEqualToString:@"door"]) animationTypeStateBlock = [MMDrawerVisualState swingingDoorVisualStateBlock];

+ 26
- 25
lib/ios/RNNSideMenuPresenter.m Vedi File

@@ -10,52 +10,53 @@
10 10
 
11 11
 - (void)applyOptions:(RNNNavigationOptions *)options {
12 12
 	[super applyOptions:options];
13
-		
13
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
14 14
 	RNNSideMenuController* sideMenuController = self.boundViewController;
15
+
16
+	[sideMenuController side:MMDrawerSideLeft enabled:[withDefault.sideMenu.left.enabled getWithDefaultValue:YES]];
17
+	[sideMenuController side:MMDrawerSideRight enabled:[withDefault.sideMenu.right.enabled getWithDefaultValue:YES]];
15 18
 	
16
-	[sideMenuController side:MMDrawerSideLeft enabled:[options.sideMenu.left.enabled getWithDefaultValue:YES]];
17
-	[sideMenuController side:MMDrawerSideRight enabled:[options.sideMenu.right.enabled getWithDefaultValue:YES]];
18
-	
19
-	[sideMenuController setShouldStretchLeftDrawer:[options.sideMenu.left.shouldStretchDrawer getWithDefaultValue:YES]];
20
-	[sideMenuController setShouldStretchRightDrawer:[options.sideMenu.right.shouldStretchDrawer getWithDefaultValue:YES]];
19
+	[sideMenuController setShouldStretchLeftDrawer:[withDefault.sideMenu.left.shouldStretchDrawer getWithDefaultValue:YES]];
20
+	[sideMenuController setShouldStretchRightDrawer:[withDefault.sideMenu.right.shouldStretchDrawer getWithDefaultValue:YES]];
21 21
 	
22
-	[sideMenuController setAnimationVelocityLeft:[options.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]];
23
-	[sideMenuController setAnimationVelocityRight:[options.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]];
22
+	[sideMenuController setAnimationVelocityLeft:[withDefault.sideMenu.left.animationVelocity getWithDefaultValue:840.0f]];
23
+	[sideMenuController setAnimationVelocityRight:[withDefault.sideMenu.right.animationVelocity getWithDefaultValue:840.0f]];
24 24
 	
25
-	[sideMenuController setAnimationType:[options.sideMenu.animationType getWithDefaultValue:nil]];
25
+	[sideMenuController setAnimationType:[withDefault.sideMenu.animationType getWithDefaultValue:nil]];
26 26
 	
27
-	if (options.sideMenu.left.width.hasValue) {
28
-		[sideMenuController side:MMDrawerSideLeft width:options.sideMenu.left.width.get];
27
+	if (withDefault.sideMenu.left.width.hasValue) {
28
+		[sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get];
29 29
 	}
30 30
 	
31
-	if (options.sideMenu.right.width.hasValue) {
32
-		[sideMenuController side:MMDrawerSideRight width:options.sideMenu.right.width.get];
31
+	if (withDefault.sideMenu.right.width.hasValue) {
32
+		[sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get];
33 33
 	}
34 34
 	
35
-	if (options.sideMenu.left.visible.hasValue) {
36
-		[sideMenuController side:MMDrawerSideLeft visible:options.sideMenu.left.visible.get];
37
-		[options.sideMenu.left.visible consume];
35
+	if (withDefault.sideMenu.left.visible.hasValue) {
36
+		[sideMenuController side:MMDrawerSideLeft visible:withDefault.sideMenu.left.visible.get];
37
+		[withDefault.sideMenu.left.visible consume];
38 38
 	}
39 39
 	
40
-	if (options.sideMenu.right.visible.hasValue) {
41
-		[sideMenuController side:MMDrawerSideRight visible:options.sideMenu.right.visible.get];
42
-		[options.sideMenu.right.visible consume];
40
+	if (withDefault.sideMenu.right.visible.hasValue) {
41
+		[sideMenuController side:MMDrawerSideRight visible:withDefault.sideMenu.right.visible.get];
42
+		[withDefault.sideMenu.right.visible consume];
43 43
 	}
44 44
 }
45 45
 
46 46
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)initialOptions {
47 47
 	[super applyOptionsOnInit:initialOptions];
48
-	
48
+
49
+	RNNNavigationOptions *withDefault = [initialOptions withDefault:[self defaultOptions]];
49 50
 	RNNSideMenuController* sideMenuController = self.boundViewController;
50
-	if (initialOptions.sideMenu.left.width.hasValue) {
51
-		[sideMenuController side:MMDrawerSideLeft width:initialOptions.sideMenu.left.width.get];
51
+	if (withDefault.sideMenu.left.width.hasValue) {
52
+		[sideMenuController side:MMDrawerSideLeft width:withDefault.sideMenu.left.width.get];
52 53
 	}
53 54
 	
54
-	if (initialOptions.sideMenu.right.width.hasValue) {
55
-		[sideMenuController side:MMDrawerSideRight width:initialOptions.sideMenu.right.width.get];
55
+	if (withDefault.sideMenu.right.width.hasValue) {
56
+		[sideMenuController side:MMDrawerSideRight width:withDefault.sideMenu.right.width.get];
56 57
 	}
57 58
 
58
-		[sideMenuController setOpenDrawerGestureModeMask:[[initialOptions.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]];
59
+		[sideMenuController setOpenDrawerGestureModeMask:[[withDefault.sideMenu.openGestureMode getWithDefaultValue:@(MMOpenDrawerGestureModeAll)] integerValue]];
59 60
 }
60 61
 
61 62
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {

+ 10
- 13
lib/ios/RNNTabBarPresenter.m Vedi File

@@ -5,25 +5,22 @@
5 5
 
6 6
 @implementation RNNTabBarPresenter
7 7
 
8
--(instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions {
9
-    self = [super initWithDefaultOptions:defaultOptions];
10
-    return self;
11
-}
12
-
13 8
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
14 9
     UITabBarController *tabBarController = self.boundViewController;
15
-    [tabBarController rnn_setCurrentTabIndex:[options.bottomTabs.currentTabIndex getWithDefaultValue:0]];
10
+    RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
11
+    [tabBarController rnn_setCurrentTabIndex:[withDefault.bottomTabs.currentTabIndex getWithDefaultValue:0]];
16 12
 }
17 13
 
18 14
 - (void)applyOptions:(RNNNavigationOptions *)options {
19 15
     UITabBarController *tabBarController = self.boundViewController;
20
-
21
-    [tabBarController rnn_setTabBarTestID:[options.bottomTabs.testID getWithDefaultValue:nil]];
22
-    [tabBarController rnn_setTabBarBackgroundColor:[options.bottomTabs.backgroundColor getWithDefaultValue:nil]];
23
-    [tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]];
24
-    [tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]];
25
-    [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
26
-    [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
16
+    RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
17
+
18
+    [tabBarController rnn_setTabBarTestID:[withDefault.bottomTabs.testID getWithDefaultValue:nil]];
19
+    [tabBarController rnn_setTabBarBackgroundColor:[withDefault.bottomTabs.backgroundColor getWithDefaultValue:nil]];
20
+    [tabBarController rnn_setTabBarTranslucent:[withDefault.bottomTabs.translucent getWithDefaultValue:NO]];
21
+    [tabBarController rnn_setTabBarHideShadow:[withDefault.bottomTabs.hideShadow getWithDefaultValue:NO]];
22
+    [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[withDefault.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
23
+    [tabBarController rnn_setTabBarVisible:[withDefault.bottomTabs.visible getWithDefaultValue:YES] animated:[withDefault.bottomTabs.animate getWithDefaultValue:NO]];
27 24
 }
28 25
 
29 26
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions {

+ 26
- 25
lib/ios/RNNViewControllerPresenter.m Vedi File

@@ -2,8 +2,6 @@
2 2
 #import "UIViewController+RNNOptions.h"
3 3
 #import "UITabBarController+RNNOptions.h"
4 4
 #import "RCTConvert+Modal.h"
5
-#import "RNNReactView.h"
6
-#import "RNNCustomTitleView.h"
7 5
 #import "RNNTitleViewHelper.h"
8 6
 #import "UIViewController+LayoutProtocol.h"
9 7
 
@@ -31,48 +29,51 @@
31 29
 - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)options {
32 30
 	[super applyOptionsOnWillMoveToParentViewController:options];
33 31
 	UIViewController* viewController = self.boundViewController;
34
-	[viewController rnn_setBackButtonIcon:[options.topBar.backButton.icon getWithDefaultValue:nil] withColor:[options.topBar.backButton.color getWithDefaultValue:nil] title:[options.topBar.backButton.showTitle getWithDefaultValue:YES] ? [options.topBar.backButton.title getWithDefaultValue:nil] : @""];
32
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
33
+	[viewController rnn_setBackButtonIcon:[withDefault.topBar.backButton.icon getWithDefaultValue:nil] withColor:[withDefault.topBar.backButton.color getWithDefaultValue:nil] title:[withDefault.topBar.backButton.showTitle getWithDefaultValue:YES] ? [withDefault.topBar.backButton.title getWithDefaultValue:nil] : @""];
35 34
 }
36 35
 
37 36
 - (void)applyOptions:(RNNNavigationOptions *)options {
38 37
 	[super applyOptions:options];
39 38
 	
40 39
 	UIViewController* viewController = self.boundViewController;
41
-	[viewController rnn_setBackgroundImage:[options.backgroundImage getWithDefaultValue:nil]];
42
-	[viewController rnn_setNavigationItemTitle:[options.topBar.title.text getWithDefaultValue:nil]];
43
-	[viewController rnn_setTopBarPrefersLargeTitle:[options.topBar.largeTitle.visible getWithDefaultValue:NO]];
44
-	[viewController rnn_setTabBarItemBadgeColor:[options.bottomTab.badgeColor getWithDefaultValue:nil]];
45
-	[viewController rnn_setStatusBarBlur:[options.statusBar.blur getWithDefaultValue:NO]];
46
-	[viewController rnn_setStatusBarStyle:[options.statusBar.style getWithDefaultValue:@"default"] animated:[options.statusBar.animate getWithDefaultValue:YES]];
47
-	[viewController rnn_setBackButtonVisible:[options.topBar.backButton.visible getWithDefaultValue:YES]];
48
-	[viewController rnn_setInterceptTouchOutside:[options.overlay.interceptTouchOutside getWithDefaultValue:YES]];
40
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
41
+	[viewController rnn_setBackgroundImage:[withDefault.backgroundImage getWithDefaultValue:nil]];
42
+	[viewController rnn_setNavigationItemTitle:[withDefault.topBar.title.text getWithDefaultValue:nil]];
43
+	[viewController rnn_setTopBarPrefersLargeTitle:[withDefault.topBar.largeTitle.visible getWithDefaultValue:NO]];
44
+	[viewController rnn_setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]];
45
+	[viewController rnn_setStatusBarBlur:[withDefault.statusBar.blur getWithDefaultValue:NO]];
46
+	[viewController rnn_setStatusBarStyle:[withDefault.statusBar.style getWithDefaultValue:@"default"] animated:[withDefault.statusBar.animate getWithDefaultValue:YES]];
47
+	[viewController rnn_setBackButtonVisible:[withDefault.topBar.backButton.visible getWithDefaultValue:YES]];
48
+	[viewController rnn_setInterceptTouchOutside:[withDefault.overlay.interceptTouchOutside getWithDefaultValue:YES]];
49 49
 	
50
-	if (options.layout.backgroundColor.hasValue) {
51
-		[viewController rnn_setBackgroundColor:options.layout.backgroundColor.get];
50
+	if (withDefault.layout.backgroundColor.hasValue) {
51
+		[viewController rnn_setBackgroundColor:withDefault.layout.backgroundColor.get];
52 52
 	}
53 53
 	
54
-	if (options.topBar.searchBar.hasValue) {
54
+	if (withDefault.topBar.searchBar.hasValue) {
55 55
 		BOOL hideNavBarOnFocusSearchBar = YES;
56
-		if (options.topBar.hideNavBarOnFocusSearchBar.hasValue) {
57
-			hideNavBarOnFocusSearchBar = options.topBar.hideNavBarOnFocusSearchBar.get;
56
+		if (withDefault.topBar.hideNavBarOnFocusSearchBar.hasValue) {
57
+			hideNavBarOnFocusSearchBar = withDefault.topBar.hideNavBarOnFocusSearchBar.get;
58 58
 		}
59
-		[viewController rnn_setSearchBarWithPlaceholder:[options.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar: hideNavBarOnFocusSearchBar];
59
+		[viewController rnn_setSearchBarWithPlaceholder:[withDefault.topBar.searchBarPlaceholder getWithDefaultValue:@""] hideNavBarOnFocusSearchBar: hideNavBarOnFocusSearchBar];
60 60
 	}
61 61
 	
62
-	[self setTitleViewWithSubtitle:options];
62
+	[self setTitleViewWithSubtitle:withDefault];
63 63
 }
64 64
 
65 65
 - (void)applyOptionsOnInit:(RNNNavigationOptions *)options {
66 66
 	[super applyOptionsOnInit:options];
67 67
 	
68 68
 	UIViewController* viewController = self.boundViewController;
69
-	[viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[options.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
70
-	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[options.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
71
-	[viewController rnn_setDrawBehindTopBar:[options.topBar.drawBehind getWithDefaultValue:NO]];
72
-	[viewController rnn_setDrawBehindTabBar:[options.bottomTabs.drawBehind getWithDefaultValue:NO] || ![options.bottomTabs.visible getWithDefaultValue:YES]];
73
-	
74
-	if ((options.topBar.leftButtons || options.topBar.rightButtons)) {
75
-		[_navigationButtons applyLeftButtons:options.topBar.leftButtons rightButtons:options.topBar.rightButtons defaultLeftButtonStyle:options.topBar.leftButtonStyle defaultRightButtonStyle:options.topBar.rightButtonStyle];
69
+	RNNNavigationOptions *withDefault = [options withDefault:[self defaultOptions]];
70
+	[viewController rnn_setModalPresentationStyle:[RCTConvert UIModalPresentationStyle:[withDefault.modalPresentationStyle getWithDefaultValue:@"fullScreen"]]];
71
+	[viewController rnn_setModalTransitionStyle:[RCTConvert UIModalTransitionStyle:[withDefault.modalTransitionStyle getWithDefaultValue:@"coverVertical"]]];
72
+	[viewController rnn_setDrawBehindTopBar:[withDefault.topBar.drawBehind getWithDefaultValue:NO]];
73
+	[viewController rnn_setDrawBehindTabBar:[withDefault.bottomTabs.drawBehind getWithDefaultValue:NO] || ![withDefault.bottomTabs.visible getWithDefaultValue:YES]];
74
+	
75
+	if ((withDefault.topBar.leftButtons || withDefault.topBar.rightButtons)) {
76
+		[_navigationButtons applyLeftButtons:withDefault.topBar.leftButtons rightButtons:withDefault.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle];
76 77
 	}
77 78
 }
78 79
 

+ 3
- 0
lib/ios/UIViewController+RNNOptions.h Vedi File

@@ -1,9 +1,12 @@
1 1
 #import <UIKit/UIKit.h>
2 2
 
3 3
 @class RNNBottomTabOptions;
4
+@class RNNNavigationOptions;
4 5
 
5 6
 @interface UIViewController (RNNOptions)
6 7
 
8
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions;
9
+
7 10
 - (void)rnn_setBackgroundImage:(UIImage *)backgroundImage;
8 11
 
9 12
 - (void)rnn_setModalPresentationStyle:(UIModalPresentationStyle)modalPresentationStyle;

+ 5
- 0
lib/ios/UIViewController+RNNOptions.m Vedi File

@@ -2,12 +2,17 @@
2 2
 #import <React/RCTRootView.h>
3 3
 #import "UIImage+tint.h"
4 4
 #import "RNNBottomTabOptions.h"
5
+#import "RNNNavigationOptions.h"
5 6
 
6 7
 #define kStatusBarAnimationDuration 0.35
7 8
 const NSInteger BLUR_STATUS_TAG = 78264801;
8 9
 
9 10
 @implementation UIViewController (RNNOptions)
10 11
 
12
+- (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions {
13
+
14
+}
15
+
11 16
 - (void)rnn_setBackgroundImage:(UIImage *)backgroundImage {
12 17
 	if (backgroundImage) {
13 18
 		UIImageView* backgroundImageView = (self.view.subviews.count > 0) ? self.view.subviews[0] : nil;

+ 17
- 11
playground/src/screens/StatusBarOptionsScreen.js Vedi File

@@ -31,18 +31,20 @@ class StatusBarOptions extends React.Component {
31 31
 
32 32
   render() {
33 33
     return (
34
-      <Root componentId={this.props.componentId} style={style.root}>
34
+      <View style={style.container}>
35 35
         <Image
36
-          style={style.image}
37
-          source={require('../../img/city.png')}
38
-          fadeDuration={0}
39
-        />
40
-        <Button label='Full Screen Modal' onPress={this.fullScreenModal} />
41
-        <Button label='Push' onPress={this.push} />
42
-        <Button label='BottomTabs' onPress={this.bottomTabs} />
43
-        <Button label='Open Left' onPress={() => this.open('left')} />
44
-        <Button label='Open Right' onPress={() => this.open('right')} />
45
-      </Root>
36
+            style={style.image}
37
+            source={require('../../img/city.png')}
38
+            fadeDuration={0}
39
+          />
40
+        <Root componentId={this.props.componentId} style={style.root}>
41
+          <Button label='Full Screen Modal' onPress={this.fullScreenModal} />
42
+          <Button label='Push' onPress={this.push} />
43
+          <Button label='BottomTabs' onPress={this.bottomTabs} />
44
+          <Button label='Open Left' onPress={() => this.open('left')} />
45
+          <Button label='Open Right' onPress={() => this.open('right')} />
46
+        </Root>
47
+      </View>
46 48
     );
47 49
   }
48 50
 
@@ -62,6 +64,10 @@ const style = StyleSheet.create({
62 64
     paddingTop: 0,
63 65
     paddingHorizontal: 0
64 66
   },
67
+  container: {
68
+    flex: 1,
69
+    flexDirection: 'column'
70
+  },
65 71
   image: {
66 72
     height: 250,
67 73
     width: '100%',