Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[V2][iOS] Fix bottomTabs’s animate option #4465

Merged
merged 11 commits into from
Apr 21, 2019
1 change: 1 addition & 0 deletions lib/ios/RNNBottomTabsOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions lib/ios/RNNBottomTabsOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
8 changes: 6 additions & 2 deletions lib/ios/RNNTabBarPresenter.m
Original file line number Diff line number Diff line change
Expand Up @@ -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:NO]];
}

- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
Expand Down Expand Up @@ -55,7 +55,11 @@ - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavig
}

if (newOptions.bottomTabs.visible.hasValue) {
guyca marked this conversation as resolved.
Show resolved Hide resolved
[tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get];
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];
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,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];
}
Expand All @@ -48,7 +48,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];
Expand Down
2 changes: 1 addition & 1 deletion lib/ios/UITabBarController+RNNOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@

- (void)rnn_setTabBarHideShadow:(BOOL)hideShadow;

- (void)rnn_setTabBarVisible:(BOOL)visible;
- (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated;

@end
43 changes: 41 additions & 2 deletions lib/ios/UITabBarController+RNNOptions.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,47 @@ - (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 {
yogevbd marked this conversation as resolved.
Show resolved Hide resolved
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