From 55e33712ba626cfa818a2188d26ddd66e45c045a Mon Sep 17 00:00:00 2001 From: wilson Date: Tue, 18 Dec 2018 14:55:00 +0800 Subject: [PATCH 1/5] =?UTF-8?q?[V2][iOS]=20Fix=20bottomTabs=E2=80=99s=20an?= =?UTF-8?q?imate=20option?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wilson --- lib/ios/RNNBottomTabsOptions.h | 1 + lib/ios/RNNBottomTabsOptions.m | 1 + lib/ios/RNNTabBarPresenter.m | 4 ++-- lib/ios/UITabBarController+RNNOptions.h | 2 +- lib/ios/UITabBarController+RNNOptions.m | 15 +++++++++++++-- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/lib/ios/RNNBottomTabsOptions.h b/lib/ios/RNNBottomTabsOptions.h index 6d2e43ba5ef..a6b1027c43f 100644 --- a/lib/ios/RNNBottomTabsOptions.h +++ b/lib/ios/RNNBottomTabsOptions.h @@ -5,6 +5,7 @@ @property (nonatomic, strong) Bool* visible; @property (nonatomic, strong) IntNumber* currentTabIndex; @property (nonatomic, strong) Bool* drawBehind; +@property (nonatomic, strong) Bool* animate; @property (nonatomic, strong) Color* tabColor; @property (nonatomic, strong) Color* selectedTabColor; @property (nonatomic, strong) Bool* translucent; diff --git a/lib/ios/RNNBottomTabsOptions.m b/lib/ios/RNNBottomTabsOptions.m index d5d5ed35871..cb040159c27 100644 --- a/lib/ios/RNNBottomTabsOptions.m +++ b/lib/ios/RNNBottomTabsOptions.m @@ -8,6 +8,7 @@ - (instancetype)initWithDict:(NSDictionary *)dict { self.visible = [BoolParser parse:dict key:@"visible"]; self.currentTabIndex = [IntNumberParser parse:dict key:@"currentTabIndex"]; self.drawBehind = [BoolParser parse:dict key:@"drawBehind"]; + self.animate = [BoolParser parse:dict key:@"animate"]; self.tabColor = [ColorParser parse:dict key:@"tabColor"]; self.selectedTabColor = [ColorParser parse:dict key:@"selectedTabColor"]; self.translucent = [BoolParser parse:dict key:@"translucent"]; diff --git a/lib/ios/RNNTabBarPresenter.m b/lib/ios/RNNTabBarPresenter.m index 62884292329..adfaee5e13c 100644 --- a/lib/ios/RNNTabBarPresenter.m +++ b/lib/ios/RNNTabBarPresenter.m @@ -16,7 +16,7 @@ - (void)applyOptions:(RNNNavigationOptions *)options { [tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]]; [tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]]; [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]]; - [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES]]; + [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:YES]]; } - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions { @@ -55,7 +55,7 @@ - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavig } if (newOptions.bottomTabs.visible.hasValue) { - [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get]; + [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:YES]]; } } diff --git a/lib/ios/UITabBarController+RNNOptions.h b/lib/ios/UITabBarController+RNNOptions.h index 751d07dac65..2d292b5bdd6 100644 --- a/lib/ios/UITabBarController+RNNOptions.h +++ b/lib/ios/UITabBarController+RNNOptions.h @@ -16,6 +16,6 @@ - (void)rnn_setTabBarHideShadow:(BOOL)hideShadow; -- (void)rnn_setTabBarVisible:(BOOL)visible; +- (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated; @end diff --git a/lib/ios/UITabBarController+RNNOptions.m b/lib/ios/UITabBarController+RNNOptions.m index fd423fae1fd..b47a16bddec 100644 --- a/lib/ios/UITabBarController+RNNOptions.m +++ b/lib/ios/UITabBarController+RNNOptions.m @@ -31,8 +31,19 @@ - (void)rnn_setTabBarHideShadow:(BOOL)hideShadow { self.tabBar.clipsToBounds = hideShadow; } -- (void)rnn_setTabBarVisible:(BOOL)visible { - self.tabBar.hidden = !visible; +- (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated { + CGRect nextFrame = self.tabBar.frame; + nextFrame.origin.y = UIScreen.mainScreen.bounds.size.height - (visible ? self.tabBar.frame.size.height : 0); + + [UIView animateWithDuration: (animated ? 0.15 : 0) + delay: 0 + options: (visible ? UIViewAnimationOptionCurveEaseOut : UIViewAnimationOptionCurveEaseIn) + animations:^() + { + [self.tabBar setFrame:nextFrame]; + } + completion:^(BOOL finished) + {}]; } @end From 1bee6fa9611a7a79cd15355dab011ed986f1e35c Mon Sep 17 00:00:00 2001 From: wilson Date: Tue, 8 Jan 2019 18:33:30 +0800 Subject: [PATCH 2/5] change animated default value to false Signed-off-by: wilson --- lib/ios/RNNTabBarPresenter.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ios/RNNTabBarPresenter.m b/lib/ios/RNNTabBarPresenter.m index adfaee5e13c..0b054692f00 100644 --- a/lib/ios/RNNTabBarPresenter.m +++ b/lib/ios/RNNTabBarPresenter.m @@ -16,7 +16,7 @@ - (void)applyOptions:(RNNNavigationOptions *)options { [tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]]; [tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]]; [tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]]; - [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:YES]]; + [tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:NO]]; } - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions { @@ -54,8 +54,8 @@ - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavig [tabBarController rnn_setTabBarHideShadow:newOptions.bottomTabs.hideShadow.get]; } - if (newOptions.bottomTabs.visible.hasValue) { - [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:YES]]; + if (newOptions.bottomTabs.visible.hasValue && newOptions.bottomTabs.animate.hasValue) { + [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:NO]]; } } From 3f7e1fe38af561242bf3f9057612e0da45787fad Mon Sep 17 00:00:00 2001 From: wilson Date: Tue, 8 Jan 2019 18:35:09 +0800 Subject: [PATCH 3/5] fix self.tabBar.hidden value Signed-off-by: wilson --- lib/ios/UITabBarController+RNNOptions.m | 52 +++++++++++++++++++------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/ios/UITabBarController+RNNOptions.m b/lib/ios/UITabBarController+RNNOptions.m index b47a16bddec..9f28ee83307 100644 --- a/lib/ios/UITabBarController+RNNOptions.m +++ b/lib/ios/UITabBarController+RNNOptions.m @@ -32,18 +32,46 @@ - (void)rnn_setTabBarHideShadow:(BOOL)hideShadow { } - (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated { - CGRect nextFrame = self.tabBar.frame; - nextFrame.origin.y = UIScreen.mainScreen.bounds.size.height - (visible ? self.tabBar.frame.size.height : 0); - - [UIView animateWithDuration: (animated ? 0.15 : 0) - delay: 0 - options: (visible ? UIViewAnimationOptionCurveEaseOut : UIViewAnimationOptionCurveEaseIn) - animations:^() - { - [self.tabBar setFrame:nextFrame]; - } - completion:^(BOOL finished) - {}]; + const CGRect tabBarFrame = self.tabBar.frame; + const CGRect tabBarVisibleFrame = CGRectMake(tabBarFrame.origin.x, + self.view.frame.size.height - tabBarFrame.size.height, + tabBarFrame.size.width, + tabBarFrame.size.height); + const CGRect tabBarHiddenFrame = CGRectMake(tabBarFrame.origin.x, + self.view.frame.size.height, + tabBarFrame.size.width, + tabBarFrame.size.height); + if (!animated) { + self.tabBar.hidden = !visible; + self.tabBar.frame = visible ? tabBarVisibleFrame : tabBarHiddenFrame; + return; + } + static const CGFloat animationDuration = 0.15; + + if (visible) { + self.tabBar.hidden = NO; + [UIView animateWithDuration: animationDuration + delay: 0 + options: UIViewAnimationOptionCurveEaseOut + animations:^() + { + self.tabBar.frame = tabBarVisibleFrame; + } + completion:^(BOOL finished) + {}]; + } else { + [UIView animateWithDuration: animationDuration + delay: 0 + options: UIViewAnimationOptionCurveEaseIn + animations:^() + { + self.tabBar.frame = tabBarHiddenFrame; + } + completion:^(BOOL finished) + { + self.tabBar.hidden = YES; + }]; + } } @end From 1e0975eced2de811349bf2987f753e87e0e5ff41 Mon Sep 17 00:00:00 2001 From: wilson Date: Tue, 8 Jan 2019 18:46:59 +0800 Subject: [PATCH 4/5] Fix tests Signed-off-by: wilson --- lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m b/lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m index b6c269c324d..ed9bd4afe05 100644 --- a/lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m +++ b/lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m @@ -28,7 +28,7 @@ - (void)testApplyOptions_shouldSetDefaultEmptyOptions { [[self.bindedViewController expect] rnn_setTabBarTranslucent:NO]; [[self.bindedViewController expect] rnn_setTabBarHideShadow:NO]; [[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleDefault]; - [[self.bindedViewController expect] rnn_setTabBarVisible:YES]; + [[self.bindedViewController expect] rnn_setTabBarVisible:YES animated:NO]; [self.uut applyOptions:emptyOptions]; [self.bindedViewController verify]; } @@ -47,7 +47,7 @@ - (void)testApplyOptions_shouldApplyOptions { [[self.bindedViewController expect] rnn_setTabBarTranslucent:NO]; [[self.bindedViewController expect] rnn_setTabBarHideShadow:YES]; [[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleBlack]; - [[self.bindedViewController expect] rnn_setTabBarVisible:NO]; + [[self.bindedViewController expect] rnn_setTabBarVisible:NO animated:NO]; [self.uut applyOptions:initialOptions]; [self.bindedViewController verify]; From 7466a70610653b677be56142b5b77d251615b7c7 Mon Sep 17 00:00:00 2001 From: wilson Date: Thu, 31 Jan 2019 18:51:40 +0800 Subject: [PATCH 5/5] fix value check Signed-off-by: wilson --- lib/ios/RNNTabBarPresenter.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/ios/RNNTabBarPresenter.m b/lib/ios/RNNTabBarPresenter.m index 0b054692f00..083f35946de 100644 --- a/lib/ios/RNNTabBarPresenter.m +++ b/lib/ios/RNNTabBarPresenter.m @@ -54,8 +54,12 @@ - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavig [tabBarController rnn_setTabBarHideShadow:newOptions.bottomTabs.hideShadow.get]; } - if (newOptions.bottomTabs.visible.hasValue && newOptions.bottomTabs.animate.hasValue) { - [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:NO]]; + if (newOptions.bottomTabs.visible.hasValue) { + if (newOptions.bottomTabs.animate.hasValue) { + [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:NO]]; + } else { + [tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:NO]; + } } }