Browse Source

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

* [V2][iOS] Fix bottomTabs’s animate option

Signed-off-by: wilson <wilson@waveo.com>

* change animated default value to false

Signed-off-by: wilson <wilson@waveo.com>

* fix self.tabBar.hidden value

Signed-off-by: wilson <wilson@waveo.com>

* Fix tests

Signed-off-by: wilson <wilson@waveo.com>

* fix value check

Signed-off-by: wilson <wilson@waveo.com>
Wilson 5 years ago
parent
commit
9836730570

+ 1
- 0
lib/ios/RNNBottomTabsOptions.h View File

5
 @property (nonatomic, strong) Bool* visible;
5
 @property (nonatomic, strong) Bool* visible;
6
 @property (nonatomic, strong) IntNumber* currentTabIndex;
6
 @property (nonatomic, strong) IntNumber* currentTabIndex;
7
 @property (nonatomic, strong) Bool* drawBehind;
7
 @property (nonatomic, strong) Bool* drawBehind;
8
+@property (nonatomic, strong) Bool* animate;
8
 @property (nonatomic, strong) Color* tabColor;
9
 @property (nonatomic, strong) Color* tabColor;
9
 @property (nonatomic, strong) Color* selectedTabColor;
10
 @property (nonatomic, strong) Color* selectedTabColor;
10
 @property (nonatomic, strong) Bool* translucent;
11
 @property (nonatomic, strong) Bool* translucent;

+ 1
- 0
lib/ios/RNNBottomTabsOptions.m View File

8
 	self.visible = [BoolParser parse:dict key:@"visible"];
8
 	self.visible = [BoolParser parse:dict key:@"visible"];
9
 	self.currentTabIndex = [IntNumberParser parse:dict key:@"currentTabIndex"];
9
 	self.currentTabIndex = [IntNumberParser parse:dict key:@"currentTabIndex"];
10
 	self.drawBehind = [BoolParser parse:dict key:@"drawBehind"];
10
 	self.drawBehind = [BoolParser parse:dict key:@"drawBehind"];
11
+	self.animate = [BoolParser parse:dict key:@"animate"];
11
 	self.tabColor = [ColorParser parse:dict key:@"tabColor"];
12
 	self.tabColor = [ColorParser parse:dict key:@"tabColor"];
12
 	self.selectedTabColor = [ColorParser parse:dict key:@"selectedTabColor"];
13
 	self.selectedTabColor = [ColorParser parse:dict key:@"selectedTabColor"];
13
 	self.translucent = [BoolParser parse:dict key:@"translucent"];
14
 	self.translucent = [BoolParser parse:dict key:@"translucent"];

+ 6
- 2
lib/ios/RNNTabBarPresenter.m View File

16
 	[tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]];
16
 	[tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]];
17
 	[tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]];
17
 	[tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]];
18
 	[tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
18
 	[tabBarController rnn_setTabBarStyle:[RCTConvert UIBarStyle:[options.bottomTabs.barStyle getWithDefaultValue:@"default"]]];
19
-	[tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES]];
19
+	[tabBarController rnn_setTabBarVisible:[options.bottomTabs.visible getWithDefaultValue:YES] animated:[options.bottomTabs.animate getWithDefaultValue:NO]];
20
 }
20
 }
21
 
21
 
22
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
22
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
55
 	}
55
 	}
56
 	
56
 	
57
 	if (newOptions.bottomTabs.visible.hasValue) {
57
 	if (newOptions.bottomTabs.visible.hasValue) {
58
-		[tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get];
58
+		if (newOptions.bottomTabs.animate.hasValue) {
59
+			[tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:[newOptions.bottomTabs.animate getWithDefaultValue:NO]];
60
+		} else {
61
+			[tabBarController rnn_setTabBarVisible:newOptions.bottomTabs.visible.get animated:NO];
62
+		}
59
 	}
63
 	}
60
 }
64
 }
61
 
65
 

+ 2
- 2
lib/ios/ReactNativeNavigationTests/RNNTabBarPresenterTest.m View File

29
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
29
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
30
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:NO];
30
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:NO];
31
     [[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleDefault];
31
     [[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleDefault];
32
-	[[self.bindedViewController expect] rnn_setTabBarVisible:YES];
32
+	[[self.bindedViewController expect] rnn_setTabBarVisible:YES animated:NO];
33
 	[self.uut applyOptions:emptyOptions];
33
 	[self.uut applyOptions:emptyOptions];
34
 	[self.bindedViewController verify];
34
 	[self.bindedViewController verify];
35
 }
35
 }
48
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
48
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
49
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:YES];
49
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:YES];
50
 	[[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleBlack];
50
 	[[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleBlack];
51
-	[[self.bindedViewController expect] rnn_setTabBarVisible:NO];
51
+	[[self.bindedViewController expect] rnn_setTabBarVisible:NO animated:NO];
52
 	
52
 	
53
 	[self.uut applyOptions:initialOptions];
53
 	[self.uut applyOptions:initialOptions];
54
 	[self.bindedViewController verify];
54
 	[self.bindedViewController verify];

+ 1
- 1
lib/ios/UITabBarController+RNNOptions.h View File

16
 
16
 
17
 - (void)rnn_setTabBarHideShadow:(BOOL)hideShadow;
17
 - (void)rnn_setTabBarHideShadow:(BOOL)hideShadow;
18
 
18
 
19
-- (void)rnn_setTabBarVisible:(BOOL)visible;
19
+- (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated;
20
 
20
 
21
 @end
21
 @end

+ 41
- 2
lib/ios/UITabBarController+RNNOptions.m View File

31
 	self.tabBar.clipsToBounds = hideShadow;
31
 	self.tabBar.clipsToBounds = hideShadow;
32
 }
32
 }
33
 
33
 
34
-- (void)rnn_setTabBarVisible:(BOOL)visible {
35
-	self.tabBar.hidden = !visible;
34
+- (void)rnn_setTabBarVisible:(BOOL)visible animated:(BOOL)animated {
35
+    const CGRect tabBarFrame = self.tabBar.frame;
36
+	const CGRect tabBarVisibleFrame = CGRectMake(tabBarFrame.origin.x,
37
+												 self.view.frame.size.height - tabBarFrame.size.height,
38
+												 tabBarFrame.size.width,
39
+												 tabBarFrame.size.height);
40
+	const CGRect tabBarHiddenFrame = CGRectMake(tabBarFrame.origin.x,
41
+												self.view.frame.size.height,
42
+												tabBarFrame.size.width,
43
+												tabBarFrame.size.height);
44
+	if (!animated) {
45
+		self.tabBar.hidden = !visible;
46
+		self.tabBar.frame = visible ? tabBarVisibleFrame : tabBarHiddenFrame;
47
+		return;
48
+	}
49
+	static const CGFloat animationDuration = 0.15;
50
+
51
+	if (visible) {
52
+		self.tabBar.hidden = NO;
53
+		[UIView animateWithDuration: animationDuration
54
+							  delay: 0
55
+							options: UIViewAnimationOptionCurveEaseOut
56
+						 animations:^()
57
+		 {
58
+			 self.tabBar.frame = tabBarVisibleFrame;
59
+		 }
60
+						 completion:^(BOOL finished)
61
+		 {}];
62
+	} else {
63
+		[UIView animateWithDuration: animationDuration
64
+							  delay: 0
65
+							options: UIViewAnimationOptionCurveEaseIn
66
+						 animations:^()
67
+		 {
68
+			 self.tabBar.frame = tabBarHiddenFrame;
69
+		 }
70
+						 completion:^(BOOL finished)
71
+		 {
72
+			 self.tabBar.hidden = YES;
73
+		 }];
74
+	}
36
 }
75
 }
37
 
76
 
38
 @end
77
 @end