diff --git a/lib/ios/BottomTabPresenter.m b/lib/ios/BottomTabPresenter.m index 3ac5da8ee74..8ed70198543 100644 --- a/lib/ios/BottomTabPresenter.m +++ b/lib/ios/BottomTabPresenter.m @@ -21,18 +21,18 @@ - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)opt [child setTabBarItemBadgeColor:[withDefault.bottomTab.badgeColor getWithDefaultValue:nil]]; } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)resolvedOptions child:(UIViewController *)child { RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[resolvedOptions - withDefault:self.defaultOptions] overrideOptions:options]; + withDefault:self.defaultOptions] mergeOptions:mergeOptions]; - if (options.bottomTab.hasValue) + if (mergeOptions.bottomTab.hasValue) [self createTabBarItem:child bottomTabOptions:withDefault.bottomTab]; - if (options.bottomTab.badge.hasValue) - [child setTabBarItemBadge:options.bottomTab.badge.get]; - if (options.bottomTab.badgeColor.hasValue) - [child setTabBarItemBadgeColor:options.bottomTab.badgeColor.get]; + if (mergeOptions.bottomTab.badge.hasValue) + [child setTabBarItemBadge:mergeOptions.bottomTab.badge.get]; + if (mergeOptions.bottomTab.badgeColor.hasValue) + [child setTabBarItemBadgeColor:mergeOptions.bottomTab.badgeColor.get]; } - (void)createTabBarItem:(UIViewController *)child diff --git a/lib/ios/BottomTabsBasePresenter.m b/lib/ios/BottomTabsBasePresenter.m index 8b09fa06bde..e03012822b8 100644 --- a/lib/ios/BottomTabsBasePresenter.m +++ b/lib/ios/BottomTabsBasePresenter.m @@ -33,52 +33,52 @@ - (void)applyOptions:(RNNNavigationOptions *)options { getWithDefaultValue:@"default"]]]; } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)currentOptions { - [super mergeOptions:options resolvedOptions:currentOptions]; + [super mergeOptions:mergeOptions resolvedOptions:currentOptions]; RNNBottomTabsController *bottomTabs = self.tabBarController; - if (options.bottomTabs.currentTabIndex.hasValue) { - [bottomTabs setCurrentTabIndex:options.bottomTabs.currentTabIndex.get]; - [options.bottomTabs.currentTabIndex consume]; + if (mergeOptions.bottomTabs.currentTabIndex.hasValue) { + [bottomTabs setCurrentTabIndex:mergeOptions.bottomTabs.currentTabIndex.get]; + [mergeOptions.bottomTabs.currentTabIndex consume]; } - if (options.bottomTabs.currentTabId.hasValue) { - [bottomTabs setCurrentTabID:options.bottomTabs.currentTabId.get]; - [options.bottomTabs.currentTabId consume]; + if (mergeOptions.bottomTabs.currentTabId.hasValue) { + [bottomTabs setCurrentTabID:mergeOptions.bottomTabs.currentTabId.get]; + [mergeOptions.bottomTabs.currentTabId consume]; } - if (options.bottomTabs.testID.hasValue) { - [bottomTabs setTabBarTestID:options.bottomTabs.testID.get]; + if (mergeOptions.bottomTabs.testID.hasValue) { + [bottomTabs setTabBarTestID:mergeOptions.bottomTabs.testID.get]; } - if (options.bottomTabs.backgroundColor.hasValue) { - [self setTabBarBackgroundColor:options.bottomTabs.backgroundColor.get]; + if (mergeOptions.bottomTabs.backgroundColor.hasValue) { + [self setTabBarBackgroundColor:mergeOptions.bottomTabs.backgroundColor.get]; } - if (options.bottomTabs.barStyle.hasValue) { - [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:options.bottomTabs.barStyle.get]]; + if (mergeOptions.bottomTabs.barStyle.hasValue) { + [bottomTabs setTabBarStyle:[RCTConvert UIBarStyle:mergeOptions.bottomTabs.barStyle.get]]; } - if (options.bottomTabs.translucent.hasValue) { - [bottomTabs setTabBarTranslucent:options.bottomTabs.translucent.get]; + if (mergeOptions.bottomTabs.translucent.hasValue) { + [bottomTabs setTabBarTranslucent:mergeOptions.bottomTabs.translucent.get]; } - if (options.bottomTabs.hideShadow.hasValue) { - [bottomTabs setTabBarHideShadow:options.bottomTabs.hideShadow.get]; + if (mergeOptions.bottomTabs.hideShadow.hasValue) { + [bottomTabs setTabBarHideShadow:mergeOptions.bottomTabs.hideShadow.get]; } - if (options.bottomTabs.visible.hasValue) { - if (options.bottomTabs.animate.hasValue) { - [bottomTabs setTabBarVisible:options.bottomTabs.visible.get - animated:[options.bottomTabs.animate getWithDefaultValue:NO]]; + if (mergeOptions.bottomTabs.visible.hasValue) { + if (mergeOptions.bottomTabs.animate.hasValue) { + [bottomTabs setTabBarVisible:mergeOptions.bottomTabs.visible.get + animated:[mergeOptions.bottomTabs.animate getWithDefaultValue:NO]]; } else { - [bottomTabs setTabBarVisible:options.bottomTabs.visible.get animated:NO]; + [bottomTabs setTabBarVisible:mergeOptions.bottomTabs.visible.get animated:NO]; } } - if (options.layout.backgroundColor.hasValue) { - [bottomTabs.view setBackgroundColor:options.layout.backgroundColor.get]; + if (mergeOptions.layout.backgroundColor.hasValue) { + [bottomTabs.view setBackgroundColor:mergeOptions.layout.backgroundColor.get]; } } diff --git a/lib/ios/DeprecationOptions.m b/lib/ios/DeprecationOptions.m index 0703df4ec8c..6236805f529 100644 --- a/lib/ios/DeprecationOptions.m +++ b/lib/ios/DeprecationOptions.m @@ -3,8 +3,11 @@ @implementation DeprecationOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; return self; } +- (void)mergeOptions:(DeprecationOptions *)options { +} + @end diff --git a/lib/ios/DotIndicatorOptions.m b/lib/ios/DotIndicatorOptions.m index 967d100824f..42cc0faea46 100644 --- a/lib/ios/DotIndicatorOptions.m +++ b/lib/ios/DotIndicatorOptions.m @@ -5,7 +5,7 @@ @implementation DotIndicatorOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.color = [ColorParser parse:dict key:@"color"]; self.size = [NumberParser parse:dict key:@"size"]; @@ -20,8 +20,17 @@ - (instancetype)init { return self; } +- (void)mergeOptions:(DotIndicatorOptions *)options { + if (options.color.hasValue) + self.color = options.color; + if (options.size.hasValue) + self.size = options.size; + if (options.visible.hasValue) + self.visible = options.visible; +} + - (bool)hasValue { return [self.visible hasValue]; } -@end \ No newline at end of file +@end diff --git a/lib/ios/NSObject+Utils.h b/lib/ios/NSObject+Utils.h deleted file mode 100644 index cfd1ddaa487..00000000000 --- a/lib/ios/NSObject+Utils.h +++ /dev/null @@ -1,7 +0,0 @@ -#import - -@interface NSObject (Utils) - -- (NSArray *)classProperties; - -@end diff --git a/lib/ios/NSObject+Utils.m b/lib/ios/NSObject+Utils.m deleted file mode 100644 index a8087ff2ea9..00000000000 --- a/lib/ios/NSObject+Utils.m +++ /dev/null @@ -1,25 +0,0 @@ -#import "NSObject+Utils.h" -#import "RNNOptions.h" -#import - -@implementation NSObject (Utils) - -- (NSArray *)classProperties { - NSMutableArray *properties = [NSMutableArray new]; - unsigned int count; - Class cls = [self class]; - do { - objc_property_t *props = class_copyPropertyList(cls, &count); - for (int i = 0; i < count; i++) { - objc_property_t property = props[i]; - NSString *propertyName = [NSString stringWithCString:property_getName(property) - encoding:NSUTF8StringEncoding]; - [properties addObject:propertyName]; - } - free(props); - cls = [cls superclass]; - } while (![cls isEqual:[NSObject class]] && cls != nil); - return properties; -} - -@end diff --git a/lib/ios/RNNAnimationsOptions.m b/lib/ios/RNNAnimationsOptions.m index 4fe62ba2a83..a18b3b488b0 100644 --- a/lib/ios/RNNAnimationsOptions.m +++ b/lib/ios/RNNAnimationsOptions.m @@ -3,7 +3,7 @@ @implementation RNNAnimationsOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.push = [[RNNScreenTransition alloc] initWithDict:dict[@"push"]]; self.pop = [[RNNScreenTransition alloc] initWithDict:dict[@"pop"]]; @@ -15,4 +15,13 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNAnimationsOptions *)options { + [self.push mergeOptions:options.push]; + [self.pop mergeOptions:options.pop]; + [self.showModal mergeOptions:options.showModal]; + [self.dismissModal mergeOptions:options.dismissModal]; + [self.setStackRoot mergeOptions:options.setStackRoot]; + [self.setRoot mergeOptions:options.setRoot]; +} + @end diff --git a/lib/ios/RNNBackButtonOptions.m b/lib/ios/RNNBackButtonOptions.m index af153b3cc65..d036fdddc37 100644 --- a/lib/ios/RNNBackButtonOptions.m +++ b/lib/ios/RNNBackButtonOptions.m @@ -3,7 +3,7 @@ @implementation RNNBackButtonOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.icon = [ImageParser parse:dict key:@"icon"]; self.title = [TextParser parse:dict key:@"title"]; @@ -18,6 +18,27 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNBackButtonOptions *)options { + if (options.icon.hasValue) + self.icon = options.icon; + if (options.title.hasValue) + self.title = options.title; + if (options.transition.hasValue) + self.transition = options.transition; + if (options.color.hasValue) + self.color = options.color; + if (options.showTitle.hasValue) + self.showTitle = options.showTitle; + if (options.visible.hasValue) + self.visible = options.visible; + if (options.testID.hasValue) + self.testID = options.testID; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; +} + - (BOOL)hasValue { return self.icon.hasValue || self.showTitle.hasValue || self.color.hasValue || self.fontFamily.hasValue || self.fontSize.hasValue || self.title.hasValue; diff --git a/lib/ios/RNNBackgroundOptions.m b/lib/ios/RNNBackgroundOptions.m index 6bceced3427..d10371295dd 100644 --- a/lib/ios/RNNBackgroundOptions.m +++ b/lib/ios/RNNBackgroundOptions.m @@ -3,7 +3,7 @@ @implementation RNNBackgroundOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.color = [ColorParser parse:dict key:@"color"]; self.translucent = [BoolParser parse:dict key:@"translucent"]; @@ -14,4 +14,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNBackgroundOptions *)options { + [self.component mergeOptions:options.component]; + + if (options.color.hasValue) + self.color = options.color; + if (options.translucent.hasValue) + self.translucent = options.translucent; + if (options.blur.hasValue) + self.blur = options.blur; + if (options.clipToBounds.hasValue) + self.clipToBounds = options.clipToBounds; +} + @end diff --git a/lib/ios/RNNBasePresenter.m b/lib/ios/RNNBasePresenter.m index a33608cc948..238e2e65f13 100644 --- a/lib/ios/RNNBasePresenter.m +++ b/lib/ios/RNNBasePresenter.m @@ -40,9 +40,10 @@ - (void)componentDidDisappear { - (void)willMoveToParentViewController:(UIViewController *)parent { if (parent) { - [self applyOptionsOnWillMoveToParentViewController:self.boundViewController.resolveOptions]; + RNNNavigationOptions *resolvedOptions = [self.boundViewController resolveOptions]; + [self applyOptionsOnWillMoveToParentViewController:resolvedOptions]; [self.boundViewController onChildAddToParent:self.boundViewController - options:self.boundViewController.resolveOptions]; + options:resolvedOptions]; } } @@ -70,27 +71,27 @@ - (void)applyOptionsOnWillMoveToParentViewController:(RNNNavigationOptions *)opt - (void)applyOptions:(RNNNavigationOptions *)options { } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)resolvedOptions { RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[resolvedOptions - withDefault:_defaultOptions] overrideOptions:options]; + withDefault:_defaultOptions] mergeOptions:mergeOptions]; if (@available(iOS 13.0, *)) { if (withDefault.modal.swipeToDismiss.hasValue) self.boundViewController.modalInPresentation = !withDefault.modal.swipeToDismiss.get; } - if (options.window.backgroundColor.hasValue) { + if (mergeOptions.window.backgroundColor.hasValue) { UIApplication.sharedApplication.delegate.window.backgroundColor = withDefault.window.backgroundColor.get; } - if (options.statusBar.visible.hasValue) { + if (mergeOptions.statusBar.visible.hasValue) { [self.boundViewController setNeedsStatusBarAppearanceUpdate]; } - if (options.layout.autoHideHomeIndicator.hasValue && - options.layout.autoHideHomeIndicator.get != _prefersHomeIndicatorAutoHidden) { - _prefersHomeIndicatorAutoHidden = options.layout.autoHideHomeIndicator.get; + if (mergeOptions.layout.autoHideHomeIndicator.hasValue && + mergeOptions.layout.autoHideHomeIndicator.get != _prefersHomeIndicatorAutoHidden) { + _prefersHomeIndicatorAutoHidden = mergeOptions.layout.autoHideHomeIndicator.get; [self.boundViewController setNeedsUpdateOfHomeIndicatorAutoHidden]; } } @@ -130,9 +131,10 @@ - (BOOL)getStatusBarVisibility { } - (RNNStatusBarOptions *)resolveStatusBarOptions { - return (RNNStatusBarOptions *)[[self.boundViewController.options.statusBar - mergeInOptions:self.boundViewController.getCurrentChild.presenter.resolveStatusBarOptions] - withDefault:self.defaultOptions.statusBar]; + RNNNavigationOptions *options = self.boundViewController.options.copy; + [options.statusBar + mergeOptions:self.boundViewController.getCurrentChild.presenter.resolveStatusBarOptions]; + return [[options withDefault:self.defaultOptions] statusBar]; } - (UINavigationItem *)currentNavigationItem { diff --git a/lib/ios/RNNBottomTabOptions.m b/lib/ios/RNNBottomTabOptions.m index 9aef961c4d4..4eb0f74e406 100644 --- a/lib/ios/RNNBottomTabOptions.m +++ b/lib/ios/RNNBottomTabOptions.m @@ -5,15 +5,15 @@ @implementation RNNBottomTabOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.tag = arc4random(); self.text = [TextParser parse:dict key:@"text"]; self.badge = [TextParser parse:dict key:@"badge"]; - self.badgeColor = [ColorParser parse:dict key:@"badgeColor"]; self.fontFamily = [TextParser parse:dict key:@"fontFamily"]; self.fontWeight = [TextParser parse:dict key:@"fontWeight"]; self.testID = [TextParser parse:dict key:@"testID"]; + self.badgeColor = [ColorParser parse:dict key:@"badgeColor"]; self.dotIndicator = [DotIndicatorParser parse:dict]; @@ -32,6 +32,43 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNBottomTabOptions *)options { + [self.dotIndicator mergeOptions:options.dotIndicator]; + + if (options.text.hasValue) + self.text = options.text; + if (options.badge.hasValue) + self.badge = options.badge; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.fontWeight.hasValue) + self.fontWeight = options.fontWeight; + if (options.testID.hasValue) + self.testID = options.testID; + if (options.badgeColor.hasValue) + self.badgeColor = options.badgeColor; + if (options.icon.hasValue) + self.icon = options.icon; + if (options.selectedIcon.hasValue) + self.selectedIcon = options.selectedIcon; + if (options.iconColor.hasValue) + self.iconColor = options.iconColor; + if (options.selectedIconColor.hasValue) + self.selectedIconColor = options.selectedIconColor; + if (options.selectedTextColor.hasValue) + self.selectedTextColor = options.selectedTextColor; + if (options.iconInsets.hasValue) + self.iconInsets = options.iconInsets; + if (options.textColor.hasValue) + self.textColor = options.textColor; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.visible.hasValue) + self.visible = options.visible; + if (options.selectTabOnPress.hasValue) + self.selectTabOnPress = options.selectTabOnPress; +} + - (BOOL)hasValue { return self.text.hasValue || self.badge.hasValue || self.badgeColor.hasValue || self.fontFamily.hasValue || self.fontWeight.hasValue || self.fontSize.hasValue || diff --git a/lib/ios/RNNBottomTabsOptions.m b/lib/ios/RNNBottomTabsOptions.m index fb91a70da95..f1bd8a4251b 100644 --- a/lib/ios/RNNBottomTabsOptions.m +++ b/lib/ios/RNNBottomTabsOptions.m @@ -3,7 +3,7 @@ @implementation RNNBottomTabsOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.visible = [BoolParser parse:dict key:@"visible"]; self.currentTabIndex = [IntNumberParser parse:dict key:@"currentTabIndex"]; @@ -27,6 +27,41 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNBottomTabsOptions *)options { + if (options.visible.hasValue) + self.visible = options.visible; + if (options.currentTabIndex.hasValue) + self.currentTabIndex = options.currentTabIndex; + if (options.drawBehind.hasValue) + self.drawBehind = options.drawBehind; + if (options.animate.hasValue) + self.animate = options.animate; + if (options.tabColor.hasValue) + self.tabColor = options.tabColor; + if (options.selectedTabColor.hasValue) + self.selectedTabColor = options.selectedTabColor; + if (options.translucent.hasValue) + self.translucent = options.translucent; + if (options.hideShadow.hasValue) + self.hideShadow = options.hideShadow; + if (options.backgroundColor.hasValue) + self.backgroundColor = options.backgroundColor; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.testID.hasValue) + self.testID = options.testID; + if (options.currentTabId.hasValue) + self.currentTabId = options.currentTabId; + if (options.barStyle.hasValue) + self.barStyle = options.barStyle; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.titleDisplayMode.hasValue) + self.titleDisplayMode = options.titleDisplayMode; + if (options.tabsAttachMode.hasValue) + self.tabsAttachMode = options.tabsAttachMode; +} + - (BOOL)shouldDrawBehind { return [self.drawBehind getWithDefaultValue:NO] || [self.translucent getWithDefaultValue:NO] || ![self.visible getWithDefaultValue:YES]; diff --git a/lib/ios/RNNButtonOptions.m b/lib/ios/RNNButtonOptions.m index c4859ff9417..525ebbec8d9 100644 --- a/lib/ios/RNNButtonOptions.m +++ b/lib/ios/RNNButtonOptions.m @@ -3,7 +3,7 @@ @implementation RNNButtonOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.fontFamily = [TextParser parse:dict key:@"fontFamily"]; self.text = [TextParser parse:dict key:@"text"]; @@ -18,4 +18,25 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNButtonOptions *)options { + [self.iconInsets mergeOptions:options.iconInsets]; + + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.text.hasValue) + self.text = options.text; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.color.hasValue) + self.color = options.color; + if (options.disabledColor.hasValue) + self.disabledColor = options.disabledColor; + if (options.icon.hasValue) + self.icon = options.icon; + if (options.enabled.hasValue) + self.enabled = options.enabled; + if (options.selectTabOnPress.hasValue) + self.selectTabOnPress = options.selectTabOnPress; +} + @end diff --git a/lib/ios/RNNCommandsHandler.m b/lib/ios/RNNCommandsHandler.m index 14c4031b23a..ae040cd8399 100644 --- a/lib/ios/RNNCommandsHandler.m +++ b/lib/ios/RNNCommandsHandler.m @@ -156,9 +156,9 @@ - (void)push:(NSString *)componentId [_layoutManager addPendingViewController:newVc]; UIViewController *fromVC = [_layoutManager findComponentForId:componentId]; + RNNNavigationOptions *optionsWithDefault = newVc.resolveOptionsWithDefault; - if ([[newVc.resolveOptionsWithDefault.preview.reactTag getWithDefaultValue:@(0)] floatValue] > - 0) { + if ([[optionsWithDefault.preview.reactTag getWithDefaultValue:@(0)] floatValue] > 0) { if ([fromVC isKindOfClass:[RNNComponentViewController class]]) { RNNComponentViewController *rootVc = (RNNComponentViewController *)fromVC; rootVc.previewController = newVc; @@ -183,32 +183,31 @@ - (void)push:(NSString *)componentId CGSize size = CGSizeMake(rootVc.view.frame.size.width, rootVc.view.frame.size.height); - if (newVc.resolveOptionsWithDefault.preview.width.hasValue) { + if (optionsWithDefault.preview.width.hasValue) { size.width = [newVc.resolveOptionsWithDefault.preview.width.get floatValue]; } - if (newVc.resolveOptionsWithDefault.preview.height.hasValue) { + if (optionsWithDefault.preview.height.hasValue) { size.height = [newVc.resolveOptionsWithDefault.preview.height.get floatValue]; } - if (newVc.resolveOptionsWithDefault.preview.width.hasValue || - newVc.resolveOptionsWithDefault.preview.height.hasValue) { + if (optionsWithDefault.preview.width.hasValue || + optionsWithDefault.preview.height.hasValue) { newVc.preferredContentSize = size; } RCTExecuteOnMainQueue(^{ UIView *view = [[ReactNativeNavigation getBridge].uiManager - viewForReactTag:newVc.resolveOptionsWithDefault.preview.reactTag.get]; + viewForReactTag:optionsWithDefault.preview.reactTag.get]; [rootVc registerForPreviewingWithDelegate:(id)rootVc sourceView:view]; }); } } else { - newVc.waitForRender = newVc.resolveOptionsWithDefault.animations.push.shouldWaitForRender; + newVc.waitForRender = optionsWithDefault.animations.push.shouldWaitForRender; __weak UIViewController *weakNewVC = newVc; [newVc setReactViewReadyCallback:^{ [fromVC.stack push:weakNewVC onTop:fromVC - animated:[weakNewVC.resolveOptionsWithDefault.animations.push.enable - getWithDefaultValue:YES] + animated:[optionsWithDefault.animations.push.enable getWithDefaultValue:YES] completion:^{ [self->_layoutManager removePendingViewController:weakNewVC]; [self->_eventEmitter sendOnNavigationCommandCompletion:push @@ -277,7 +276,7 @@ - (void)pop:(NSString *)componentId (RNNComponentViewController *)[_layoutManager findComponentForId:componentId]; if (vc) { RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions]; - [vc overrideOptions:options]; + [vc mergeOptions:options]; [vc.stack pop:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] @@ -307,7 +306,7 @@ - (void)popTo:(NSString *)componentId RNNComponentViewController *vc = (RNNComponentViewController *)[_layoutManager findComponentForId:componentId]; RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions]; - [vc overrideOptions:options]; + [vc mergeOptions:options]; [vc.stack popTo:vc animated:[vc.resolveOptionsWithDefault.animations.pop.enable getWithDefaultValue:YES] @@ -329,7 +328,7 @@ - (void)popToRoot:(NSString *)componentId RNNComponentViewController *vc = (RNNComponentViewController *)[_layoutManager findComponentForId:componentId]; RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions]; - [vc overrideOptions:options]; + [vc mergeOptions:options]; [CATransaction begin]; [CATransaction setCompletionBlock:^{ @@ -394,7 +393,7 @@ - (void)dismissModal:(NSString *)componentId } RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:mergeOptions]; - [modalToDismiss.presentedComponentViewController overrideOptions:options]; + [modalToDismiss.presentedComponentViewController mergeOptions:options]; [_modalManager dismissModal:modalToDismiss completion:^{ diff --git a/lib/ios/RNNComponentOptions.m b/lib/ios/RNNComponentOptions.m index 5c6dbb08bb1..688b21e0074 100644 --- a/lib/ios/RNNComponentOptions.m +++ b/lib/ios/RNNComponentOptions.m @@ -3,7 +3,7 @@ @implementation RNNComponentOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.name = [TextParser parse:dict key:@"name"]; self.componentId = [TextParser parse:dict key:@"componentId"]; @@ -13,6 +13,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNComponentOptions *)options { + if (options.name.hasValue) + self.name = options.name; + if (options.componentId.hasValue) + self.componentId = options.componentId; + if (options.alignment.hasValue) + self.alignment = options.alignment; + if (options.waitForRender.hasValue) + self.waitForRender = options.waitForRender; +} + - (BOOL)hasValue { return _name.hasValue; } diff --git a/lib/ios/RNNComponentPresenter.m b/lib/ios/RNNComponentPresenter.m index 0ce35361985..b2f856eefbc 100644 --- a/lib/ios/RNNComponentPresenter.m +++ b/lib/ios/RNNComponentPresenter.m @@ -1,6 +1,5 @@ #import "RNNComponentPresenter.h" #import "RNNComponentViewController.h" -#import "RNNReactTitleView.h" #import "RNNTitleViewHelper.h" #import "TopBarTitlePresenter.h" #import "UITabBarController+RNNOptions.h" @@ -112,15 +111,15 @@ - (void)applyOptionsOnInit:(RNNNavigationOptions *)options { } } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)currentOptions { - [super mergeOptions:options resolvedOptions:currentOptions]; + [super mergeOptions:mergeOptions resolvedOptions:currentOptions]; RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[currentOptions - overrideOptions:options] withDefault:[self defaultOptions]]; + mergeOptions:mergeOptions] withDefault:self.defaultOptions]; RNNComponentViewController *viewController = self.boundViewController; - if (options.backgroundImage.hasValue) { - [viewController setBackgroundImage:options.backgroundImage.get]; + if (mergeOptions.backgroundImage.hasValue) { + [viewController setBackgroundImage:mergeOptions.backgroundImage.get]; } if ([withDefault.topBar.searchBar.visible getWithDefaultValue:NO]) { @@ -130,7 +129,6 @@ - (void)mergeOptions:(RNNNavigationOptions *)options BOOL obscuresBackgroundDuringPresentation = [withDefault.topBar.searchBar.obscuresBackgroundDuringPresentation getWithDefaultValue:NO]; - BOOL focus = [withDefault.topBar.searchBar.focus getWithDefaultValue:NO]; [viewController setSearchBarWithOptions:[withDefault.topBar.searchBar.placeholder @@ -139,69 +137,70 @@ - (void)mergeOptions:(RNNNavigationOptions *)options hideTopBarOnFocus:hideTopBarOnFocus hideOnScroll:hideOnScroll obscuresBackgroundDuringPresentation:obscuresBackgroundDuringPresentation - backgroundColor:[options.topBar.searchBar.backgroundColor + backgroundColor:[mergeOptions.topBar.searchBar.backgroundColor getWithDefaultValue:nil] - tintColor:[options.topBar.searchBar.tintColor + tintColor:[mergeOptions.topBar.searchBar.tintColor getWithDefaultValue:nil]]; } else { [viewController setSearchBarVisible:NO]; } - if (options.topBar.drawBehind.hasValue) { - [viewController setDrawBehindTopBar:options.topBar.drawBehind.get]; + if (mergeOptions.topBar.drawBehind.hasValue) { + [viewController setDrawBehindTopBar:mergeOptions.topBar.drawBehind.get]; } - if (options.bottomTabs.drawBehind.hasValue) { - [viewController setDrawBehindBottomTabs:options.bottomTabs.drawBehind.get]; + if (mergeOptions.bottomTabs.drawBehind.hasValue) { + [viewController setDrawBehindBottomTabs:mergeOptions.bottomTabs.drawBehind.get]; } - if (options.topBar.title.text.hasValue) { - [viewController setNavigationItemTitle:options.topBar.title.text.get]; + if (mergeOptions.topBar.title.text.hasValue) { + [viewController setNavigationItemTitle:mergeOptions.topBar.title.text.get]; } - if (options.topBar.largeTitle.visible.hasValue) { - [viewController setTopBarPrefersLargeTitle:options.topBar.largeTitle.visible.get]; + if (mergeOptions.topBar.largeTitle.visible.hasValue) { + [viewController setTopBarPrefersLargeTitle:mergeOptions.topBar.largeTitle.visible.get]; } - if (options.layout.componentBackgroundColor.hasValue) { - [viewController setBackgroundColor:options.layout.componentBackgroundColor.get]; + if (mergeOptions.layout.componentBackgroundColor.hasValue) { + [viewController setBackgroundColor:mergeOptions.layout.componentBackgroundColor.get]; } - if (options.bottomTab.badgeColor.hasValue) { - [viewController setTabBarItemBadgeColor:options.bottomTab.badgeColor.get]; + if (mergeOptions.bottomTab.badgeColor.hasValue) { + [viewController setTabBarItemBadgeColor:mergeOptions.bottomTab.badgeColor.get]; } - if (options.bottomTab.visible.hasValue) { + if (mergeOptions.bottomTab.visible.hasValue) { [viewController.tabBarController setCurrentTabIndex:[viewController.tabBarController.viewControllers indexOfObject:viewController]]; } - if (options.statusBar.blur.hasValue) { - [viewController setStatusBarBlur:options.statusBar.blur.get]; + if (mergeOptions.statusBar.blur.hasValue) { + [viewController setStatusBarBlur:mergeOptions.statusBar.blur.get]; } - if (options.statusBar.style.hasValue) { - [viewController setStatusBarStyle:options.statusBar.style.get + if (mergeOptions.statusBar.style.hasValue) { + [viewController setStatusBarStyle:mergeOptions.statusBar.style.get animated:[withDefault.statusBar.animate getWithDefaultValue:YES]]; } - if (options.topBar.backButton.visible.hasValue) { - [viewController setBackButtonVisible:options.topBar.backButton.visible.get]; + if (mergeOptions.topBar.backButton.visible.hasValue) { + [viewController setBackButtonVisible:mergeOptions.topBar.backButton.visible.get]; } - if (options.topBar.leftButtons || options.topBar.rightButtons) { - [_navigationButtons applyLeftButtons:options.topBar.leftButtons - rightButtons:options.topBar.rightButtons + if (mergeOptions.topBar.leftButtons || mergeOptions.topBar.rightButtons) { + [_navigationButtons applyLeftButtons:mergeOptions.topBar.leftButtons + rightButtons:mergeOptions.topBar.rightButtons defaultLeftButtonStyle:withDefault.topBar.leftButtonStyle defaultRightButtonStyle:withDefault.topBar.rightButtonStyle]; } - if (options.overlay.interceptTouchOutside.hasValue) { - viewController.reactView.passThroughTouches = !options.overlay.interceptTouchOutside.get; + if (mergeOptions.overlay.interceptTouchOutside.hasValue) { + viewController.reactView.passThroughTouches = + !mergeOptions.overlay.interceptTouchOutside.get; } - [_topBarTitlePresenter mergeOptions:options.topBar resolvedOptions:withDefault.topBar]; + [_topBarTitlePresenter mergeOptions:mergeOptions.topBar resolvedOptions:withDefault.topBar]; } - (void)renderComponents:(RNNNavigationOptions *)options diff --git a/lib/ios/RNNComponentViewController.m b/lib/ios/RNNComponentViewController.m index 0f3d2a48275..42d72df09a8 100644 --- a/lib/ios/RNNComponentViewController.m +++ b/lib/ios/RNNComponentViewController.m @@ -27,10 +27,6 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo return self; } -- (void)overrideOptions:(RNNNavigationOptions *)options { - [self.options overrideOptions:options]; -} - - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [_presenter applyOptions:self.resolveOptions]; diff --git a/lib/ios/RNNComponentViewCreator.h b/lib/ios/RNNComponentViewCreator.h index 5c88776ca6c..2f8a938ea8b 100644 --- a/lib/ios/RNNComponentViewCreator.h +++ b/lib/ios/RNNComponentViewCreator.h @@ -2,7 +2,6 @@ #import "RNNComponentOptions.h" #import "RNNReactBackgroundView.h" #import "RNNReactButtonView.h" -#import "RNNReactTitleView.h" #import "RNNReactView.h" #import diff --git a/lib/ios/RNNDotIndicatorPresenter.h b/lib/ios/RNNDotIndicatorPresenter.h index 3fa7ec02106..fa99360f2e9 100644 --- a/lib/ios/RNNDotIndicatorPresenter.h +++ b/lib/ios/RNNDotIndicatorPresenter.h @@ -7,11 +7,11 @@ - (instancetype)initWithDefaultOptions:(RNNNavigationOptions *)defaultOptions; -- (void)apply:(UIViewController *)child:(DotIndicatorOptions *)options; +- (void)apply:(UIViewController *)child options:(DotIndicatorOptions *)options; - (void)bottomTabsDidLayoutSubviews:(UITabBarController *)bottomTabs; -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(NSDictionary *)options resolvedOptions:(RNNNavigationOptions *)resolvedOptions child:(UIViewController *)child; diff --git a/lib/ios/RNNDotIndicatorPresenter.m b/lib/ios/RNNDotIndicatorPresenter.m index 0545e89b017..1fd851f83d8 100644 --- a/lib/ios/RNNDotIndicatorPresenter.m +++ b/lib/ios/RNNDotIndicatorPresenter.m @@ -20,21 +20,21 @@ - (void)bottomTabsDidLayoutSubviews:(UITabBarController *)bottomTabs { } - (void)applyDotIndicator:(UIViewController *)child { - [self apply:child:[child resolveOptions].bottomTab.dotIndicator]; + [self apply:child options:[child resolveOptions].bottomTab.dotIndicator]; } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)resolvedOptions child:(UIViewController *)child { RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[resolvedOptions - withDefault:self.defaultOptions] overrideOptions:options]; + withDefault:self.defaultOptions] mergeOptions:mergeOptions]; - if ([options.bottomTab.dotIndicator hasValue]) { - [self apply:child:withDefault.bottomTab.dotIndicator]; + if ([mergeOptions.bottomTab.dotIndicator hasValue]) { + [self apply:child options:withDefault.bottomTab.dotIndicator]; } } -- (void)apply:(UIViewController *)child:(DotIndicatorOptions *)options { +- (void)apply:(UIViewController *)child options:(DotIndicatorOptions *)options { if (![options hasValue]) return; @@ -43,7 +43,7 @@ - (void)apply:(UIViewController *)child:(DotIndicatorOptions *)options { [self remove:child]; return; } - if ([self currentIndicatorEquals:child:options]) + if ([self currentIndicatorEquals:child options:options]) return; if ([self hasIndicator:child]) @@ -81,7 +81,7 @@ - (void)applyConstraints:(DotIndicatorOptions *)options ]]; } -- (BOOL)currentIndicatorEquals:(UIViewController *)child:(DotIndicatorOptions *)options { +- (BOOL)currentIndicatorEquals:(UIViewController *)child options:(DotIndicatorOptions *)options { if (![self hasIndicator:child]) return NO; UIView *currentIndicator = [self getCurrentIndicator:child]; @@ -96,7 +96,7 @@ - (UIView *)getCurrentIndicator:(UIViewController *)child { } - (BOOL)hasIndicator:(UIViewController *)child { - return [child tabBarItem].tag > 0; + return [[[self getTabBarController:child] tabBar] viewWithTag:child.tabBarItem.tag]; } - (void)remove:(UIViewController *)child { diff --git a/lib/ios/RNNInsetsOptions.m b/lib/ios/RNNInsetsOptions.m index 5dd35994636..517f3889f99 100644 --- a/lib/ios/RNNInsetsOptions.m +++ b/lib/ios/RNNInsetsOptions.m @@ -3,7 +3,7 @@ @implementation RNNInsetsOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.top = [DoubleParser parse:dict key:@"top"]; self.left = [DoubleParser parse:dict key:@"left"]; @@ -13,4 +13,15 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNInsetsOptions *)options { + if (options.top.hasValue) + self.top = options.top; + if (options.left.hasValue) + self.left = options.left; + if (options.bottom.hasValue) + self.bottom = options.bottom; + if (options.right.hasValue) + self.right = options.right; +} + @end diff --git a/lib/ios/RNNLargeTitleOptions.m b/lib/ios/RNNLargeTitleOptions.m index 17c8fa9f2e2..8b4af51c506 100644 --- a/lib/ios/RNNLargeTitleOptions.m +++ b/lib/ios/RNNLargeTitleOptions.m @@ -3,7 +3,7 @@ @implementation RNNLargeTitleOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.fontSize = [NumberParser parse:dict key:@"fontSize"]; self.visible = [BoolParser parse:dict key:@"visible"]; @@ -14,4 +14,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNLargeTitleOptions *)options { + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.visible.hasValue) + self.visible = options.visible; + if (options.color.hasValue) + self.color = options.color; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.fontWeight.hasValue) + self.fontWeight = options.fontWeight; +} + @end diff --git a/lib/ios/RNNLayoutOptions.m b/lib/ios/RNNLayoutOptions.m index 980d3ae7ae3..3e09f88eeb9 100644 --- a/lib/ios/RNNLayoutOptions.m +++ b/lib/ios/RNNLayoutOptions.m @@ -5,7 +5,7 @@ @implementation RNNLayoutOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"]; self.componentBackgroundColor = [ColorParser parse:dict key:@"componentBackgroundColor"]; self.direction = [TextParser parse:dict key:@"direction"]; @@ -14,6 +14,19 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNLayoutOptions *)options { + if (options.backgroundColor.hasValue) + self.backgroundColor = options.backgroundColor; + if (options.componentBackgroundColor.hasValue) + self.componentBackgroundColor = options.componentBackgroundColor; + if (options.direction.hasValue) + self.direction = options.direction; + if (options.orientation) + self.orientation = options.orientation; + if (options.autoHideHomeIndicator) + self.autoHideHomeIndicator = options.autoHideHomeIndicator; +} + - (UIInterfaceOrientationMask)supportedOrientations { NSArray *orientationsArray = [self.orientation isKindOfClass:[NSString class]] ? @[ self.orientation ] diff --git a/lib/ios/RNNLayoutProtocol.h b/lib/ios/RNNLayoutProtocol.h index 9c95c5aad56..fc0f84475ec 100644 --- a/lib/ios/RNNLayoutProtocol.h +++ b/lib/ios/RNNLayoutProtocol.h @@ -36,8 +36,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void); - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions; -- (void)overrideOptions:(RNNNavigationOptions *)options; - - (void)onChildWillAppear; - (void)readyForPresentation; diff --git a/lib/ios/RNNModalOptions.m b/lib/ios/RNNModalOptions.m index a425630c012..cc795cc82c5 100644 --- a/lib/ios/RNNModalOptions.m +++ b/lib/ios/RNNModalOptions.m @@ -3,9 +3,14 @@ @implementation RNNModalOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.swipeToDismiss = [BoolParser parse:dict key:@"swipeToDismiss"]; return self; } +- (void)mergeOptions:(RNNModalOptions *)options { + if (options.swipeToDismiss.hasValue) + self.swipeToDismiss = options.swipeToDismiss; +} + @end diff --git a/lib/ios/RNNNavigationOptions.h b/lib/ios/RNNNavigationOptions.h index af22a178d36..30acd973e9d 100644 --- a/lib/ios/RNNNavigationOptions.h +++ b/lib/ios/RNNNavigationOptions.h @@ -41,12 +41,12 @@ extern const NSInteger BLUR_TOPBAR_TAG; @property(nonatomic, strong) Text *modalPresentationStyle; @property(nonatomic, strong) Text *modalTransitionStyle; -- (instancetype)initEmptyOptions; - + (instancetype)emptyOptions; - (RNNNavigationOptions *)withDefault:(RNNNavigationOptions *)defaultOptions; - (RNNNavigationOptions *)copy; +- (RNNNavigationOptions *)mergeOptions:(RNNNavigationOptions *)options; + @end diff --git a/lib/ios/RNNNavigationOptions.m b/lib/ios/RNNNavigationOptions.m index 128430ea3c0..1dcde935f43 100644 --- a/lib/ios/RNNNavigationOptions.m +++ b/lib/ios/RNNNavigationOptions.m @@ -13,6 +13,15 @@ @implementation RNNNavigationOptions ++ (instancetype)emptyOptions { + return [[RNNNavigationOptions alloc] initEmptyOptions]; +} + +- (instancetype)initEmptyOptions { + self = [self initWithDict:@{}]; + return self; +} + - (instancetype)initWithDict:(NSDictionary *)dict { self = [super init]; @@ -33,7 +42,6 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.window = [[WindowOptions alloc] initWithDict:dict[@"window"]]; self.popGesture = [[Bool alloc] initWithValue:dict[@"popGesture"]]; - self.backgroundImage = [ImageParser parse:dict key:@"backgroundImage"]; self.rootBackgroundImage = [ImageParser parse:dict key:@"rootBackgroundImage"]; self.modalPresentationStyle = [[Text alloc] initWithValue:dict[@"modalPresentationStyle"]]; @@ -42,24 +50,71 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } -+ (instancetype)emptyOptions { - return [[RNNNavigationOptions alloc] initEmptyOptions]; -} +- (RNNNavigationOptions *)mergeOptions:(RNNNavigationOptions *)options { + if (!options) { + return self; + } -- (instancetype)initEmptyOptions { - self = [self initWithDict:@{}]; - return self; + RNNNavigationOptions *result = self; + [result.topBar mergeOptions:options.topBar]; + [result.bottomTabs mergeOptions:options.bottomTabs]; + [result.bottomTab mergeOptions:options.bottomTab]; + [result.topTabs mergeOptions:options.topTabs]; + [result.topTab mergeOptions:options.topTab]; + [result.sideMenu mergeOptions:options.sideMenu]; + [result.splitView mergeOptions:options.splitView]; + [result.overlay mergeOptions:options.overlay]; + [result.animations mergeOptions:options.animations]; + [result.statusBar mergeOptions:options.statusBar]; + [result.preview mergeOptions:options.preview]; + [result.layout mergeOptions:options.layout]; + [result.modal mergeOptions:options.modal]; + [result.deprecations mergeOptions:options.deprecations]; + [result.window mergeOptions:options.window]; + + if (options.popGesture.hasValue) + result.popGesture = options.popGesture; + if (options.backgroundImage.hasValue) + result.backgroundImage = options.backgroundImage; + if (options.rootBackgroundImage.hasValue) + result.rootBackgroundImage = options.rootBackgroundImage; + if (options.modalPresentationStyle.hasValue) + result.modalPresentationStyle = options.modalPresentationStyle; + if (options.modalTransitionStyle.hasValue) + result.modalTransitionStyle = options.modalTransitionStyle; + + return result; } - (RNNNavigationOptions *)copy { - RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc] initWithDict:@{}]; - [newOptions overrideOptions:self]; + RNNNavigationOptions *newOptions = [RNNNavigationOptions emptyOptions]; + [newOptions.topBar mergeOptions:self.topBar]; + [newOptions.bottomTabs mergeOptions:self.bottomTabs]; + [newOptions.bottomTab mergeOptions:self.bottomTab]; + [newOptions.topTabs mergeOptions:self.topTabs]; + [newOptions.topTab mergeOptions:self.topTab]; + [newOptions.sideMenu mergeOptions:self.sideMenu]; + [newOptions.splitView mergeOptions:self.splitView]; + [newOptions.overlay mergeOptions:self.overlay]; + [newOptions.animations mergeOptions:self.animations]; + [newOptions.statusBar mergeOptions:self.statusBar]; + [newOptions.preview mergeOptions:self.preview]; + [newOptions.layout mergeOptions:self.layout]; + [newOptions.modal mergeOptions:self.modal]; + [newOptions.deprecations mergeOptions:self.deprecations]; + [newOptions.window mergeOptions:self.window]; + + newOptions.popGesture = self.popGesture; + newOptions.backgroundImage = self.backgroundImage; + newOptions.rootBackgroundImage = self.rootBackgroundImage; + newOptions.modalPresentationStyle = self.modalPresentationStyle; + newOptions.modalTransitionStyle = self.modalTransitionStyle; return newOptions; } - (RNNNavigationOptions *)withDefault:(RNNNavigationOptions *)defaultOptions { - return (RNNNavigationOptions *)[super withDefault:defaultOptions]; + return defaultOptions ? [defaultOptions.copy mergeOptions:self] : self; } @end diff --git a/lib/ios/RNNOptions.h b/lib/ios/RNNOptions.h index 8fc050181fa..8e4d026ec9c 100644 --- a/lib/ios/RNNOptions.h +++ b/lib/ios/RNNOptions.h @@ -15,10 +15,6 @@ - (instancetype)initWithDict:(NSDictionary *)dict; -- (RNNOptions *)overrideOptions:(RNNOptions *)otherOptions; -- (RNNOptions *)mergeOptions:(RNNOptions *)otherOptions; -- (RNNOptions *)mergeInOptions:(RNNOptions *)otherOptions; - -- (RNNOptions *)withDefault:(RNNOptions *)defaultOptions; +- (void)mergeOptions:(RNNOptions *)otherOptions; @end diff --git a/lib/ios/RNNOptions.m b/lib/ios/RNNOptions.m index b10968c56ce..7cd89944937 100644 --- a/lib/ios/RNNOptions.m +++ b/lib/ios/RNNOptions.m @@ -1,5 +1,4 @@ #import "RNNOptions.h" -#import "NSObject+Utils.h" @implementation RNNOptions @@ -8,46 +7,11 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } -- (RNNOptions *)mergeOptions:(RNNOptions *)otherOptions overrideOptions:(BOOL)override { - for (id prop in self.classProperties) { - id value = [otherOptions valueForKey:prop]; - if ([value isKindOfClass:[RNNOptions class]]) { - [[self valueForKey:prop] mergeOptions:value overrideOptions:override]; - } else if ([value isKindOfClass:[Param class]]) { - if ((((Param *)value).hasValue) && - (override || !((Param *)[self valueForKey:prop]).hasValue)) { - [self setValue:value forKey:prop]; - } - } else if (value && (override || ![self valueForKey:prop])) { - [self setValue:value forKey:prop]; - } - } - - return self; -} - -- (RNNOptions *)overrideOptions:(RNNOptions *)otherOptions { - return [self mergeOptions:otherOptions overrideOptions:YES]; -} - -- (RNNOptions *)mergeOptions:(RNNOptions *)otherOptions { - return [self mergeOptions:otherOptions overrideOptions:NO]; -} - -- (RNNOptions *)mergeInOptions:(RNNOptions *)otherOptions { - if (!otherOptions) { - return self; - } - - return [otherOptions mergeOptions:self overrideOptions:NO]; -} - -- (RNNOptions *)withDefault:(RNNOptions *)defaultOptions { - RNNOptions *newOptions = [[[self class] alloc] initWithDict:@{}]; - [newOptions mergeOptions:defaultOptions overrideOptions:YES]; - [newOptions mergeOptions:self overrideOptions:YES]; - - return newOptions; +- (void)mergeOptions:(RNNOptions *)otherOptions { + @throw [NSException + exceptionWithName:@"RNNOptions mergeOptions:otherOptions not implemented" + reason:@"mergeOptions:otherOptions should be implemented by subclass" + userInfo:nil]; } @end diff --git a/lib/ios/RNNOverlayOptions.m b/lib/ios/RNNOverlayOptions.m index dfe3ca656dd..e8b628e350e 100644 --- a/lib/ios/RNNOverlayOptions.m +++ b/lib/ios/RNNOverlayOptions.m @@ -4,7 +4,7 @@ @implementation RNNOverlayOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.interceptTouchOutside = [BoolParser parse:dict key:@"interceptTouchOutside"]; self.handleKeyboardEvents = [BoolParser parse:dict key:@"handleKeyboardEvents"]; @@ -12,4 +12,11 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNOverlayOptions *)options { + if (options.interceptTouchOutside.hasValue) + self.interceptTouchOutside = options.interceptTouchOutside; + if (options.handleKeyboardEvents.hasValue) + self.handleKeyboardEvents = options.handleKeyboardEvents; +} + @end diff --git a/lib/ios/RNNPreviewOptions.m b/lib/ios/RNNPreviewOptions.m index 867d5310047..6bf0170672e 100644 --- a/lib/ios/RNNPreviewOptions.m +++ b/lib/ios/RNNPreviewOptions.m @@ -14,4 +14,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNPreviewOptions *)options { + if (options.reactTag.hasValue) + self.reactTag = options.reactTag; + if (options.height.hasValue) + self.height = options.height; + if (options.width.hasValue) + self.width = options.width; + if (options.commit.hasValue) + self.commit = options.commit; + if (options.actions) + self.actions = options.actions; +} + @end diff --git a/lib/ios/RNNReactComponentRegistry.h b/lib/ios/RNNReactComponentRegistry.h index 1663e1da825..be336bcf4d7 100644 --- a/lib/ios/RNNReactComponentRegistry.h +++ b/lib/ios/RNNReactComponentRegistry.h @@ -1,7 +1,6 @@ #import "RNNComponentOptions.h" #import "RNNComponentViewCreator.h" #import "RNNReactButtonView.h" -#import "RNNReactTitleView.h" #import @interface RNNReactComponentRegistry : NSObject diff --git a/lib/ios/RNNReactRootViewCreator.m b/lib/ios/RNNReactRootViewCreator.m index f4af9be32a2..59bb49c6b5f 100644 --- a/lib/ios/RNNReactRootViewCreator.m +++ b/lib/ios/RNNReactRootViewCreator.m @@ -1,6 +1,7 @@ #import "RNNReactRootViewCreator.h" #import "RNNComponentRootView.h" +#import "RNNReactTitleView.h" #import "RNNReactView.h" @implementation RNNReactRootViewCreator { diff --git a/lib/ios/RNNScreenTransition.m b/lib/ios/RNNScreenTransition.m index 16e93a392dd..7143d2f4355 100644 --- a/lib/ios/RNNScreenTransition.m +++ b/lib/ios/RNNScreenTransition.m @@ -4,7 +4,7 @@ @implementation RNNScreenTransition - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.topBar = [[ElementTransitionOptions alloc] initWithDict:dict[@"topBar"]]; self.content = [[ElementTransitionOptions alloc] initWithDict:dict[@"content"]]; @@ -22,6 +22,23 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNScreenTransition *)options { + [self.topBar mergeOptions:options.topBar]; + [self.content mergeOptions:options.content]; + [self.bottomTabs mergeOptions:options.bottomTabs]; + + if (options.enable.hasValue) + self.enable = options.enable; + if (options.waitForRender.hasValue) + self.waitForRender = options.waitForRender; + if (options.duration.hasValue) + self.duration = options.duration; + if (options.sharedElementTransitions) + self.sharedElementTransitions = options.sharedElementTransitions; + if (options.elementTransitions) + self.elementTransitions = options.elementTransitions; +} + - (BOOL)hasCustomAnimation { return (self.topBar.hasAnimation || self.content.hasAnimation || self.bottomTabs.hasAnimation || self.sharedElementTransitions || self.elementTransitions); diff --git a/lib/ios/RNNScrollEdgeAppearanceBackgroundOptions.m b/lib/ios/RNNScrollEdgeAppearanceBackgroundOptions.m index 477a9c14c67..faef10edb74 100644 --- a/lib/ios/RNNScrollEdgeAppearanceBackgroundOptions.m +++ b/lib/ios/RNNScrollEdgeAppearanceBackgroundOptions.m @@ -3,7 +3,7 @@ @implementation RNNScrollEdgeAppearanceBackgroundOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.color = [ColorParser parse:dict key:@"color"]; self.translucent = [BoolParser parse:dict key:@"translucent"]; @@ -11,4 +11,11 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNScrollEdgeAppearanceBackgroundOptions *)options { + if (options.color.hasValue) + self.color = options.color; + if (options.translucent.hasValue) + self.translucent = options.translucent; +} + @end diff --git a/lib/ios/RNNScrollEdgeAppearanceOptions.m b/lib/ios/RNNScrollEdgeAppearanceOptions.m index d231c684134..72a888c3005 100644 --- a/lib/ios/RNNScrollEdgeAppearanceOptions.m +++ b/lib/ios/RNNScrollEdgeAppearanceOptions.m @@ -3,12 +3,19 @@ @implementation RNNScrollEdgeAppearanceOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; - + self = [super initWithDict:dict]; self.background = [[RNNScrollEdgeAppearanceBackgroundOptions alloc] initWithDict:dict[@"background"]]; self.active = [BoolParser parse:dict key:@"active"]; + return self; } +- (void)mergeOptions:(RNNScrollEdgeAppearanceOptions *)options { + [self.background mergeOptions:options.background]; + + if (options.active.hasValue) + self.active = options.active; +} + @end diff --git a/lib/ios/RNNSearchBarOptions.m b/lib/ios/RNNSearchBarOptions.m index 89115f4825d..9b919d7be42 100644 --- a/lib/ios/RNNSearchBarOptions.m +++ b/lib/ios/RNNSearchBarOptions.m @@ -3,8 +3,7 @@ @implementation RNNSearchBarOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; - + self = [super initWithDict:dict]; self.visible = [BoolParser parse:dict key:@"visible"]; self.focus = [BoolParser parse:dict key:@"focus"]; self.hideOnScroll = [BoolParser parse:dict key:@"hiddenWhenScrolling"]; @@ -17,4 +16,21 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNSearchBarOptions *)options { + if (options.visible.hasValue) + self.visible = options.visible; + if (options.hideOnScroll.hasValue) + self.hideOnScroll = options.hideOnScroll; + if (options.hideTopBarOnFocus.hasValue) + self.hideTopBarOnFocus = options.hideTopBarOnFocus; + if (options.obscuresBackgroundDuringPresentation.hasValue) + self.obscuresBackgroundDuringPresentation = options.obscuresBackgroundDuringPresentation; + if (options.backgroundColor.hasValue) + self.backgroundColor = options.backgroundColor; + if (options.tintColor.hasValue) + self.tintColor = options.tintColor; + if (options.placeholder.hasValue) + self.placeholder = options.placeholder; +} + @end diff --git a/lib/ios/RNNSharedElementAnimationOptions.m b/lib/ios/RNNSharedElementAnimationOptions.m index f9bd44fa1f2..c4ae5c47c68 100644 --- a/lib/ios/RNNSharedElementAnimationOptions.m +++ b/lib/ios/RNNSharedElementAnimationOptions.m @@ -7,7 +7,7 @@ @implementation RNNSharedElementAnimationOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.animations = dict[@"animations"]; self.duration = dict[@"duration"]; diff --git a/lib/ios/RNNSideMenuOptions.m b/lib/ios/RNNSideMenuOptions.m index 9a4fc565bf9..610c51ea7ad 100644 --- a/lib/ios/RNNSideMenuOptions.m +++ b/lib/ios/RNNSideMenuOptions.m @@ -4,7 +4,7 @@ @implementation RNNSideMenuOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.left = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"left"]]; self.right = [[RNNSideMenuSideOptions alloc] initWithDict:dict[@"right"]]; @@ -14,4 +14,14 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNSideMenuOptions *)options { + [self.left mergeOptions:options.left]; + [self.right mergeOptions:options.right]; + + if (options.animationType.hasValue) + self.animationType = options.animationType; + if (options.openGestureMode.hasValue) + self.openGestureMode = options.openGestureMode; +} + @end diff --git a/lib/ios/RNNSideMenuSideOptions.m b/lib/ios/RNNSideMenuSideOptions.m index 12282464736..1f21afdd8d0 100644 --- a/lib/ios/RNNSideMenuSideOptions.m +++ b/lib/ios/RNNSideMenuSideOptions.m @@ -3,7 +3,7 @@ @implementation RNNSideMenuSideOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.visible = [BoolParser parse:dict key:@"visible"]; self.enabled = [BoolParser parse:dict key:@"enabled"]; @@ -14,4 +14,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNSideMenuSideOptions *)options { + if (options.visible.hasValue) + self.visible = options.visible; + if (options.enabled.hasValue) + self.enabled = options.enabled; + if (options.width.hasValue) + self.width = options.width; + if (options.shouldStretchDrawer.hasValue) + self.shouldStretchDrawer = options.shouldStretchDrawer; + if (options.animationVelocity.hasValue) + self.animationVelocity = options.animationVelocity; +} + @end diff --git a/lib/ios/RNNSplitViewOptions.m b/lib/ios/RNNSplitViewOptions.m index 7b0bcce0a3c..1da73b1187d 100644 --- a/lib/ios/RNNSplitViewOptions.m +++ b/lib/ios/RNNSplitViewOptions.m @@ -3,7 +3,7 @@ @implementation RNNSplitViewOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.displayMode = dict[@"displayMode"]; self.primaryEdge = dict[@"primaryEdge"]; @@ -13,4 +13,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNSplitViewOptions *)options { + if (options.displayMode) + self.displayMode = options.displayMode; + if (options.primaryEdge) + self.primaryEdge = options.primaryEdge; + if (options.minWidth.hasValue) + self.minWidth = options.minWidth; + if (options.maxWidth.hasValue) + self.maxWidth = options.maxWidth; + if (options.primaryBackgroundStyle) + self.primaryBackgroundStyle = options.primaryBackgroundStyle; +} + @end diff --git a/lib/ios/RNNStackPresenter.m b/lib/ios/RNNStackPresenter.m index f38d65a3073..bb68a406d9d 100644 --- a/lib/ios/RNNStackPresenter.m +++ b/lib/ios/RNNStackPresenter.m @@ -85,55 +85,55 @@ - (void)applyOptionsBeforePopping:(RNNNavigationOptions *)options { [_topBarPresenter applyOptionsBeforePopping:options.topBar]; } -- (void)mergeOptions:(RNNNavigationOptions *)options +- (void)mergeOptions:(RNNNavigationOptions *)mergeOptions resolvedOptions:(RNNNavigationOptions *)resolvedOptions { - [super mergeOptions:options resolvedOptions:resolvedOptions]; + [super mergeOptions:mergeOptions resolvedOptions:resolvedOptions]; RNNStackController *stack = self.stackController; - if (options.popGesture.hasValue) { - [_interactivePopGestureDelegate setEnabled:options.popGesture.get]; + if (mergeOptions.popGesture.hasValue) { + [_interactivePopGestureDelegate setEnabled:mergeOptions.popGesture.get]; } - if (options.rootBackgroundImage.hasValue) { - [stack setRootBackgroundImage:options.rootBackgroundImage.get]; + if (mergeOptions.rootBackgroundImage.hasValue) { + [stack setRootBackgroundImage:mergeOptions.rootBackgroundImage.get]; } - if (options.topBar.testID.hasValue) { - [stack setNavigationBarTestId:options.topBar.testID.get]; + if (mergeOptions.topBar.testID.hasValue) { + [stack setNavigationBarTestId:mergeOptions.topBar.testID.get]; } - if (options.topBar.visible.hasValue) { - [stack setNavigationBarVisible:options.topBar.visible.get - animated:[options.topBar.animate getWithDefaultValue:YES]]; + if (mergeOptions.topBar.visible.hasValue) { + [stack setNavigationBarVisible:mergeOptions.topBar.visible.get + animated:[mergeOptions.topBar.animate getWithDefaultValue:YES]]; } - if (options.topBar.hideOnScroll.hasValue) { - [stack hideBarsOnScroll:[options.topBar.hideOnScroll get]]; + if (mergeOptions.topBar.hideOnScroll.hasValue) { + [stack hideBarsOnScroll:[mergeOptions.topBar.hideOnScroll get]]; } - if (options.topBar.barStyle.hasValue) { - [stack setBarStyle:[RCTConvert UIBarStyle:options.topBar.barStyle.get]]; + if (mergeOptions.topBar.barStyle.hasValue) { + [stack setBarStyle:[RCTConvert UIBarStyle:mergeOptions.topBar.barStyle.get]]; } - if (options.topBar.background.clipToBounds.hasValue) { - [stack setNavigationBarClipsToBounds:[options.topBar.background.clipToBounds get]]; + if (mergeOptions.topBar.background.clipToBounds.hasValue) { + [stack setNavigationBarClipsToBounds:[mergeOptions.topBar.background.clipToBounds get]]; } - if (options.topBar.background.blur.hasValue) { - [stack setNavigationBarBlur:[options.topBar.background.blur get]]; + if (mergeOptions.topBar.background.blur.hasValue) { + [stack setNavigationBarBlur:[mergeOptions.topBar.background.blur get]]; } - if (options.topBar.background.component.name.hasValue) { - [self setCustomNavigationComponentBackground:options perform:nil]; + if (mergeOptions.topBar.background.component.name.hasValue) { + [self setCustomNavigationComponentBackground:mergeOptions perform:nil]; } - if (options.layout.backgroundColor.hasValue) { - [stack.view setBackgroundColor:options.layout.backgroundColor.get]; + if (mergeOptions.layout.backgroundColor.hasValue) { + [stack.view setBackgroundColor:mergeOptions.layout.backgroundColor.get]; } - RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[options - mergeInOptions:resolvedOptions] withDefault:[self defaultOptions]]; - [_topBarPresenter mergeOptions:options.topBar withDefault:withDefault.topBar]; + RNNNavigationOptions *withDefault = (RNNNavigationOptions *)[[resolvedOptions + mergeOptions:mergeOptions] withDefault:[self defaultOptions]]; + [_topBarPresenter mergeOptions:mergeOptions.topBar withDefault:withDefault.topBar]; } - (void)renderComponents:(RNNNavigationOptions *)options diff --git a/lib/ios/RNNStatusBarOptions.m b/lib/ios/RNNStatusBarOptions.m index 44a578f2f67..c47bd70891c 100644 --- a/lib/ios/RNNStatusBarOptions.m +++ b/lib/ios/RNNStatusBarOptions.m @@ -4,7 +4,7 @@ @implementation RNNStatusBarOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.blur = [BoolParser parse:dict key:@"blur"]; self.hideWithTopBar = [BoolParser parse:dict key:@"hideWithTopBar"]; @@ -15,4 +15,17 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNStatusBarOptions *)options { + if (options.blur.hasValue) + self.blur = options.blur; + if (options.hideWithTopBar.hasValue) + self.hideWithTopBar = options.hideWithTopBar; + if (options.visible.hasValue) + self.visible = options.visible; + if (options.animate.hasValue) + self.animate = options.animate; + if (options.style.hasValue) + self.style = options.style; +} + @end diff --git a/lib/ios/RNNSubtitleOptions.m b/lib/ios/RNNSubtitleOptions.m index a08cde0a6fd..f5d6e749f3d 100644 --- a/lib/ios/RNNSubtitleOptions.m +++ b/lib/ios/RNNSubtitleOptions.m @@ -3,7 +3,7 @@ @implementation RNNSubtitleOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.text = [TextParser parse:dict key:@"text"]; self.alignment = [TextParser parse:dict key:@"alignment"]; @@ -15,4 +15,19 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNSubtitleOptions *)options { + if (options.text.hasValue) + self.text = options.text; + if (options.alignment.hasValue) + self.alignment = options.alignment; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.fontWeight.hasValue) + self.fontWeight = options.fontWeight; + if (options.color.hasValue) + self.color = options.color; +} + @end diff --git a/lib/ios/RNNTitleOptions.m b/lib/ios/RNNTitleOptions.m index 4368e21fc47..9d612dbe96d 100644 --- a/lib/ios/RNNTitleOptions.m +++ b/lib/ios/RNNTitleOptions.m @@ -3,7 +3,7 @@ @implementation RNNTitleOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.text = [TextParser parse:dict key:@"text"]; self.fontFamily = [TextParser parse:dict key:@"fontFamily"]; @@ -16,6 +16,21 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNTitleOptions *)options { + [self.component mergeOptions:options.component]; + + if (options.text.hasValue) + self.text = options.text; + if (options.fontFamily.hasValue) + self.fontFamily = options.fontFamily; + if (options.fontSize.hasValue) + self.fontSize = options.fontSize; + if (options.fontWeight.hasValue) + self.fontWeight = options.fontWeight; + if (options.color.hasValue) + self.color = options.color; +} + - (BOOL)hasValue { return self.text.hasValue || self.fontFamily.hasValue || self.fontSize.hasValue || self.fontWeight.hasValue || self.color.hasValue || self.component.hasValue || diff --git a/lib/ios/RNNTopBarOptions.m b/lib/ios/RNNTopBarOptions.m index 912f3e9600b..78401eb5a0c 100644 --- a/lib/ios/RNNTopBarOptions.m +++ b/lib/ios/RNNTopBarOptions.m @@ -13,7 +13,7 @@ @interface RNNTopBarOptions () @implementation RNNTopBarOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.visible = [BoolParser parse:dict key:@"visible"]; self.hideOnScroll = [BoolParser parse:dict key:@"hideOnScroll"]; self.leftButtonColor = [ColorParser parse:dict key:@"leftButtonColor"]; @@ -24,7 +24,6 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.noBorder = [BoolParser parse:dict key:@"noBorder"]; self.borderColor = [ColorParser parse:dict key:@"borderColor"]; self.animate = [BoolParser parse:dict key:@"animate"]; - self.searchBar = [[RNNSearchBarOptions alloc] initWithDict:dict[@"searchBar"]]; self.searchBarHiddenWhenScrolling = [BoolParser parse:dict key:@"searchBarHiddenWhenScrolling"]; self.hideNavBarOnFocusSearchBar = [BoolParser parse:dict key:@"hideNavBarOnFocusSearchBar"]; self.testID = [TextParser parse:dict key:@"testID"]; @@ -32,6 +31,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.searchBarPlaceholder = [TextParser parse:dict key:@"searchBarPlaceholder"]; self.searchBarBackgroundColor = [ColorParser parse:dict key:@"searchBarBackgroundColor"]; self.searchBarTintColor = [ColorParser parse:dict key:@"searchBarTintColor"]; + self.searchBar = [[RNNSearchBarOptions alloc] initWithDict:dict[@"searchBar"]]; self.largeTitle = [[RNNLargeTitleOptions alloc] initWithDict:dict[@"largeTitle"]]; self.title = [[RNNTitleOptions alloc] initWithDict:dict[@"title"]]; self.subtitle = [[RNNSubtitleOptions alloc] initWithDict:dict[@"subtitle"]]; @@ -64,6 +64,57 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(RNNTopBarOptions *)options { + [self.searchBar mergeOptions:options.searchBar]; + [self.largeTitle mergeOptions:options.largeTitle]; + [self.title mergeOptions:options.title]; + [self.subtitle mergeOptions:options.subtitle]; + [self.background mergeOptions:options.background]; + [self.scrollEdgeAppearance mergeOptions:options.scrollEdgeAppearance]; + [self.backButton mergeOptions:options.backButton]; + [self.leftButtonStyle mergeOptions:options.leftButtonStyle]; + [self.rightButtonStyle mergeOptions:options.rightButtonStyle]; + + if (options.visible.hasValue) + self.visible = options.visible; + if (options.hideOnScroll) + self.hideOnScroll = options.hideOnScroll; + if (options.leftButtonColor.hasValue) + self.leftButtonColor = options.leftButtonColor; + if (options.rightButtonColor.hasValue) + self.rightButtonColor = options.rightButtonColor; + if (options.leftButtonDisabledColor.hasValue) + self.leftButtonDisabledColor = options.leftButtonDisabledColor; + if (options.rightButtonDisabledColor.hasValue) + self.rightButtonDisabledColor = options.rightButtonDisabledColor; + if (options.drawBehind.hasValue) + self.drawBehind = options.drawBehind; + if (options.noBorder.hasValue) + self.noBorder = options.noBorder; + if (options.borderColor.hasValue) + self.borderColor = options.borderColor; + if (options.animate.hasValue) + self.animate = options.animate; + if (options.searchBarHiddenWhenScrolling.hasValue) + self.searchBarHiddenWhenScrolling = options.searchBarHiddenWhenScrolling; + if (options.hideNavBarOnFocusSearchBar.hasValue) + self.hideNavBarOnFocusSearchBar = options.hideNavBarOnFocusSearchBar; + if (options.testID.hasValue) + self.testID = options.testID; + if (options.barStyle.hasValue) + self.barStyle = options.barStyle; + if (options.searchBarPlaceholder.hasValue) + self.searchBarPlaceholder = options.searchBarPlaceholder; + if (options.searchBarBackgroundColor.hasValue) + self.searchBarBackgroundColor = options.searchBarBackgroundColor; + if (options.searchBarTintColor.hasValue) + self.searchBarTintColor = options.searchBarTintColor; + if (options.leftButtons) + self.leftButtons = options.leftButtons; + if (options.rightButtons) + self.rightButtons = options.rightButtons; +} + - (BOOL)shouldDrawBehind { return [self.drawBehind getWithDefaultValue:NO] || [self.background.translucent getWithDefaultValue:NO] || diff --git a/lib/ios/RNNTopTabOptions.m b/lib/ios/RNNTopTabOptions.m index 5a2cf7e7f72..4dd192a5839 100644 --- a/lib/ios/RNNTopTabOptions.m +++ b/lib/ios/RNNTopTabOptions.m @@ -9,4 +9,7 @@ @implementation RNNTopTabOptions // } //} +- (void)mergeOptions:(RNNTopTabOptions *)options { +} + @end diff --git a/lib/ios/RNNTopTabsOptions.m b/lib/ios/RNNTopTabsOptions.m index 0ca4050b966..addf6e6264a 100644 --- a/lib/ios/RNNTopTabsOptions.m +++ b/lib/ios/RNNTopTabsOptions.m @@ -3,4 +3,9 @@ @implementation RNNTopTabsOptions +- (void)mergeOptions:(RNNTopTabsOptions *)options { + if (options.backgroundColor.hasValue) + self.backgroundColor = options.backgroundColor; +} + @end diff --git a/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj b/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj index 7225b23102d..603e4fdb542 100644 --- a/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj +++ b/lib/ios/ReactNativeNavigation.xcodeproj/project.pbxproj @@ -369,8 +369,6 @@ 50EB4ED72068EBE000D6ED34 /* RNNBackgroundOptions.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EB4ED52068EBE000D6ED34 /* RNNBackgroundOptions.h */; }; 50EB4ED82068EBE000D6ED34 /* RNNBackgroundOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EB4ED62068EBE000D6ED34 /* RNNBackgroundOptions.m */; }; 50EB93421FE14A3E00BD8EEE /* RNNBottomTabOptions.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EB93401FE14A3E00BD8EEE /* RNNBottomTabOptions.m */; }; - 50EF5BAB24CD96F4009CBFD0 /* NSObject+Utils.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EF5BA924CD96F4009CBFD0 /* NSObject+Utils.h */; }; - 50EF5BAC24CD96F4009CBFD0 /* NSObject+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EF5BAA24CD96F4009CBFD0 /* NSObject+Utils.m */; }; 50EF5BC624D1878D009CBFD0 /* RNNModalManagerEventHandler.h in Headers */ = {isa = PBXBuildFile; fileRef = 50EF5BC424D1878D009CBFD0 /* RNNModalManagerEventHandler.h */; }; 50EF5BC724D1878D009CBFD0 /* RNNModalManagerEventHandler.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EF5BC524D1878D009CBFD0 /* RNNModalManagerEventHandler.m */; }; 50F5DFC11F407A8C001A00BC /* RNNBottomTabsController.h in Headers */ = {isa = PBXBuildFile; fileRef = 50F5DFBF1F407A8C001A00BC /* RNNBottomTabsController.h */; }; @@ -883,8 +881,6 @@ 50EB4ED62068EBE000D6ED34 /* RNNBackgroundOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBackgroundOptions.m; sourceTree = ""; }; 50EB933F1FE14A3E00BD8EEE /* RNNBottomTabOptions.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBottomTabOptions.h; sourceTree = ""; }; 50EB93401FE14A3E00BD8EEE /* RNNBottomTabOptions.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNBottomTabOptions.m; sourceTree = ""; }; - 50EF5BA924CD96F4009CBFD0 /* NSObject+Utils.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSObject+Utils.h"; sourceTree = ""; }; - 50EF5BAA24CD96F4009CBFD0 /* NSObject+Utils.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSObject+Utils.m"; sourceTree = ""; }; 50EF5BC424D1878D009CBFD0 /* RNNModalManagerEventHandler.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNModalManagerEventHandler.h; sourceTree = ""; }; 50EF5BC524D1878D009CBFD0 /* RNNModalManagerEventHandler.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNNModalManagerEventHandler.m; sourceTree = ""; }; 50F5DFBF1F407A8C001A00BC /* RNNBottomTabsController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNNBottomTabsController.h; sourceTree = ""; }; @@ -1075,8 +1071,6 @@ 9F8E06B424EBDB48004BDA83 /* RCTConvert+Interpolation.m */, 5095BB702416A3B900C4CD41 /* RNNConvert.h */, 5095BB712416A3B900C4CD41 /* RNNConvert.m */, - 50EF5BA924CD96F4009CBFD0 /* NSObject+Utils.h */, - 50EF5BAA24CD96F4009CBFD0 /* NSObject+Utils.m */, 5038A3BB216E1490009280BC /* RNNTabBarItemCreator.h */, 5038A3BC216E1490009280BC /* RNNTabBarItemCreator.m */, 5022EDBF24053C9F00852BA6 /* TabBarItemAppearanceCreator.h */, @@ -1890,7 +1884,6 @@ 5039559B2174867000B0A663 /* DoubleParser.h in Headers */, E8AEDB3C1F55A1C2000F5A6A /* RNNElementView.h in Headers */, E8E518321F83B3E0000467AC /* RNNUtils.h in Headers */, - 50EF5BAB24CD96F4009CBFD0 /* NSObject+Utils.h in Headers */, 50E5F791223FA04C002AFEAD /* TransitionDetailsOptions.h in Headers */, 50D4656D23CE2553005A84B2 /* Transition.h in Headers */, 5049594E216F6277006D2B81 /* NumberParser.h in Headers */, @@ -2125,7 +2118,6 @@ 5022EDBE2405237100852BA6 /* BottomTabPresenterCreator.m in Sources */, 5038A3C7216E2D93009280BC /* Number.m in Sources */, E5F6C3A622DB4D0F0093C2CE /* UIViewController+Utils.m in Sources */, - 50EF5BAC24CD96F4009CBFD0 /* NSObject+Utils.m in Sources */, 5048862E20BE976D000908DE /* RNNLayoutOptions.m in Sources */, 501CD320214A5B6900A6E225 /* RNNLayoutInfo.m in Sources */, 7BEF0D191E437684003E96B0 /* RNNComponentViewController.m in Sources */, diff --git a/lib/ios/StackControllerDelegate.m b/lib/ios/StackControllerDelegate.m index 1db955a19ca..e3c0402ec1d 100644 --- a/lib/ios/StackControllerDelegate.m +++ b/lib/ios/StackControllerDelegate.m @@ -30,9 +30,11 @@ - (void)navigationController:(UINavigationController *)navigationController animationControllerForOperation:(UINavigationControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC { + RNNNavigationOptions *toVCOptionsWithDefault = toVC.resolveOptionsWithDefault; + RNNNavigationOptions *fromVCOptionsWithDefault = fromVC.resolveOptionsWithDefault; if (operation == UINavigationControllerOperationPush && - toVC.resolveOptionsWithDefault.animations.push.hasCustomAnimation) { - RNNScreenTransition *screenTransition = toVC.resolveOptions.animations.push; + toVCOptionsWithDefault.animations.push.hasCustomAnimation) { + RNNScreenTransition *screenTransition = toVCOptionsWithDefault.animations.push; return [[TransitionDelegate alloc] initWithContentTransition:screenTransition.content elementTransitions:screenTransition.elementTransitions @@ -40,8 +42,8 @@ - (void)navigationController:(UINavigationController *)navigationController duration:screenTransition.maxDuration bridge:_eventEmitter.bridge]; } else if (operation == UINavigationControllerOperationPop && - fromVC.resolveOptionsWithDefault.animations.pop.hasCustomAnimation) { - RNNScreenTransition *screenTransition = fromVC.resolveOptions.animations.pop; + fromVCOptionsWithDefault.animations.pop.hasCustomAnimation) { + RNNScreenTransition *screenTransition = fromVCOptionsWithDefault.animations.pop; return [[ReversedTransitionDelegate alloc] initWithContentTransition:screenTransition.content elementTransitions:screenTransition.elementTransitions diff --git a/lib/ios/TransitionDetailsOptions.m b/lib/ios/TransitionDetailsOptions.m index d67c522d3c8..c5021f79979 100644 --- a/lib/ios/TransitionDetailsOptions.m +++ b/lib/ios/TransitionDetailsOptions.m @@ -4,7 +4,7 @@ @implementation TransitionDetailsOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.from = [DoubleParser parse:dict key:@"from"]; self.to = [DoubleParser parse:dict key:@"to"]; @@ -15,6 +15,19 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(TransitionDetailsOptions *)options { + if (options.from.hasValue) + self.from = options.from; + if (options.to.hasValue) + self.to = options.to; + if (options.startDelay.hasValue) + self.startDelay = options.startDelay; + if (options.duration.hasValue) + self.duration = options.duration; + if (options.interpolator) + self.interpolator = options.interpolator; +} + - (BOOL)hasAnimation { return self.from.hasValue || self.to.hasValue; } diff --git a/lib/ios/TransitionOptions.m b/lib/ios/TransitionOptions.m index 1884a9ee06d..04084bc8763 100644 --- a/lib/ios/TransitionOptions.m +++ b/lib/ios/TransitionOptions.m @@ -3,7 +3,7 @@ @implementation TransitionOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.alpha = [[TransitionDetailsOptions alloc] initWithDict:dict[@"alpha"]]; self.x = [[TransitionDetailsOptions alloc] initWithDict:dict[@"x"]]; @@ -19,6 +19,21 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(TransitionOptions *)options { + [self.alpha mergeOptions:options.alpha]; + [self.x mergeOptions:options.x]; + [self.y mergeOptions:options.y]; + [self.translationX mergeOptions:options.translationX]; + [self.translationY mergeOptions:options.translationY]; + [self.rotationX mergeOptions:options.rotationX]; + [self.rotationY mergeOptions:options.rotationY]; + + if (options.enable.hasValue) + self.enable = options.enable; + if (options.waitForRender.hasValue) + self.waitForRender = options.waitForRender; +} + - (BOOL)hasAnimation { return self.x.hasAnimation || self.y.hasAnimation || self.alpha.hasAnimation || self.translationX.hasAnimation || self.translationY.hasAnimation || diff --git a/lib/ios/UIViewController+LayoutProtocol.h b/lib/ios/UIViewController+LayoutProtocol.h index 30d4bbec398..727ae9ad6e0 100644 --- a/lib/ios/UIViewController+LayoutProtocol.h +++ b/lib/ios/UIViewController+LayoutProtocol.h @@ -32,8 +32,6 @@ typedef void (^RNNReactViewReadyCompletionBlock)(void); - (void)setDefaultOptions:(RNNNavigationOptions *)defaultOptions; -- (void)overrideOptions:(RNNNavigationOptions *)options; - - (void)readyForPresentation; - (void)componentDidAppear; diff --git a/lib/ios/UIViewController+LayoutProtocol.m b/lib/ios/UIViewController+LayoutProtocol.m index 9917fddc0cd..0a3fd537b71 100644 --- a/lib/ios/UIViewController+LayoutProtocol.m +++ b/lib/ios/UIViewController+LayoutProtocol.m @@ -27,7 +27,7 @@ - (instancetype)initWithLayoutInfo:(RNNLayoutInfo *)layoutInfo } - (void)mergeOptions:(RNNNavigationOptions *)options { - [self.options overrideOptions:options]; + [self.options mergeOptions:options]; [self.presenter mergeOptions:options resolvedOptions:self.resolveOptions]; [self.parentViewController mergeChildOptions:options child:self]; } @@ -38,17 +38,13 @@ - (void)mergeChildOptions:(RNNNavigationOptions *)options child:(UIViewControlle } - (RNNNavigationOptions *)resolveOptions { - return (RNNNavigationOptions *)[self.options - mergeInOptions:self.getCurrentChild.resolveOptions.copy]; + return (RNNNavigationOptions *)[self.options.copy + mergeOptions:self.getCurrentChild.resolveOptions]; } - (RNNNavigationOptions *)resolveOptionsWithDefault { - return [(RNNNavigationOptions *)[self.options - mergeInOptions:self.getCurrentChild.resolveOptions.copy] withDefault:self.defaultOptions]; -} - -- (void)overrideOptions:(RNNNavigationOptions *)options { - [self.options overrideOptions:options]; + return [(RNNNavigationOptions *)[self.options.copy + mergeOptions:self.getCurrentChild.resolveOptions] withDefault:self.defaultOptions]; } - (UINavigationController *)stack { diff --git a/lib/ios/ViewAnimationOptions.m b/lib/ios/ViewAnimationOptions.m index 08b90de557e..2b86221dd13 100644 --- a/lib/ios/ViewAnimationOptions.m +++ b/lib/ios/ViewAnimationOptions.m @@ -16,6 +16,13 @@ - (instancetype)initWithDict:(NSDictionary *)dict { return self; } +- (void)mergeOptions:(ViewAnimationOptions *)options { + if (options.sharedElementTransitions) + self.sharedElementTransitions = options.sharedElementTransitions; + if (options.elementTransitions) + self.elementTransitions = options.elementTransitions; +} + - (BOOL)hasAnimation { return super.hasAnimation || self.sharedElementTransitions || self.elementTransitions; } diff --git a/lib/ios/WindowOptions.m b/lib/ios/WindowOptions.m index ac073ceffeb..78e6e8aa610 100644 --- a/lib/ios/WindowOptions.m +++ b/lib/ios/WindowOptions.m @@ -3,9 +3,14 @@ @implementation WindowOptions - (instancetype)initWithDict:(NSDictionary *)dict { - self = [super init]; + self = [super initWithDict:dict]; self.backgroundColor = [ColorParser parse:dict key:@"backgroundColor"]; return self; } +- (void)mergeOptions:(WindowOptions *)options { + if (options.backgroundColor.hasValue) + self.backgroundColor = options.backgroundColor; +} + @end diff --git a/playground/ios/NavigationIOS12Tests/RNNBottomTabsPresenterTest.m b/playground/ios/NavigationIOS12Tests/RNNBottomTabsPresenterTest.m index 9d8b7a00d34..48e963a73cd 100644 --- a/playground/ios/NavigationIOS12Tests/RNNBottomTabsPresenterTest.m +++ b/playground/ios/NavigationIOS12Tests/RNNBottomTabsPresenterTest.m @@ -19,11 +19,11 @@ - (void)setUp { self.uut = [OCMockObject partialMockForObject:[RNNBottomTabsPresenter new]]; self.boundViewController = [OCMockObject partialMockForObject:[RNNBottomTabsController new]]; [self.uut bindViewController:self.boundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)testApplyOptions_shouldSetDefaultEmptyOptions { - RNNNavigationOptions *emptyOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *emptyOptions = [RNNNavigationOptions emptyOptions]; [[self.boundViewController expect] setTabBarTestID:nil]; [[(id)self.uut expect] applyBackgroundColor:nil translucent:NO]; [[self.boundViewController expect] setTabBarHideShadow:NO]; @@ -34,7 +34,7 @@ - (void)testApplyOptions_shouldSetDefaultEmptyOptions { } - (void)testApplyOptions_shouldApplyOptions { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"]; initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]]; initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)]; @@ -52,7 +52,7 @@ - (void)testApplyOptions_shouldApplyOptions { } - (void)testApplyOptions_shouldRestoreHiddenTabBar { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)]; [[self.boundViewController expect] setTabBarVisible:YES]; @@ -62,7 +62,7 @@ - (void)testApplyOptions_shouldRestoreHiddenTabBar { } - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"]; [[self.boundViewController reject] centerTabItems]; [self.uut applyOptionsOnInit:initialOptions]; @@ -70,7 +70,7 @@ - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages { } - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"]; [[self.boundViewController expect] centerTabItems]; [self.uut applyOptionsOnInit:initialOptions]; diff --git a/playground/ios/NavigationIOS12Tests/RNNRootViewControllerTest.m b/playground/ios/NavigationIOS12Tests/RNNRootViewControllerTest.m index cc642d2afd6..9be7a57b500 100644 --- a/playground/ios/NavigationIOS12Tests/RNNRootViewControllerTest.m +++ b/playground/ios/NavigationIOS12Tests/RNNRootViewControllerTest.m @@ -667,31 +667,35 @@ - (void)testBackgroundImage { } - (void)testMergeOptionsShouldCallPresenterMergeOptions { - RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - [[(id)self.uut.presenter expect] mergeOptions:newOptions resolvedOptions:self.uut.options]; + RNNNavigationOptions *newOptions = [RNNNavigationOptions emptyOptions]; + [[(id)self.uut.presenter expect] + mergeOptions:newOptions + resolvedOptions:[OCMArg checkWithBlock:^BOOL(RNNNavigationOptions *options) { + return [options isKindOfClass:RNNNavigationOptions.class]; + }]]; [self.uut mergeOptions:newOptions]; [(id)self.uut.presenter verify]; } - (void)testOverrideOptions { - RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *newOptions = [RNNNavigationOptions emptyOptions]; newOptions.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]]; - [self.uut overrideOptions:newOptions]; + [self.uut mergeOptions:newOptions]; XCTAssertEqual([UIColor redColor], self.uut.options.topBar.background.color.get); } #pragma mark BottomTabs - (RNNStackController *)createNavigationController { - RNNStackController *nav = [[RNNStackController alloc] - initWithLayoutInfo:nil - creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - presenter:[[RNNStackPresenter alloc] init] - eventEmitter:nil - childViewControllers:@[ self.uut ]]; + RNNStackController *nav = + [[RNNStackController alloc] initWithLayoutInfo:nil + creator:nil + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + presenter:[[RNNStackPresenter alloc] init] + eventEmitter:nil + childViewControllers:@[ self.uut ]]; [nav viewWillAppear:NO]; return nav; } diff --git a/playground/ios/NavigationTests/BottomTabPresenterTest.m b/playground/ios/NavigationTests/BottomTabPresenterTest.m index dab241cbfe5..5611b7b412e 100644 --- a/playground/ios/NavigationTests/BottomTabPresenterTest.m +++ b/playground/ios/NavigationTests/BottomTabPresenterTest.m @@ -21,13 +21,13 @@ @implementation RNNBottomTabPresenterTest - (void)setUp { [super setUp]; self.uut = [[BottomTabAppearancePresenter alloc] - initWithDefaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + initWithDefaultOptions:[RNNNavigationOptions emptyOptions]]; self.componentViewController = [RNNComponentViewController new]; self.boundViewController = [RNNBottomTabsController createWithChildren:@[ self.componentViewController ]]; self.mockBoundViewController = [OCMockObject partialMockForObject:self.boundViewController]; [self.uut bindViewController:self.mockBoundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)tearDown { @@ -43,11 +43,11 @@ - (void)testApplyOptions_shouldSetTabBarItemBadgeWithValue { } - (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions { - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor]; self.uut.defaultOptions = defaultOptions; - RNNNavigationOptions *mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *mergeOptions = [RNNNavigationOptions emptyOptions]; mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"]; [self.uut mergeOptions:mergeOptions @@ -57,11 +57,11 @@ - (void)testMergeOptions_shouldSetTabBarItemColorWithDefaultOptions { } - (void)testMergeOptions_shouldCreateNewTabBarItemInstance { - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; defaultOptions.bottomTab.selectedIconColor = [Color withColor:UIColor.greenColor]; self.uut.defaultOptions = defaultOptions; - RNNNavigationOptions *mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *mergeOptions = [RNNNavigationOptions emptyOptions]; mergeOptions.bottomTab.text = [[Text alloc] initWithValue:@"title"]; UITabBarItem *currentTabBarItem = self.componentViewController.tabBarItem; diff --git a/playground/ios/NavigationTests/BottomTabsControllerTest.m b/playground/ios/NavigationTests/BottomTabsControllerTest.m index 985c0e0016d..002d517081a 100644 --- a/playground/ios/NavigationTests/BottomTabsControllerTest.m +++ b/playground/ios/NavigationTests/BottomTabsControllerTest.m @@ -218,7 +218,7 @@ - (void)testSetSelectedIndexByComponentID_ShouldSetSelectedIndexWithCorrectIndex } - (void)testSetSelectedIndex_ShouldSetSelectedIndexWithCurrentTabIndex { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.bottomTabs.currentTabIndex = [[IntNumber alloc] initWithValue:@(1)]; RNNComponentViewController *vc = [[RNNComponentViewController alloc] initWithLayoutInfo:nil @@ -236,7 +236,7 @@ - (void)testSetSelectedIndex_ShouldSetSelectedIndexWithCurrentTabIndex { } - (void)testDidSelectViewController_emitEventOnTabPress { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; RNNComponentViewController *vc = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil @@ -255,7 +255,7 @@ - (void)testDidSelectViewController_emitEventOnTabPress { } - (void)testTabLongPress_ShouldEmitEvent { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; RNNComponentViewController *vc = [[RNNComponentViewController alloc] initWithLayoutInfo:nil rootViewCreator:nil eventEmitter:nil diff --git a/playground/ios/NavigationTests/NSObjectUtilsTests.m b/playground/ios/NavigationTests/NSObjectUtilsTests.m deleted file mode 100644 index 8cdc8e8ad28..00000000000 --- a/playground/ios/NavigationTests/NSObjectUtilsTests.m +++ /dev/null @@ -1,38 +0,0 @@ -#import -#import -#import -#import - -@interface TestClass : NSObject -@property(nonatomic, strong) NSString *testProperty; -@end -@implementation TestClass -@end - -@interface TestSubClass : TestClass -@property(nonatomic, strong) NSString *testSubProperty; -@end -@implementation TestSubClass -@end - -@interface NSObjectUtilsTests : XCTestCase - -@end - -@implementation NSObjectUtilsTests - -- (void)testReturnClassProperties { - TestClass *testObject = [TestClass new]; - NSArray *properties = [testObject classProperties]; - NSArray *expectedProperties = @[ @"testProperty" ]; - XCTAssertTrue([properties isEqualToArray:expectedProperties]); -} - -- (void)testReturnSuperClassProperties { - TestSubClass *testObject = [TestSubClass new]; - NSArray *properties = [testObject classProperties]; - NSArray *expectedProperties = @[ @"testSubProperty", @"testProperty" ]; - XCTAssertTrue([properties isEqualToArray:expectedProperties]); -} - -@end diff --git a/playground/ios/NavigationTests/RNNBasePresenterTest.m b/playground/ios/NavigationTests/RNNBasePresenterTest.m index 521b7b25ac4..2e065097d60 100644 --- a/playground/ios/NavigationTests/RNNBasePresenterTest.m +++ b/playground/ios/NavigationTests/RNNBasePresenterTest.m @@ -17,14 +17,14 @@ @implementation RNNBasePresenterTest - (void)setUp { [super setUp]; - self.uut = [[RNNBasePresenter alloc] - initWithDefaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + self.uut = + [[RNNBasePresenter alloc] initWithDefaultOptions:[RNNNavigationOptions emptyOptions]]; self.boundViewController = [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:[RNNNavigationOptions emptyOptions]]; self.mockBoundViewController = [OCMockObject partialMockForObject:self.boundViewController]; [self.uut bindViewController:self.mockBoundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)tearDown { @@ -74,7 +74,7 @@ - (void)testGetPreferredStatusBarStyle_returnDefaultIfNil { } - (void)testGetPreferredStatusBarStyle_considersDefaultOptions { - RNNNavigationOptions *lightOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *lightOptions = [RNNNavigationOptions emptyOptions]; lightOptions.statusBar.style = [[Text alloc] initWithValue:@"light"]; [_uut setDefaultOptions:lightOptions]; diff --git a/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m b/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m index 8f9968caf38..b774897cfce 100644 --- a/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m +++ b/playground/ios/NavigationTests/RNNBottomTabsAppearancePresenterTest.m @@ -48,11 +48,11 @@ - (void)setUp { bottomTabsAttacher:nil]]; [self.boundViewController viewWillAppear:YES]; [self.uut bindViewController:self.boundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)testApplyOptions_shouldSetDefaultEmptyOptions { - RNNNavigationOptions *emptyOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *emptyOptions = [RNNNavigationOptions emptyOptions]; [[self.boundViewController expect] setTabBarTestID:nil]; [[(id)self.uut expect] applyBackgroundColor:nil translucent:NO]; [[self.boundViewController expect] setTabBarHideShadow:NO]; @@ -63,7 +63,7 @@ - (void)testApplyOptions_shouldSetDefaultEmptyOptions { } - (void)testApplyOptions_shouldApplyOptions { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.testID = [[Text alloc] initWithValue:@"testID"]; initialOptions.bottomTabs.backgroundColor = [[Color alloc] initWithValue:[UIColor redColor]]; initialOptions.bottomTabs.translucent = [[Bool alloc] initWithValue:@(0)]; @@ -81,7 +81,7 @@ - (void)testApplyOptions_shouldApplyOptions { } - (void)testApplyOptions_shouldRestoreHiddenTabBar { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.visible = [[Bool alloc] initWithValue:@(1)]; [[self.boundViewController expect] setTabBarVisible:YES]; @@ -91,7 +91,7 @@ - (void)testApplyOptions_shouldRestoreHiddenTabBar { } - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysShow"]; [[self.boundViewController reject] centerTabItems]; [self.uut applyOptionsOnInit:initialOptions]; @@ -99,7 +99,7 @@ - (void)testApplyOptionsOnInit_alwaysShow_shouldNotCenterTabImages { } - (void)testApplyOptions_shouldApplyOptionsOnInit_alwaysHide_shouldCenterTabImages { - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.bottomTabs.titleDisplayMode = [[Text alloc] initWithValue:@"alwaysHide"]; [[self.boundViewController expect] centerTabItems]; [self.uut applyOptionsOnInit:initialOptions]; diff --git a/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m b/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m index e030fd13dea..8282e5c95b7 100644 --- a/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m +++ b/playground/ios/NavigationTests/RNNBottomTabsController+Helpers.m @@ -10,13 +10,12 @@ + (RNNBottomTabsController *)create { } + (RNNBottomTabsController *)createWithChildren:(NSArray *)children { - return [self createWithChildren:children - options:[[RNNNavigationOptions alloc] initEmptyOptions]]; + return [self createWithChildren:children options:[RNNNavigationOptions emptyOptions]]; } + (RNNBottomTabsController *)createWithChildren:(NSArray *)children options:(RNNNavigationOptions *)options { - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; return [[RNNBottomTabsController alloc] initWithLayoutInfo:nil creator:nil diff --git a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m index da01d00513e..5a013a91b85 100644 --- a/playground/ios/NavigationTests/RNNCommandsHandlerTest.m +++ b/playground/ios/NavigationTests/RNNCommandsHandlerTest.m @@ -156,14 +156,14 @@ - (void)testDynamicStylesMergeWithStaticStyles { [RNNComponentViewController createWithComponentId:@"componentId" initialOptions:initialOptions]; - RNNStackController *nav = [[RNNStackController alloc] - initWithLayoutInfo:nil - creator:creator - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - presenter:[[RNNStackPresenter alloc] init] - eventEmitter:nil - childViewControllers:@[ vc ]]; + RNNStackController *nav = + [[RNNStackController alloc] initWithLayoutInfo:nil + creator:creator + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + presenter:[[RNNStackPresenter alloc] init] + eventEmitter:nil + childViewControllers:@[ vc ]]; [self.mainWindow setRootViewController:nav]; [vc viewWillAppear:false]; XCTAssertTrue([vc.navigationItem.title isEqual:@"the title"]); @@ -433,7 +433,7 @@ - (void)testSetStackRoot_waitForRender { - (void)testSetRoot_waitForRenderTrue { [self.uut setReadyToReceiveCommands:true]; - self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.vc1.options = [RNNNavigationOptions emptyOptions]; self.vc1.options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES]; id mockedVC = [OCMockObject partialMockForObject:self.vc1]; @@ -449,7 +449,7 @@ - (void)testSetRoot_waitForRenderTrue { - (void)testSetRoot_waitForRenderFalse { [self.uut setReadyToReceiveCommands:true]; - self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.vc1.options = [RNNNavigationOptions emptyOptions]; self.vc1.options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:NO]; id mockedVC = [OCMockObject partialMockForObject:self.vc1]; @@ -465,22 +465,22 @@ - (void)testSetRoot_waitForRenderFalse { - (void)testSetRoot_withBottomTabsAttachModeTogether { [self.uut setReadyToReceiveCommands:true]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.bottomTabs.tabsAttachMode = [[BottomTabsAttachMode alloc] initWithValue:@"together"]; BottomTabsBaseAttacher *attacher = [[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options]; - RNNBottomTabsController *tabBarController = [[RNNBottomTabsController alloc] - initWithLayoutInfo:nil - creator:nil - options:options - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] - presenter:[RNNBasePresenter new] - bottomTabPresenter:nil - dotIndicatorPresenter:nil - eventEmitter:_eventEmmiter - childViewControllers:@[ _vc1, _vc2 ] - bottomTabsAttacher:attacher]; + RNNBottomTabsController *tabBarController = + [[RNNBottomTabsController alloc] initWithLayoutInfo:nil + creator:nil + options:options + defaultOptions:[RNNNavigationOptions emptyOptions] + presenter:[RNNBasePresenter new] + bottomTabPresenter:nil + dotIndicatorPresenter:nil + eventEmitter:_eventEmmiter + childViewControllers:@[ _vc1, _vc2 ] + bottomTabsAttacher:attacher]; OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController); @@ -496,24 +496,24 @@ - (void)testSetRoot_withBottomTabsAttachModeTogether { - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab { [self.uut setReadyToReceiveCommands:true]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.bottomTabs.tabsAttachMode = [[BottomTabsAttachMode alloc] initWithValue:@"onSwitchToTab"]; options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES]; BottomTabsBaseAttacher *attacher = [[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options]; - RNNBottomTabsController *tabBarController = [[RNNBottomTabsController alloc] - initWithLayoutInfo:nil - creator:nil - options:options - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] - presenter:[RNNBasePresenter new] - bottomTabPresenter:nil - dotIndicatorPresenter:nil - eventEmitter:_eventEmmiter - childViewControllers:@[ _vc1, _vc2 ] - bottomTabsAttacher:attacher]; + RNNBottomTabsController *tabBarController = + [[RNNBottomTabsController alloc] initWithLayoutInfo:nil + creator:nil + options:options + defaultOptions:[RNNNavigationOptions emptyOptions] + presenter:[RNNBasePresenter new] + bottomTabPresenter:nil + dotIndicatorPresenter:nil + eventEmitter:_eventEmmiter + childViewControllers:@[ _vc1, _vc2 ] + bottomTabsAttacher:attacher]; [tabBarController viewWillAppear:YES]; OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController); @@ -529,24 +529,24 @@ - (void)testSetRoot_withBottomTabsAttachModeOnSwitchToTab { - (void)testSetRoot_withBottomTabsAttachModeAfterInitialTab { [self.uut setReadyToReceiveCommands:true]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.bottomTabs.tabsAttachMode = [[BottomTabsAttachMode alloc] initWithValue:@"afterInitialTab"]; options.animations.setRoot.waitForRender = [[Bool alloc] initWithBOOL:YES]; BottomTabsBaseAttacher *attacher = [[[BottomTabsAttachModeFactory alloc] initWithDefaultOptions:nil] fromOptions:options]; - RNNBottomTabsController *tabBarController = [[RNNBottomTabsController alloc] - initWithLayoutInfo:nil - creator:nil - options:options - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] - presenter:[RNNBasePresenter new] - bottomTabPresenter:nil - dotIndicatorPresenter:nil - eventEmitter:_eventEmmiter - childViewControllers:@[ _vc1, _vc2 ] - bottomTabsAttacher:attacher]; + RNNBottomTabsController *tabBarController = + [[RNNBottomTabsController alloc] initWithLayoutInfo:nil + creator:nil + options:options + defaultOptions:[RNNNavigationOptions emptyOptions] + presenter:[RNNBasePresenter new] + bottomTabPresenter:nil + dotIndicatorPresenter:nil + eventEmitter:_eventEmmiter + childViewControllers:@[ _vc1, _vc2 ] + bottomTabsAttacher:attacher]; [tabBarController viewWillAppear:YES]; OCMStub([self.controllerFactory createLayout:[OCMArg any]]).andReturn(tabBarController); @@ -612,7 +612,7 @@ - (void)testMergeOptions_shouldMergeWithChildOnly { initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] + defaultOptions:[RNNNavigationOptions emptyOptions] presenter:[RNNBasePresenter new] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:[RNNNavigationOptions emptyOptions]] @@ -667,7 +667,7 @@ - (void)testMergeOptions_shouldResolveTreeOptions { initWithLayoutInfo:nil creator:nil options:[RNNNavigationOptions emptyOptions] - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] + defaultOptions:[RNNNavigationOptions emptyOptions] presenter:[RNNBasePresenter new] bottomTabPresenter:[BottomTabPresenterCreator createWithDefaultOptions:[RNNNavigationOptions emptyOptions]] @@ -694,7 +694,7 @@ - (void)testMergeOptions_shouldResolveTreeOptions { - (void)testShowModal_shouldShowAnimated { [self.uut setReadyToReceiveCommands:true]; - self.vc1.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.vc1.options = [RNNNavigationOptions emptyOptions]; self.vc1.options.animations.showModal.enable = [[Bool alloc] initWithBOOL:YES]; id mockedVC = [OCMockObject partialMockForObject:self.vc1]; diff --git a/playground/ios/NavigationTests/RNNComponentPresenterTest.m b/playground/ios/NavigationTests/RNNComponentPresenterTest.m index 756318a5658..d0e684b543a 100644 --- a/playground/ios/NavigationTests/RNNComponentPresenterTest.m +++ b/playground/ios/NavigationTests/RNNComponentPresenterTest.m @@ -1,5 +1,6 @@ #import "RNNComponentPresenter.h" #import "RNNComponentViewController.h" +#import "RNNReactTitleView.h" #import "RNNTitleViewHelper.h" #import "UIViewController+LayoutProtocol.h" #import "UIViewController+RNNOptions.h" @@ -22,10 +23,10 @@ - (void)setUp { self.componentRegistry = [OCMockObject partialMockForObject:[RNNReactComponentRegistry new]]; self.uut = [[RNNComponentPresenter alloc] initWithComponentRegistry:self.componentRegistry - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + defaultOptions:[RNNNavigationOptions emptyOptions]]; self.boundViewController = [OCMockObject partialMockForObject:[RNNComponentViewController new]]; [self.uut bindViewController:self.boundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)testApplyOptions_backgroundImageDefaultNilShouldNotAddSubview { @@ -140,7 +141,7 @@ - (void)testRenderComponentsCreateReactViewWithBoundComponentId { RNNComponentViewController *boundViewController = [RNNComponentViewController new]; RNNLayoutInfo *layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"]; boundViewController.layoutInfo = layoutInfo; - boundViewController.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + boundViewController.defaultOptions = [RNNNavigationOptions emptyOptions]; [self.uut bindViewController:boundViewController]; self.options.topBar.title.component = [[RNNComponentOptions alloc] @@ -163,7 +164,7 @@ - (void)testRenderComponentsCreateReactViewWithBoundComponentId { - (void)testRenderComponentsCreateReactViewFromDefaultOptions { RNNComponentViewController *boundViewController = [RNNComponentViewController new]; boundViewController.layoutInfo = [self createLayoutInfoWithComponentId:@"componentId"]; - self.uut.defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.uut.defaultOptions = [RNNNavigationOptions emptyOptions]; [self.uut bindViewController:boundViewController]; self.uut.defaultOptions.topBar.title.component = [[RNNComponentOptions alloc] @@ -196,16 +197,14 @@ - (void)testRemoveTitleComponentIfNeeded_componentIsRemovedIfTitleTextIsDefined component.componentId = [[Text alloc] initWithValue:@"someId"]; _options.topBar.title.component = component; - [self.uut mergeOptions:_options - resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + [self.uut mergeOptions:_options resolvedOptions:[RNNNavigationOptions emptyOptions]]; XCTAssertNotNil(self.boundViewController.navigationItem.titleView); XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle); [[mockTitle expect] removeFromSuperview]; - _options = [[RNNNavigationOptions alloc] initEmptyOptions]; + _options = [RNNNavigationOptions emptyOptions]; _options.topBar.title.text = [[Text alloc] initWithValue:@""]; - [self.uut mergeOptions:_options - resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + [self.uut mergeOptions:_options resolvedOptions:[RNNNavigationOptions emptyOptions]]; XCTAssertNotEqual(self.boundViewController.navigationItem.titleView, mockTitle); [mockTitle verify]; } @@ -224,15 +223,13 @@ - (void)testRemoveTitleComponentIfNeeded_componentIsRemovedIfTitleTextIsDefined component.componentId = [[Text alloc] initWithValue:@"someId"]; _options.topBar.title.component = component; - [self.uut mergeOptions:_options - resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + [self.uut mergeOptions:_options resolvedOptions:[RNNNavigationOptions emptyOptions]]; XCTAssertNotNil(self.boundViewController.navigationItem.titleView); XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle); - _options = [[RNNNavigationOptions alloc] initEmptyOptions]; + _options = [RNNNavigationOptions emptyOptions]; _options.bottomTabs.visible = [[Bool alloc] initWithBOOL:NO]; - [self.uut mergeOptions:_options - resolvedOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + [self.uut mergeOptions:_options resolvedOptions:[RNNNavigationOptions emptyOptions]]; XCTAssertEqual(self.boundViewController.navigationItem.titleView, mockTitle); } diff --git a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m index af4861dbe87..d37c4b2be3a 100644 --- a/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m +++ b/playground/ios/NavigationTests/RNNDotIndicatorPresenterTest.m @@ -35,7 +35,7 @@ - (void)tearDown { - (void)testApply_doesNothingIfDoesNotHaveValue { DotIndicatorOptions *empty = [DotIndicatorOptions new]; - [[self uut] apply:self.child:empty]; + [[self uut] apply:self.child options:empty]; XCTAssertFalse([self tabHasIndicator]); } @@ -50,7 +50,7 @@ - (void)testApply_indicatorIsRemovedIfNotVisible { DotIndicatorOptions *options = [DotIndicatorOptions new]; options.visible = [[Bool alloc] initWithBOOL:NO]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; XCTAssertFalse([self tabHasIndicator]); } @@ -58,7 +58,7 @@ - (void)testApply_indicatorIsRemovedIfNotVisible { - (void)testApply_invisibleIndicatorIsNotAdded { DotIndicatorOptions *options = [DotIndicatorOptions new]; options.visible = [[Bool alloc] initWithBOOL:NO]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; XCTAssertFalse([self tabHasIndicator]); } @@ -96,11 +96,11 @@ - (void)testApply_itRemovesPreviousIndicator { options.color = [[Color alloc] initWithValue:[UIColor redColor]]; options.size = [[Number alloc] initWithValue:[[NSNumber alloc] initWithInt:8]]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; XCTAssertTrue([self tabHasIndicator]); options.visible = [[Bool alloc] initWithBOOL:NO]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; XCTAssertFalse([self tabHasIndicator]); } @@ -108,7 +108,7 @@ - (void)testApply_indicatorIsAlignedToTopRightOfIcon { DotIndicatorOptions *options = [DotIndicatorOptions new]; options.visible = [[Bool alloc] initWithBOOL:YES]; options.size = [[Number alloc] initWithValue:[[NSNumber alloc] initWithInt:8]]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; UIView *indicator = [self getIndicator]; UIView *icon = [_bottomTabs getTabIcon:0]; @@ -133,7 +133,10 @@ - (void)testApply_indicatorIsAlignedToTopRightOfIcon { } - (void)testApply_onBottomTabsViewDidLayout { - [[self.uut expect] apply:self.child:self.child.resolveOptions.bottomTab.dotIndicator]; + [[self.uut expect] apply:self.child + options:[OCMArg checkWithBlock:^BOOL(DotIndicatorOptions *options) { + return [options isKindOfClass:DotIndicatorOptions.class]; + }]]; [self.uut bottomTabsDidLayoutSubviews:self.bottomTabs]; [self.uut verify]; } @@ -146,7 +149,7 @@ - (void)applyIndicator:(UIColor *)color { DotIndicatorOptions *options = [DotIndicatorOptions new]; options.visible = [[Bool alloc] initWithBOOL:YES]; options.color = [[Color alloc] initWithValue:color]; - [[self uut] apply:self.child:options]; + [[self uut] apply:self.child options:options]; } - (RNNComponentViewController *)createChild { @@ -160,14 +163,13 @@ - (RNNComponentViewController *)createChild { rootViewCreator:nil eventEmitter:nil presenter:[[RNNComponentPresenter alloc] - initWithDefaultOptions:[[RNNNavigationOptions alloc] - initEmptyOptions]] + initWithDefaultOptions:[RNNNavigationOptions emptyOptions]] options:options defaultOptions:nil]; } - (BOOL)tabHasIndicator { - return [self.child tabBarItem].tag > 0; + return [[self.child.tabBarController tabBar] viewWithTag:self.child.tabBarItem.tag]; } - (UIView *)getIndicator { @@ -175,4 +177,9 @@ - (UIView *)getIndicator { ? [[((UITabBarController *)_bottomTabs) tabBar] viewWithTag:_child.tabBarItem.tag] : nil; } + +- (UIView *)getIndicatorForTag:(NSInteger)tag { + return [[((UITabBarController *)_bottomTabs) tabBar] viewWithTag:tag]; +} + @end diff --git a/playground/ios/NavigationTests/RNNExternalViewControllerTests.m b/playground/ios/NavigationTests/RNNExternalViewControllerTests.m index 4b5feb6c57d..6e78bdb36af 100644 --- a/playground/ios/NavigationTests/RNNExternalViewControllerTests.m +++ b/playground/ios/NavigationTests/RNNExternalViewControllerTests.m @@ -19,13 +19,13 @@ - (void)setUp { layoutInfo.componentId = @"externalComponentId"; RNNComponentPresenter *presenter = [[RNNComponentPresenter alloc] initWithComponentRegistry:nil defaultOptions:nil]; - self.uut = [[RNNExternalViewController alloc] - initWithLayoutInfo:layoutInfo - eventEmitter:nil - presenter:presenter - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - viewController:self.customViewController]; + self.uut = + [[RNNExternalViewController alloc] initWithLayoutInfo:layoutInfo + eventEmitter:nil + presenter:presenter + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + viewController:self.customViewController]; } - (void)testLoadView_withMainScreenBounds { diff --git a/playground/ios/NavigationTests/RNNNavigationOptionsTest.m b/playground/ios/NavigationTests/RNNNavigationOptionsTest.m index 64412132eaa..802e84ab471 100644 --- a/playground/ios/NavigationTests/RNNNavigationOptionsTest.m +++ b/playground/ios/NavigationTests/RNNNavigationOptionsTest.m @@ -34,7 +34,7 @@ - (void)testChangeRNNNavigationOptionsDynamically { @{@"topBar" : @{@"textColor" : @(0xffff00ff), @"title" : @{@"text" : @"hello"}}}; RNNNavigationOptions *dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict]; - [options overrideOptions:dynamicOptions]; + [options mergeOptions:dynamicOptions]; XCTAssertTrue([options.topBar.title.text.get isEqual:@"hello"]); } @@ -45,7 +45,7 @@ - (void)testChangeRNNNavigationOptionsWithInvalidProperties { NSDictionary *dynamicOptionsDict = @{@"topBar" : @{@"titleeeee" : @"hello"}}; RNNNavigationOptions *dynamicOptions = [[RNNNavigationOptions alloc] initWithDict:dynamicOptionsDict]; - XCTAssertNoThrow([options overrideOptions:dynamicOptions]); + XCTAssertNoThrow([options mergeOptions:dynamicOptions]); } - (void)testWithDefault { @@ -64,5 +64,36 @@ - (void)testWithDefault { options.bottomTab.selectedIconColor.get); } +- (void)testWithDefault_shouldReturnCopiedObject { + RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:@{ + @"topBar" : @{@"subtitle" : @{@"text" : @"hey"}}, + @"bottomTab" : @{@"selectedIconColor" : @(0xff000000)} + }]; + RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initWithDict:@{ + @"topBar" : @{@"subtitle" : @{@"text" : @"ho"}, @"title" : @{@"text" : @"hello"}}, + @"bottomTab" : @{@"selectedIconColor" : @(0xff0000ff)} + }]; + + RNNNavigationOptions *withDefault = [options withDefault:defaultOptions]; + XCTAssertTrue(withDefault != options); + XCTAssertTrue(withDefault != defaultOptions); +} + +- (void)testMergeOptions_shouldOverridePreviousOptions { + RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initWithDict:@{ + @"topBar" : @{@"subtitle" : @{@"text" : @"ho"}}, + @"bottomTab" : @{@"selectedIconColor" : @(0xff000000)} + }]; + RNNNavigationOptions *mergeOptions = [[RNNNavigationOptions alloc] initWithDict:@{ + @"topBar" : @{@"subtitle" : @{@"text" : @"hey"}, @"title" : @{@"text" : @"hello"}}, + @"bottomTab" : @{@"selectedIconColor" : @(0xff0000ff)} + }]; + + [self measureBlock:^{ + RNNNavigationOptions *merged = [options mergeOptions:mergeOptions]; + XCTAssertTrue([merged.topBar.subtitle.text.get isEqualToString:@"hey"]); + XCTAssertTrue([merged.topBar.title.text.get isEqualToString:@"hello"]); + }]; +} @end diff --git a/playground/ios/NavigationTests/RNNRootViewControllerTest.m b/playground/ios/NavigationTests/RNNRootViewControllerTest.m index a7f13af4a7e..f14cad0c193 100644 --- a/playground/ios/NavigationTests/RNNRootViewControllerTest.m +++ b/playground/ios/NavigationTests/RNNRootViewControllerTest.m @@ -698,31 +698,35 @@ - (void)testBackgroundImage { } - (void)testMergeOptionsShouldCallPresenterMergeOptions { - RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - [[(id)self.uut.presenter expect] mergeOptions:newOptions resolvedOptions:self.uut.options]; + RNNNavigationOptions *newOptions = [RNNNavigationOptions emptyOptions]; + [[(id)self.uut.presenter expect] + mergeOptions:newOptions + resolvedOptions:[OCMArg checkWithBlock:^BOOL(RNNNavigationOptions *options) { + return [options isKindOfClass:RNNNavigationOptions.class]; + }]]; [self.uut mergeOptions:newOptions]; [(id)self.uut.presenter verify]; } - (void)testOverrideOptions { - RNNNavigationOptions *newOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *newOptions = [RNNNavigationOptions emptyOptions]; newOptions.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]]; - [self.uut overrideOptions:newOptions]; + [self.uut mergeOptions:newOptions]; XCTAssertEqual([UIColor redColor], self.uut.options.topBar.background.color.get); } #pragma mark BottomTabs - (RNNStackController *)createNavigationController { - RNNStackController *nav = [[RNNStackController alloc] - initWithLayoutInfo:nil - creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - presenter:[[RNNStackPresenter alloc] init] - eventEmitter:nil - childViewControllers:@[ self.uut ]]; + RNNStackController *nav = + [[RNNStackController alloc] initWithLayoutInfo:nil + creator:nil + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + presenter:[[RNNStackPresenter alloc] init] + eventEmitter:nil + childViewControllers:@[ self.uut ]]; return nav; } diff --git a/playground/ios/NavigationTests/RNNSideMenuControllerTest.m b/playground/ios/NavigationTests/RNNSideMenuControllerTest.m index c8f295c1743..51923665645 100644 --- a/playground/ios/NavigationTests/RNNSideMenuControllerTest.m +++ b/playground/ios/NavigationTests/RNNSideMenuControllerTest.m @@ -95,9 +95,9 @@ - (void)testGetCurrentChild { - (void)testResolveOptions { XCTestExpectation *expectation = [self expectationWithDescription:@"Testing Async Method"]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.sideMenu.left.visible = [[Bool alloc] initWithBOOL:YES]; - [_centerVC overrideOptions:options]; + [_centerVC mergeOptions:options]; XCTAssertTrue(_uut.resolveOptions.sideMenu.left.visible); diff --git a/playground/ios/NavigationTests/RNNSideMenuPresenterTest.m b/playground/ios/NavigationTests/RNNSideMenuPresenterTest.m index 979c1e9bb59..efa47948183 100644 --- a/playground/ios/NavigationTests/RNNSideMenuPresenterTest.m +++ b/playground/ios/NavigationTests/RNNSideMenuPresenterTest.m @@ -28,7 +28,7 @@ - (void)setUp { presenter:nil eventEmitter:nil]]; [self.uut bindViewController:self.boundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (RNNSideMenuChildVC *)createChildVC:(RNNSideMenuChildType)type { diff --git a/playground/ios/NavigationTests/RNNStackControllerTest.m b/playground/ios/NavigationTests/RNNStackControllerTest.m index 3b64ac2d50c..4d37961c1bb 100644 --- a/playground/ios/NavigationTests/RNNStackControllerTest.m +++ b/playground/ios/NavigationTests/RNNStackControllerTest.m @@ -32,18 +32,18 @@ - (void)setUp { rootViewCreator:nil eventEmitter:nil presenter:[OCMockObject partialMockForObject:[[RNNComponentPresenter alloc] init]] - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; - _vc2 = [[RNNComponentViewController alloc] - initWithLayoutInfo:[RNNLayoutInfo new] - rootViewCreator:nil - eventEmitter:nil - presenter:[[RNNComponentPresenter alloc] init] - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions]]; + options:[RNNNavigationOptions emptyOptions] + defaultOptions:[RNNNavigationOptions emptyOptions]]; + _vc2 = + [[RNNComponentViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] + rootViewCreator:nil + eventEmitter:nil + presenter:[[RNNComponentPresenter alloc] init] + options:[RNNNavigationOptions emptyOptions] + defaultOptions:[RNNNavigationOptions emptyOptions]]; _vc2Mock = [OCMockObject partialMockForObject:_vc2]; _vc3 = [UIViewController new]; - _options = [OCMockObject partialMockForObject:[[RNNNavigationOptions alloc] initEmptyOptions]]; + _options = [OCMockObject partialMockForObject:[RNNNavigationOptions emptyOptions]]; self.uut = [[RNNStackController alloc] initWithLayoutInfo:nil creator:_creator options:_options @@ -119,7 +119,7 @@ - (void)testPreferredStatusHidden_shouldShowStatusBar { - (void)testPopGestureEnabled_false { NSNumber *popGestureEnabled = @(0); - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled]; self.uut = [self createNavigationControllerWithOptions:options]; @@ -130,7 +130,7 @@ - (void)testPopGestureEnabled_false { - (void)testPopGestureEnabled_true { NSNumber *popGestureEnabled = @(1); - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.popGesture = [[Bool alloc] initWithValue:popGestureEnabled]; self.uut = [self createNavigationControllerWithOptions:options]; @@ -141,7 +141,7 @@ - (void)testPopGestureEnabled_true { - (void)testRootBackgroundImage { UIImage *rootBackgroundImage = [[UIImage alloc] init]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.rootBackgroundImage = [[Image alloc] initWithValue:rootBackgroundImage]; self.uut = [self createNavigationControllerWithOptions:options]; @@ -151,7 +151,7 @@ - (void)testRootBackgroundImage { } - (void)testTopBarBackgroundClipToBounds_true { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(1)]; self.uut = [self createNavigationControllerWithOptions:options]; @@ -161,7 +161,7 @@ - (void)testTopBarBackgroundClipToBounds_true { } - (void)testTopBarBackgroundClipToBounds_false { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.topBar.background.clipToBounds = [[Bool alloc] initWithValue:@(0)]; self.uut = [self createNavigationControllerWithOptions:options]; @@ -182,7 +182,7 @@ - (void)testPopViewControllerReturnLastChildViewController { - (void)testPopViewControllerSetTopBarBackgroundForPoppingViewController { _options.topBar.background.color = [[Color alloc] initWithValue:[UIColor redColor]]; - [_vc1 overrideOptions:_options]; + [_vc1 mergeOptions:_options]; [self.uut popViewControllerAnimated:NO]; [_vc1 viewWillAppear:YES]; @@ -218,15 +218,15 @@ - (void)testPopViewController_ShouldEmitScreenPoppedEvent { [(id)uut.eventEmitter verify]; } -- (void)testOverrideOptionsShouldOverrideOptionsState { - RNNNavigationOptions *overrideOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - [(RNNNavigationOptions *)[(id)self.uut.options expect] overrideOptions:overrideOptions]; - [self.uut overrideOptions:overrideOptions]; +- (void)testMergeOptionsShouldOverrideOptionsState { + RNNNavigationOptions *overrideOptions = [RNNNavigationOptions emptyOptions]; + [(RNNNavigationOptions *)[(id)self.uut.options expect] mergeOptions:overrideOptions]; + [self.uut mergeOptions:overrideOptions]; [(id)self.uut.options verify]; } - (void)testMergeChildOptionsShouldUpdatePresenterForVisibleChild { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; [[_presenter expect] mergeOptions:options resolvedOptions:[OCMArg any]]; [self.uut mergeChildOptions:options child:self.uut.childViewControllers.lastObject]; @@ -234,7 +234,7 @@ - (void)testMergeChildOptionsShouldUpdatePresenterForVisibleChild { } - (void)testMergeChildOptionsShouldNotUpdatePresenterForInvisibleChild { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; [[_presenter reject] mergeOptions:options resolvedOptions:self.uut.resolveOptions]; [self.uut mergeChildOptions:options child:self.uut.childViewControllers.firstObject]; @@ -242,7 +242,7 @@ - (void)testMergeChildOptionsShouldNotUpdatePresenterForInvisibleChild { } - (void)testOnChildWillAppear_shouldSetBackButtonTestID { - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; options.topBar.backButton.testID = [Text withValue:@"TestID"]; RNNComponentViewController *pushedController = [RNNComponentViewController createWithComponentId:@"pushedController"]; diff --git a/playground/ios/NavigationTests/RNNStackPresenterTest.m b/playground/ios/NavigationTests/RNNStackPresenterTest.m index c76f58405ab..dccc534dedf 100644 --- a/playground/ios/NavigationTests/RNNStackPresenterTest.m +++ b/playground/ios/NavigationTests/RNNStackPresenterTest.m @@ -22,7 +22,7 @@ - (void)setUp { RNNStackController *stackController = [[RNNStackController alloc] initWithLayoutInfo:nil creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] + options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:self.uut eventEmitter:nil @@ -32,7 +32,7 @@ - (void)setUp { ]]; self.boundViewController = [OCMockObject partialMockForObject:stackController]; [self.uut bindViewController:self.boundViewController]; - self.options = [[RNNNavigationOptions alloc] initEmptyOptions]; + self.options = [RNNNavigationOptions emptyOptions]; } - (void)testApplyOptionsBeforePoppingShouldSetTopBarBackgroundForPoppingViewController { diff --git a/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m b/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m index f8f2bcce0cf..e4688ecc751 100644 --- a/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m +++ b/playground/ios/NavigationTests/TopBarAppearancePresenterTest.m @@ -20,19 +20,18 @@ - (void)setUp { [super setUp]; _componentViewController = [RNNComponentViewController createWithComponentId:@"componentId"]; _uut = [[TopBarAppearancePresenter alloc] initWithNavigationController:_stack]; - _stack = [[RNNStackController alloc] - initWithLayoutInfo:nil - creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:[[RNNNavigationOptions alloc] initEmptyOptions] - presenter:_uut - eventEmitter:nil - childViewControllers:@[ _componentViewController ]]; + _stack = [[RNNStackController alloc] initWithLayoutInfo:nil + creator:nil + options:[RNNNavigationOptions emptyOptions] + defaultOptions:[RNNNavigationOptions emptyOptions] + presenter:_uut + eventEmitter:nil + childViewControllers:@[ _componentViewController ]]; } - (void)testMergeOptions_shouldMergeWithDefault { - RNNNavigationOptions *mergeOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *mergeOptions = [RNNNavigationOptions emptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; defaultOptions.topBar.title.color = [Color withColor:UIColor.redColor]; mergeOptions.topBar.title.fontSize = [Number withValue:@(21)]; diff --git a/playground/ios/NavigationTests/UIViewController+LayoutProtocolTest.m b/playground/ios/NavigationTests/UIViewController+LayoutProtocolTest.m index 4f6a8953393..5d8e58e3934 100644 --- a/playground/ios/NavigationTests/UIViewController+LayoutProtocolTest.m +++ b/playground/ios/NavigationTests/UIViewController+LayoutProtocolTest.m @@ -24,8 +24,8 @@ - (void)setUp { - (void)testInitWithLayoutApplyDefaultOptions { RNNComponentPresenter *presenter = [[RNNComponentPresenter alloc] init]; - RNNNavigationOptions *options = [[RNNNavigationOptions alloc] initEmptyOptions]; - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *options = [RNNNavigationOptions emptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; defaultOptions.modalPresentationStyle = [[Text alloc] initWithValue:@"default"]; RNNComponentViewController *uut = @@ -89,11 +89,11 @@ - (void)testLoadChildrenShouldSetChildViewControllers { } - (void)testResolveOptions { - RNNNavigationOptions *childOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; - RNNNavigationOptions *parentOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *childOptions = [RNNNavigationOptions emptyOptions]; + RNNNavigationOptions *parentOptions = [RNNNavigationOptions emptyOptions]; parentOptions.bottomTab.text = [[Text alloc] initWithValue:@"text"]; parentOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.redColor]; - RNNNavigationOptions *defaultOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *defaultOptions = [RNNNavigationOptions emptyOptions]; defaultOptions.bottomTab.text = [[Text alloc] initWithValue:@"default text"]; defaultOptions.bottomTab.selectedIconColor = [[Color alloc] initWithValue:UIColor.blueColor]; @@ -129,7 +129,7 @@ - (void)testMergeOptions_invokedOnParentViewController { eventEmitter:nil childViewControllers:nil]; - RNNNavigationOptions *toMerge = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *toMerge = [RNNNavigationOptions emptyOptions]; [(UIViewController *)[parent expect] mergeChildOptions:toMerge child:uut]; [parent addChildViewController:uut]; @@ -141,7 +141,7 @@ - (void)testMergeOptions_invokedOnParentViewController { - (void)testMergeOptions_presenterIsInvokedWithResolvedOptions { id parent = [OCMockObject partialMockForObject:[RNNStackController new]]; id presenter = [OCMockObject partialMockForObject:[RNNStackPresenter new]]; - RNNNavigationOptions *toMerge = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *toMerge = [RNNNavigationOptions emptyOptions]; toMerge.topBar.title.color = [[Color alloc] initWithValue:[UIColor redColor]]; [[presenter expect] mergeOptions:toMerge @@ -152,7 +152,7 @@ - (void)testMergeOptions_presenterIsInvokedWithResolvedOptions { return YES; }]]; - RNNNavigationOptions *childOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *childOptions = [RNNNavigationOptions emptyOptions]; childOptions.bottomTab.text = [[Text alloc] initWithValue:@"Child tab text"]; RNNComponentViewController *child = [[RNNComponentViewController alloc] initWithLayoutInfo:[RNNLayoutInfo new] @@ -162,7 +162,7 @@ - (void)testMergeOptions_presenterIsInvokedWithResolvedOptions { presenter:[RNNComponentPresenter new] eventEmitter:nil childViewControllers:nil]; - RNNNavigationOptions *initialOptions = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *initialOptions = [RNNNavigationOptions emptyOptions]; initialOptions.topBar.title.text = [[Text alloc] initWithValue:@"Initial title"]; RNNStackController *uut = [[RNNStackController alloc] initWithLayoutInfo:[RNNLayoutInfo new] creator:nil @@ -181,12 +181,12 @@ - (void)testMergeOptions_mergedIntoCurrentOptions { UIViewController *uut = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] + options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil]; - RNNNavigationOptions *toMerge = [[RNNNavigationOptions alloc] initEmptyOptions]; + RNNNavigationOptions *toMerge = [RNNNavigationOptions emptyOptions]; toMerge.topBar.title.text = [[Text alloc] initWithValue:@"merged"]; [uut mergeOptions:toMerge]; @@ -197,27 +197,27 @@ - (void)testLayout_shouldExtendedLayoutIncludesOpaqueBars { UIViewController *component = [[UIViewController alloc] initWithLayoutInfo:nil creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] + options:[RNNNavigationOptions emptyOptions] defaultOptions:nil presenter:nil eventEmitter:nil childViewControllers:nil]; - UINavigationController *stack = [[UINavigationController alloc] - initWithLayoutInfo:nil - creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - presenter:nil - eventEmitter:nil - childViewControllers:nil]; - UITabBarController *tabBar = [[UITabBarController alloc] - initWithLayoutInfo:nil - creator:nil - options:[[RNNNavigationOptions alloc] initEmptyOptions] - defaultOptions:nil - presenter:nil - eventEmitter:nil - childViewControllers:nil]; + UINavigationController *stack = + [[UINavigationController alloc] initWithLayoutInfo:nil + creator:nil + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + presenter:nil + eventEmitter:nil + childViewControllers:nil]; + UITabBarController *tabBar = + [[UITabBarController alloc] initWithLayoutInfo:nil + creator:nil + options:[RNNNavigationOptions emptyOptions] + defaultOptions:nil + presenter:nil + eventEmitter:nil + childViewControllers:nil]; XCTAssertTrue(component.extendedLayoutIncludesOpaqueBars); XCTAssertTrue(stack.extendedLayoutIncludesOpaqueBars); diff --git a/playground/ios/playground.xcodeproj/project.pbxproj b/playground/ios/playground.xcodeproj/project.pbxproj index 671841f55e4..6a96f95327c 100644 --- a/playground/ios/playground.xcodeproj/project.pbxproj +++ b/playground/ios/playground.xcodeproj/project.pbxproj @@ -43,7 +43,6 @@ 50C9A8D1240EB95F00BD699F /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; }; 50C9A8D4240FB9D000BD699F /* RNNComponentViewController+Utils.m in Sources */ = {isa = PBXBuildFile; fileRef = 50C9A8D3240FB9D000BD699F /* RNNComponentViewController+Utils.m */; }; 50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */; }; - 50EF5BAE24CDCF04009CBFD0 /* NSObjectUtilsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 50EF5BAD24CDCF04009CBFD0 /* NSObjectUtilsTests.m */; }; 6B102251DCC578519C2DC6A4 /* libPods-NavigationIOS12Tests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = C10F72071A488F801E1F1116 /* libPods-NavigationIOS12Tests.a */; }; 8EB60A6CB93C527CC6A870A2 /* libPods-SnapshotTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E8B4CFA18A5ACE953124E129 /* libPods-SnapshotTests.a */; }; 9F9A3A9625260DA900AAAF37 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 9F9A3A9525260DA900AAAF37 /* LaunchScreen.storyboard */; }; @@ -157,7 +156,6 @@ 50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "RNNBottomTabsController+Helpers.h"; sourceTree = ""; }; 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "RNNBottomTabsController+Helpers.m"; sourceTree = ""; }; 50E4888A2427DA4800B11A8E /* StackOptionsTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = StackOptionsTest.m; sourceTree = ""; }; - 50EF5BAD24CDCF04009CBFD0 /* NSObjectUtilsTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = NSObjectUtilsTests.m; sourceTree = ""; }; 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 = ""; }; 9F9A3A9525260DA900AAAF37 /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = LaunchScreen.storyboard; sourceTree = ""; }; 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 = ""; }; @@ -420,7 +418,6 @@ 50CF233B240695B10098042D /* RNNBottomTabsController+Helpers.h */, 50CF233C240695B10098042D /* RNNBottomTabsController+Helpers.m */, 50647FE223E3196800B92025 /* RNNExternalViewControllerTests.m */, - 50EF5BAD24CDCF04009CBFD0 /* NSObjectUtilsTests.m */, E58D261F238587F4003F36BA /* Info.plist */, ); path = NavigationTests; @@ -877,7 +874,6 @@ 50CF233D240695B10098042D /* RNNBottomTabsController+Helpers.m in Sources */, E58D265D2385888C003F36BA /* RNNControllerFactoryTest.m in Sources */, E58D265C2385888C003F36BA /* RNNStackControllerTest.m in Sources */, - 50EF5BAE24CDCF04009CBFD0 /* NSObjectUtilsTests.m in Sources */, E58D26482385888C003F36BA /* RNNDotIndicatorPresenterTest.m in Sources */, E58D26522385888C003F36BA /* RNNComponentPresenterTest.m in Sources */, E58D264C2385888C003F36BA /* RNNSideMenuParserTest.m in Sources */, diff --git a/playground/ios/playground.xcodeproj/xcshareddata/xcbaselines/E58D261A238587F4003F36BA.xcbaseline/FA2AD6A4-AA07-489D-A6D5-A294DD8C07A9.plist b/playground/ios/playground.xcodeproj/xcshareddata/xcbaselines/E58D261A238587F4003F36BA.xcbaseline/FA2AD6A4-AA07-489D-A6D5-A294DD8C07A9.plist new file mode 100644 index 00000000000..ebacb09d6b0 --- /dev/null +++ b/playground/ios/playground.xcodeproj/xcshareddata/xcbaselines/E58D261A238587F4003F36BA.xcbaseline/FA2AD6A4-AA07-489D-A6D5-A294DD8C07A9.plist @@ -0,0 +1,32 @@ + + + + + classNames + + RNNNavigationOptionsTest + + testCopy + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.000527 + baselineIntegrationDisplayName + Local Baseline + + + testMergeOptions_shouldOverridePreviousOptions + + com.apple.XCTPerformanceMetric_WallClockTime + + baselineAverage + 0.000146 + baselineIntegrationDisplayName + Local Baseline + + + + + +