Toolbar.tsx
2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import React, { useCallback } from 'react';
import { SafeAreaView, TouchableOpacity, StyleSheet, View } from 'react-native';
import RNCWebview from 'react-native-webview';
import EvilIcons from 'react-native-vector-icons/EvilIcons';
import { WebviewState, WebviewActions } from './reducer';
import {
DynamicStyleSheet,
useDynamicStyleSheet,
useDynamicValue,
} from 'react-native-dark-mode';
import { colorPreset } from '../../design';
interface Props {
state: WebviewState;
dispatch: React.Dispatch<WebviewActions>;
webview: React.RefObject<RNCWebview>;
}
const dynamicStyles = new DynamicStyleSheet({
background: {
backgroundColor: colorPreset.backgroundColor.primary,
borderTopWidth: StyleSheet.hairlineWidth,
borderTopColor: colorPreset.separator.opaque,
},
container: {
height: 44,
flexDirection: 'row',
justifyContent: 'space-evenly',
},
button: {
width: 44,
height: 44,
justifyContent: 'center',
alignItems: 'center',
},
});
const Toolbar = ({ state, webview }: Props) => {
const { canGoBack, canGoForward, loading } = state;
const styles = useDynamicStyleSheet(dynamicStyles);
const primaryLabelColor = useDynamicValue(colorPreset.labelColor.primary);
const secondaryLabelColor = useDynamicValue(colorPreset.labelColor.tertiary);
const onPressLoading = useCallback(() => {
if (loading) {
webview.current?.stopLoading();
} else {
webview.current?.reload();
}
}, [loading, webview]);
return (
<SafeAreaView style={styles.background}>
<View style={styles.container}>
<TouchableOpacity
style={styles.button}
disabled={!canGoBack}
onPress={() => webview.current?.goBack()}
>
<EvilIcons
name="chevron-left"
size={40}
color={canGoBack ? primaryLabelColor : secondaryLabelColor}
/>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
disabled={!canGoForward}
onPress={() => webview.current?.goForward()}
>
<EvilIcons
name="chevron-right"
size={40}
color={canGoForward ? primaryLabelColor : secondaryLabelColor}
/>
</TouchableOpacity>
<TouchableOpacity style={styles.button} onPress={onPressLoading}>
<EvilIcons
name={loading ? 'close' : 'refresh'}
size={40}
color={primaryLabelColor}
/>
</TouchableOpacity>
</View>
</SafeAreaView>
);
};
export default Toolbar;