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
4 changes: 2 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:YES]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a breaking change because it does not animate in existing implementations.
I think that it is better to default to NO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

}

- (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
Expand Down Expand Up @@ -55,7 +55,7 @@ - (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];
[tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:YES]];
}
}

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