Bläddra i källkod

[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 år sedan
förälder
incheckning
9836730570

+ 1
- 0
lib/ios/RNNBottomTabsOptions.h Visa fil

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

+ 1
- 0
lib/ios/RNNBottomTabsOptions.m Visa fil

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

+ 6
- 2
lib/ios/RNNTabBarPresenter.m Visa fil

@@ -16,7 +16,7 @@
16 16
 	[tabBarController rnn_setTabBarTranslucent:[options.bottomTabs.translucent getWithDefaultValue:NO]];
17 17
 	[tabBarController rnn_setTabBarHideShadow:[options.bottomTabs.hideShadow getWithDefaultValue:NO]];
18 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 22
 - (void)mergeOptions:(RNNNavigationOptions *)newOptions currentOptions:(RNNNavigationOptions *)currentOptions defaultOptions:(RNNNavigationOptions *)defaultOptions {
@@ -55,7 +55,11 @@
55 55
 	}
56 56
 	
57 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 Visa fil

@@ -29,7 +29,7 @@
29 29
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
30 30
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:NO];
31 31
     [[self.bindedViewController expect] rnn_setTabBarStyle:UIBarStyleDefault];
32
-	[[self.bindedViewController expect] rnn_setTabBarVisible:YES];
32
+	[[self.bindedViewController expect] rnn_setTabBarVisible:YES animated:NO];
33 33
 	[self.uut applyOptions:emptyOptions];
34 34
 	[self.bindedViewController verify];
35 35
 }
@@ -48,7 +48,7 @@
48 48
 	[[self.bindedViewController expect] rnn_setTabBarTranslucent:NO];
49 49
 	[[self.bindedViewController expect] rnn_setTabBarHideShadow:YES];
50 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 53
 	[self.uut applyOptions:initialOptions];
54 54
 	[self.bindedViewController verify];

+ 1
- 1
lib/ios/UITabBarController+RNNOptions.h Visa fil

@@ -16,6 +16,6 @@
16 16
 
17 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 21
 @end

+ 41
- 2
lib/ios/UITabBarController+RNNOptions.m Visa fil

@@ -31,8 +31,47 @@
31 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 77
 @end