|
@@ -1,170 +1,178 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {StyleSheet, View} from "react-native";
|
5
|
|
-import {FAB, IconButton, Surface, withTheme} from "react-native-paper";
|
6
|
|
-import AutoHideHandler from "../../utils/AutoHideHandler";
|
|
4
|
+import {StyleSheet, View} from 'react-native';
|
|
5
|
+import {FAB, IconButton, Surface, withTheme} from 'react-native-paper';
|
7
|
6
|
import * as Animatable from 'react-native-animatable';
|
8
|
|
-import CustomTabBar from "../Tabbar/CustomTabBar";
|
9
|
|
-import {StackNavigationProp} from "@react-navigation/stack";
|
10
|
|
-import type {CustomTheme} from "../../managers/ThemeManager";
|
|
7
|
+import {StackNavigationProp} from '@react-navigation/stack';
|
|
8
|
+import AutoHideHandler from '../../utils/AutoHideHandler';
|
|
9
|
+import CustomTabBar from '../Tabbar/CustomTabBar';
|
|
10
|
+import type {CustomTheme} from '../../managers/ThemeManager';
|
11
|
11
|
|
12
|
12
|
const AnimatedFAB = Animatable.createAnimatableComponent(FAB);
|
13
|
13
|
|
14
|
|
-type Props = {
|
15
|
|
- navigation: StackNavigationProp,
|
16
|
|
- theme: CustomTheme,
|
17
|
|
- onPress: (action: string, data: any) => void,
|
18
|
|
- seekAttention: boolean,
|
19
|
|
-}
|
|
14
|
+type PropsType = {
|
|
15
|
+ navigation: StackNavigationProp,
|
|
16
|
+ theme: CustomTheme,
|
|
17
|
+ onPress: (action: string, data?: string) => void,
|
|
18
|
+ seekAttention: boolean,
|
|
19
|
+};
|
20
|
20
|
|
21
|
|
-type State = {
|
22
|
|
- currentMode: string,
|
23
|
|
-}
|
|
21
|
+type StateType = {
|
|
22
|
+ currentMode: string,
|
|
23
|
+};
|
24
|
24
|
|
25
|
25
|
const DISPLAY_MODES = {
|
26
|
|
- DAY: "agendaDay",
|
27
|
|
- WEEK: "agendaWeek",
|
28
|
|
- MONTH: "month",
|
29
|
|
-}
|
30
|
|
-
|
31
|
|
-class AnimatedBottomBar extends React.Component<Props, State> {
|
32
|
|
-
|
33
|
|
- ref: { current: null | Animatable.View };
|
34
|
|
- hideHandler: AutoHideHandler;
|
35
|
|
-
|
36
|
|
- displayModeIcons: { [key: string]: string };
|
|
26
|
+ DAY: 'agendaDay',
|
|
27
|
+ WEEK: 'agendaWeek',
|
|
28
|
+ MONTH: 'month',
|
|
29
|
+};
|
37
|
30
|
|
38
|
|
- state = {
|
39
|
|
- currentMode: DISPLAY_MODES.WEEK,
|
40
|
|
- }
|
41
|
|
-
|
42
|
|
- constructor() {
|
43
|
|
- super();
|
44
|
|
- this.ref = React.createRef();
|
45
|
|
- this.hideHandler = new AutoHideHandler(false);
|
46
|
|
- this.hideHandler.addListener(this.onHideChange);
|
47
|
|
-
|
48
|
|
- this.displayModeIcons = {};
|
49
|
|
- this.displayModeIcons[DISPLAY_MODES.DAY] = "calendar-text";
|
50
|
|
- this.displayModeIcons[DISPLAY_MODES.WEEK] = "calendar-week";
|
51
|
|
- this.displayModeIcons[DISPLAY_MODES.MONTH] = "calendar-range";
|
52
|
|
- }
|
|
31
|
+const styles = StyleSheet.create({
|
|
32
|
+ container: {
|
|
33
|
+ position: 'absolute',
|
|
34
|
+ left: '5%',
|
|
35
|
+ width: '90%',
|
|
36
|
+ },
|
|
37
|
+ surface: {
|
|
38
|
+ position: 'relative',
|
|
39
|
+ flexDirection: 'row',
|
|
40
|
+ justifyContent: 'space-between',
|
|
41
|
+ alignItems: 'center',
|
|
42
|
+ borderRadius: 50,
|
|
43
|
+ elevation: 2,
|
|
44
|
+ },
|
|
45
|
+ fabContainer: {
|
|
46
|
+ position: 'absolute',
|
|
47
|
+ left: 0,
|
|
48
|
+ right: 0,
|
|
49
|
+ alignItems: 'center',
|
|
50
|
+ width: '100%',
|
|
51
|
+ height: '100%',
|
|
52
|
+ },
|
|
53
|
+ fab: {
|
|
54
|
+ position: 'absolute',
|
|
55
|
+ alignSelf: 'center',
|
|
56
|
+ top: '-25%',
|
|
57
|
+ },
|
|
58
|
+});
|
53
|
59
|
|
54
|
|
- shouldComponentUpdate(nextProps: Props, nextState: State) {
|
55
|
|
- return (nextProps.seekAttention !== this.props.seekAttention)
|
56
|
|
- || (nextState.currentMode !== this.state.currentMode);
|
57
|
|
- }
|
|
60
|
+class AnimatedBottomBar extends React.Component<PropsType, StateType> {
|
|
61
|
+ ref: {current: null | Animatable.View};
|
58
|
62
|
|
59
|
|
- onHideChange = (shouldHide: boolean) => {
|
60
|
|
- if (this.ref.current != null) {
|
61
|
|
- if (shouldHide)
|
62
|
|
- this.ref.current.fadeOutDown(500);
|
63
|
|
- else
|
64
|
|
- this.ref.current.fadeInUp(500);
|
65
|
|
- }
|
66
|
|
- }
|
|
63
|
+ hideHandler: AutoHideHandler;
|
67
|
64
|
|
68
|
|
- onScroll = (event: SyntheticEvent<EventTarget>) => {
|
69
|
|
- this.hideHandler.onScroll(event);
|
70
|
|
- };
|
|
65
|
+ displayModeIcons: {[key: string]: string};
|
71
|
66
|
|
72
|
|
- changeDisplayMode = () => {
|
73
|
|
- let newMode;
|
74
|
|
- switch (this.state.currentMode) {
|
75
|
|
- case DISPLAY_MODES.DAY:
|
76
|
|
- newMode = DISPLAY_MODES.WEEK;
|
77
|
|
- break;
|
78
|
|
- case DISPLAY_MODES.WEEK:
|
79
|
|
- newMode = DISPLAY_MODES.MONTH;
|
80
|
|
-
|
81
|
|
- break;
|
82
|
|
- case DISPLAY_MODES.MONTH:
|
83
|
|
- newMode = DISPLAY_MODES.DAY;
|
84
|
|
- break;
|
85
|
|
- }
|
86
|
|
- this.setState({currentMode: newMode});
|
87
|
|
- this.props.onPress("changeView", newMode);
|
|
67
|
+ constructor() {
|
|
68
|
+ super();
|
|
69
|
+ this.state = {
|
|
70
|
+ currentMode: DISPLAY_MODES.WEEK,
|
88
|
71
|
};
|
89
|
|
-
|
90
|
|
- render() {
|
91
|
|
- const buttonColor = this.props.theme.colors.primary;
|
92
|
|
- return (
|
93
|
|
- <Animatable.View
|
94
|
|
- ref={this.ref}
|
95
|
|
- useNativeDriver
|
96
|
|
- style={{
|
97
|
|
- ...styles.container,
|
98
|
|
- bottom: 10 + CustomTabBar.TAB_BAR_HEIGHT
|
99
|
|
- }}>
|
100
|
|
- <Surface style={styles.surface}>
|
101
|
|
- <View style={styles.fabContainer}>
|
102
|
|
- <AnimatedFAB
|
103
|
|
- animation={this.props.seekAttention ? "bounce" : undefined}
|
104
|
|
- easing="ease-out"
|
105
|
|
- iterationDelay={500}
|
106
|
|
- iterationCount="infinite"
|
107
|
|
- useNativeDriver
|
108
|
|
- style={styles.fab}
|
109
|
|
- icon="account-clock"
|
110
|
|
- onPress={() => this.props.navigation.navigate('group-select')}
|
111
|
|
- />
|
112
|
|
- </View>
|
113
|
|
- <View style={{flexDirection: 'row'}}>
|
114
|
|
- <IconButton
|
115
|
|
- icon={this.displayModeIcons[this.state.currentMode]}
|
116
|
|
- color={buttonColor}
|
117
|
|
- onPress={this.changeDisplayMode}/>
|
118
|
|
- <IconButton
|
119
|
|
- icon="clock-in"
|
120
|
|
- color={buttonColor}
|
121
|
|
- style={{marginLeft: 5}}
|
122
|
|
- onPress={() => this.props.onPress('today', undefined)}/>
|
123
|
|
- </View>
|
124
|
|
- <View style={{flexDirection: 'row'}}>
|
125
|
|
- <IconButton
|
126
|
|
- icon="chevron-left"
|
127
|
|
- color={buttonColor}
|
128
|
|
- onPress={() => this.props.onPress('prev', undefined)}/>
|
129
|
|
- <IconButton
|
130
|
|
- icon="chevron-right"
|
131
|
|
- color={buttonColor}
|
132
|
|
- style={{marginLeft: 5}}
|
133
|
|
- onPress={() => this.props.onPress('next', undefined)}/>
|
134
|
|
- </View>
|
135
|
|
- </Surface>
|
136
|
|
- </Animatable.View>
|
137
|
|
- );
|
|
72
|
+ this.ref = React.createRef();
|
|
73
|
+ this.hideHandler = new AutoHideHandler(false);
|
|
74
|
+ this.hideHandler.addListener(this.onHideChange);
|
|
75
|
+
|
|
76
|
+ this.displayModeIcons = {};
|
|
77
|
+ this.displayModeIcons[DISPLAY_MODES.DAY] = 'calendar-text';
|
|
78
|
+ this.displayModeIcons[DISPLAY_MODES.WEEK] = 'calendar-week';
|
|
79
|
+ this.displayModeIcons[DISPLAY_MODES.MONTH] = 'calendar-range';
|
|
80
|
+ }
|
|
81
|
+
|
|
82
|
+ shouldComponentUpdate(nextProps: PropsType, nextState: StateType): boolean {
|
|
83
|
+ const {props, state} = this;
|
|
84
|
+ return (
|
|
85
|
+ nextProps.seekAttention !== props.seekAttention ||
|
|
86
|
+ nextState.currentMode !== state.currentMode
|
|
87
|
+ );
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ onHideChange = (shouldHide: boolean) => {
|
|
91
|
+ if (this.ref.current != null) {
|
|
92
|
+ if (shouldHide) this.ref.current.fadeOutDown(500);
|
|
93
|
+ else this.ref.current.fadeInUp(500);
|
138
|
94
|
}
|
139
|
|
-}
|
140
|
|
-
|
141
|
|
-const styles = StyleSheet.create({
|
142
|
|
- container: {
|
143
|
|
- position: 'absolute',
|
144
|
|
- left: '5%',
|
145
|
|
- width: '90%',
|
146
|
|
- },
|
147
|
|
- surface: {
|
148
|
|
- position: 'relative',
|
149
|
|
- flexDirection: 'row',
|
150
|
|
- justifyContent: 'space-between',
|
151
|
|
- alignItems: 'center',
|
152
|
|
- borderRadius: 50,
|
153
|
|
- elevation: 2,
|
154
|
|
- },
|
155
|
|
- fabContainer: {
|
156
|
|
- position: "absolute",
|
157
|
|
- left: 0,
|
158
|
|
- right: 0,
|
159
|
|
- alignItems: "center",
|
160
|
|
- width: '100%',
|
161
|
|
- height: '100%'
|
162
|
|
- },
|
163
|
|
- fab: {
|
164
|
|
- position: 'absolute',
|
165
|
|
- alignSelf: 'center',
|
166
|
|
- top: '-25%',
|
|
95
|
+ };
|
|
96
|
+
|
|
97
|
+ onScroll = (event: SyntheticEvent<EventTarget>) => {
|
|
98
|
+ this.hideHandler.onScroll(event);
|
|
99
|
+ };
|
|
100
|
+
|
|
101
|
+ changeDisplayMode = () => {
|
|
102
|
+ const {props, state} = this;
|
|
103
|
+ let newMode;
|
|
104
|
+ switch (state.currentMode) {
|
|
105
|
+ case DISPLAY_MODES.DAY:
|
|
106
|
+ newMode = DISPLAY_MODES.WEEK;
|
|
107
|
+ break;
|
|
108
|
+ case DISPLAY_MODES.WEEK:
|
|
109
|
+ newMode = DISPLAY_MODES.MONTH;
|
|
110
|
+ break;
|
|
111
|
+ case DISPLAY_MODES.MONTH:
|
|
112
|
+ newMode = DISPLAY_MODES.DAY;
|
|
113
|
+ break;
|
|
114
|
+ default:
|
|
115
|
+ newMode = DISPLAY_MODES.WEEK;
|
|
116
|
+ break;
|
167
|
117
|
}
|
168
|
|
-});
|
|
118
|
+ this.setState({currentMode: newMode});
|
|
119
|
+ props.onPress('changeView', newMode);
|
|
120
|
+ };
|
|
121
|
+
|
|
122
|
+ render(): React.Node {
|
|
123
|
+ const {props, state} = this;
|
|
124
|
+ const buttonColor = props.theme.colors.primary;
|
|
125
|
+ return (
|
|
126
|
+ <Animatable.View
|
|
127
|
+ ref={this.ref}
|
|
128
|
+ useNativeDriver
|
|
129
|
+ style={{
|
|
130
|
+ ...styles.container,
|
|
131
|
+ bottom: 10 + CustomTabBar.TAB_BAR_HEIGHT,
|
|
132
|
+ }}>
|
|
133
|
+ <Surface style={styles.surface}>
|
|
134
|
+ <View style={styles.fabContainer}>
|
|
135
|
+ <AnimatedFAB
|
|
136
|
+ animation={props.seekAttention ? 'bounce' : undefined}
|
|
137
|
+ easing="ease-out"
|
|
138
|
+ iterationDelay={500}
|
|
139
|
+ iterationCount="infinite"
|
|
140
|
+ useNativeDriver
|
|
141
|
+ style={styles.fab}
|
|
142
|
+ icon="account-clock"
|
|
143
|
+ onPress={(): void => props.navigation.navigate('group-select')}
|
|
144
|
+ />
|
|
145
|
+ </View>
|
|
146
|
+ <View style={{flexDirection: 'row'}}>
|
|
147
|
+ <IconButton
|
|
148
|
+ icon={this.displayModeIcons[state.currentMode]}
|
|
149
|
+ color={buttonColor}
|
|
150
|
+ onPress={this.changeDisplayMode}
|
|
151
|
+ />
|
|
152
|
+ <IconButton
|
|
153
|
+ icon="clock-in"
|
|
154
|
+ color={buttonColor}
|
|
155
|
+ style={{marginLeft: 5}}
|
|
156
|
+ onPress={(): void => props.onPress('today')}
|
|
157
|
+ />
|
|
158
|
+ </View>
|
|
159
|
+ <View style={{flexDirection: 'row'}}>
|
|
160
|
+ <IconButton
|
|
161
|
+ icon="chevron-left"
|
|
162
|
+ color={buttonColor}
|
|
163
|
+ onPress={(): void => props.onPress('prev')}
|
|
164
|
+ />
|
|
165
|
+ <IconButton
|
|
166
|
+ icon="chevron-right"
|
|
167
|
+ color={buttonColor}
|
|
168
|
+ style={{marginLeft: 5}}
|
|
169
|
+ onPress={(): void => props.onPress('next')}
|
|
170
|
+ />
|
|
171
|
+ </View>
|
|
172
|
+ </Surface>
|
|
173
|
+ </Animatable.View>
|
|
174
|
+ );
|
|
175
|
+ }
|
|
176
|
+}
|
169
|
177
|
|
170
|
178
|
export default withTheme(AnimatedBottomBar);
|