forked from callstack/react-native-paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDrawerItems.js
101 lines (90 loc) · 2.53 KB
/
DrawerItems.js
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
90
91
92
93
94
95
96
97
98
99
100
101
/* @flow */
import * as React from 'react';
import { View, StyleSheet, Platform } from 'react-native';
import {
Drawer,
withTheme,
Switch,
TouchableRipple,
Text,
Colors,
type Theme,
} from 'react-native-paper';
type Props = {
theme: Theme,
toggleTheme: Function,
toggleRTL: Function,
isRTL: boolean,
isDarkTheme: boolean,
};
type State = {
open: boolean,
drawerItemIndex: number,
};
const DrawerItemsData = [
{ label: 'Inbox', icon: 'inbox', key: 0 },
{ label: 'Starred', icon: 'star', key: 1 },
{ label: 'Sent mail', icon: 'send', key: 2 },
{ label: 'Colored label', icon: 'color-lens', key: 3 },
{ label: 'A very long title that will be truncated', icon: 'delete', key: 4 },
];
class DrawerItems extends React.Component<Props, State> {
state = {
open: false,
drawerItemIndex: 0,
};
_setDrawerItem = index => this.setState({ drawerItemIndex: index });
render() {
const { colors } = this.props.theme;
return (
<View style={[styles.drawerContent, { backgroundColor: colors.surface }]}>
<Drawer.Section title="Example items">
{DrawerItemsData.map((props, index) => (
<Drawer.Item
{...props}
key={props.key}
theme={
props.key === 3
? { colors: { primary: Colors.tealA200 } }
: undefined
}
active={this.state.drawerItemIndex === index}
onPress={() => this._setDrawerItem(index)}
/>
))}
</Drawer.Section>
<Drawer.Section title="Preferences">
<TouchableRipple onPress={this.props.toggleTheme}>
<View style={styles.preference}>
<Text>Dark Theme</Text>
<View pointerEvents="none">
<Switch value={this.props.isDarkTheme} />
</View>
</View>
</TouchableRipple>
<TouchableRipple onPress={this.props.toggleRTL}>
<View style={styles.preference}>
<Text>RTL</Text>
<View pointerEvents="none">
<Switch value={this.props.isRTL} />
</View>
</View>
</TouchableRipple>
</Drawer.Section>
</View>
);
}
}
const styles = StyleSheet.create({
drawerContent: {
flex: 1,
paddingTop: Platform.OS === 'android' ? 25 : 22,
},
preference: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingVertical: 12,
paddingHorizontal: 16,
},
});
export default withTheme(DrawerItems);