|
@@ -2,33 +2,45 @@ import * as React from 'react';
|
2
|
2
|
import {withTheme} from 'react-native-paper';
|
3
|
3
|
import TabIcon from "./TabIcon";
|
4
|
4
|
import TabHomeIcon from "./TabHomeIcon";
|
5
|
|
-import * as Animatable from 'react-native-animatable';
|
|
5
|
+import {AnimatedValue} from "react-native-reanimated";
|
|
6
|
+import {Animated} from 'react-native';
|
6
|
7
|
|
7
|
8
|
type Props = {
|
8
|
9
|
state: Object,
|
9
|
10
|
descriptors: Object,
|
10
|
11
|
navigation: Object,
|
11
|
12
|
theme: Object,
|
|
13
|
+ collapsibleStack: Object,
|
|
14
|
+}
|
|
15
|
+
|
|
16
|
+type State = {
|
|
17
|
+ translateY: AnimatedValue,
|
12
|
18
|
}
|
13
|
19
|
|
14
|
20
|
/**
|
15
|
21
|
* Abstraction layer for Agenda component, using custom configuration
|
16
|
22
|
*/
|
17
|
|
-class CustomTabBar extends React.Component<Props> {
|
|
23
|
+class CustomTabBar extends React.Component<Props, State> {
|
18
|
24
|
|
19
|
25
|
static TAB_BAR_HEIGHT = 48;
|
20
|
26
|
|
|
27
|
+ barSynced: boolean; // Is the bar synced with the header for animations?
|
|
28
|
+
|
|
29
|
+ state = {
|
|
30
|
+ translateY: new Animated.Value(0),
|
|
31
|
+ }
|
|
32
|
+
|
21
|
33
|
// shouldComponentUpdate(nextProps: Props): boolean {
|
22
|
34
|
// return (nextProps.theme.dark !== this.props.theme.dark)
|
23
|
35
|
// || (nextProps.state.index !== this.props.state.index);
|
24
|
36
|
// }
|
25
|
37
|
|
26
|
|
- isHidden: boolean;
|
27
|
38
|
tabRef: Object;
|
28
|
39
|
|
29
|
40
|
constructor() {
|
30
|
41
|
super();
|
31
|
42
|
this.tabRef = React.createRef();
|
|
43
|
+ this.barSynced = false;
|
32
|
44
|
}
|
33
|
45
|
|
34
|
46
|
onItemPress(route: Object, currentIndex: number, destIndex: number) {
|
|
@@ -38,6 +50,7 @@ class CustomTabBar extends React.Component<Props> {
|
38
|
50
|
canPreventDefault: true,
|
39
|
51
|
});
|
40
|
52
|
if (currentIndex !== destIndex && !event.defaultPrevented) {
|
|
53
|
+ this.state.translateY = new Animated.Value(0);
|
41
|
54
|
this.props.navigation.navigate(route.name, {
|
42
|
55
|
screen: 'index',
|
43
|
56
|
params: {animationDir: currentIndex < destIndex ? "right" : "left"}
|
|
@@ -45,16 +58,21 @@ class CustomTabBar extends React.Component<Props> {
|
45
|
58
|
}
|
46
|
59
|
}
|
47
|
60
|
|
|
61
|
+ onRouteChange = () => {
|
|
62
|
+ this.barSynced = false;
|
|
63
|
+ }
|
|
64
|
+
|
48
|
65
|
render() {
|
49
|
66
|
const state = this.props.state;
|
50
|
67
|
const descriptors = this.props.descriptors;
|
51
|
68
|
const navigation = this.props.navigation;
|
|
69
|
+ this.props.navigation.addListener('state', this.onRouteChange);
|
52
|
70
|
return (
|
53
|
|
- <Animatable.View
|
|
71
|
+ <Animated.View
|
54
|
72
|
ref={this.tabRef}
|
55
|
|
- animation={"fadeInUp"}
|
56
|
|
- duration={500}
|
57
|
|
- useNativeDriver
|
|
73
|
+ // animation={"fadeInUp"}
|
|
74
|
+ // duration={500}
|
|
75
|
+ // useNativeDriver
|
58
|
76
|
style={{
|
59
|
77
|
flexDirection: 'row',
|
60
|
78
|
height: CustomTabBar.TAB_BAR_HEIGHT,
|
|
@@ -63,6 +81,7 @@ class CustomTabBar extends React.Component<Props> {
|
63
|
81
|
bottom: 0,
|
64
|
82
|
left: 0,
|
65
|
83
|
backgroundColor: this.props.theme.colors.surface,
|
|
84
|
+ transform: [{translateY: this.state.translateY}]
|
66
|
85
|
}}
|
67
|
86
|
>
|
68
|
87
|
{state.routes.map((route, index) => {
|
|
@@ -85,18 +104,14 @@ class CustomTabBar extends React.Component<Props> {
|
85
|
104
|
});
|
86
|
105
|
};
|
87
|
106
|
if (isFocused) {
|
88
|
|
- const tabVisible = options.tabBarVisible();
|
89
|
|
- console.log(tabVisible);
|
90
|
|
- if (this.tabRef.current) {
|
91
|
|
- if (this.isHidden && tabVisible) {
|
92
|
|
- this.isHidden = false;
|
93
|
|
- this.tabRef.current.slideInUp(300);
|
94
|
|
- } else if (!this.isHidden && !tabVisible){
|
95
|
|
- this.isHidden = true;
|
96
|
|
- this.tabRef.current.slideOutDown(300);
|
97
|
|
- }
|
|
107
|
+ const stackState = route.state;
|
|
108
|
+ const stackRoute = route.state ? stackState.routes[stackState.index] : undefined;
|
|
109
|
+ const params = stackRoute ? stackRoute.params : undefined;
|
|
110
|
+ const collapsible = params ? params.collapsible : undefined;
|
|
111
|
+ if (collapsible && !this.barSynced) {
|
|
112
|
+ this.barSynced = true;
|
|
113
|
+ this.setState({translateY: Animated.multiply(-1.5, collapsible.translateY)});
|
98
|
114
|
}
|
99
|
|
-
|
100
|
115
|
}
|
101
|
116
|
|
102
|
117
|
const color = isFocused ? options.activeColor : options.inactiveColor;
|
|
@@ -120,7 +135,7 @@ class CustomTabBar extends React.Component<Props> {
|
120
|
135
|
key={route.key}
|
121
|
136
|
/>
|
122
|
137
|
})}
|
123
|
|
- </Animatable.View>
|
|
138
|
+ </Animated.View>
|
124
|
139
|
);
|
125
|
140
|
}
|
126
|
141
|
}
|