-
Notifications
You must be signed in to change notification settings - Fork 372
Expand file tree
/
Copy pathMenuDrawer.tsx
More file actions
173 lines (163 loc) · 4.23 KB
/
MenuDrawer.tsx
File metadata and controls
173 lines (163 loc) · 4.23 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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
import React, { useCallback, useEffect, useState } from 'react';
import {
Image,
StyleSheet,
Text,
TouchableOpacity,
Pressable,
View,
} from 'react-native';
import { Edit, Group, User, useTheme } from 'stream-chat-react-native';
import { useAppContext } from '../context/AppContext';
import { SecretMenu } from './SecretMenu.tsx';
import type { DrawerContentComponentProps } from '@react-navigation/drawer';
import { SafeAreaView } from 'react-native-safe-area-context';
export const styles = StyleSheet.create({
avatar: {
borderRadius: 20,
height: 40,
width: 40,
},
container: {
flex: 1,
},
menuContainer: {
flex: 1,
justifyContent: 'space-between',
marginTop: 16,
},
menuItem: {
alignItems: 'center',
flexDirection: 'row',
paddingHorizontal: 16,
paddingVertical: 12,
},
menuTitle: {
fontSize: 14,
fontWeight: '500',
marginLeft: 16,
},
userName: {
fontSize: 16,
fontWeight: '600',
marginLeft: 16,
},
userRow: {
alignItems: 'center',
flexDirection: 'row',
padding: 8,
},
});
export const MenuDrawer = ({ navigation }: DrawerContentComponentProps) => {
const [secretMenuPressCounter, setSecretMenuPressCounter] = useState(0);
const [secretMenuVisible, setSecretMenuVisible] = useState(false);
const {
theme: {
colors: { black, grey, white },
},
} = useTheme();
useEffect(() => {
if (!secretMenuVisible && secretMenuPressCounter >= 7) {
setSecretMenuVisible(true);
}
}, [secretMenuVisible, secretMenuPressCounter]);
const closeSecretMenu = useCallback(() => {
setSecretMenuPressCounter(0);
setSecretMenuVisible(false);
}, []);
const { chatClient, logout } = useAppContext();
if (!chatClient) {
return null;
}
return (
<View style={[styles.container, { backgroundColor: white }]}>
<SafeAreaView style={{ flex: 1 }}>
<Pressable onPress={() => setSecretMenuPressCounter((c) => c + 1)} style={[styles.userRow]}>
<Image
source={{
uri: chatClient.user?.image,
}}
style={styles.avatar}
/>
<Text
style={[
styles.userName,
{
color: black,
},
]}
>
{chatClient.user?.name}
</Text>
</Pressable>
<View style={styles.menuContainer}>
<View>
<SecretMenu
visible={secretMenuVisible}
close={closeSecretMenu}
chatClient={chatClient}
/>
<TouchableOpacity
onPress={() =>
navigation.navigate('HomeScreen', {
screen: 'NewDirectMessagingScreen',
})
}
style={styles.menuItem}
>
<Edit height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
New Direct Messages
</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() =>
navigation.navigate('HomeScreen', {
screen: 'NewGroupChannelAddMemberScreen',
})
}
style={styles.menuItem}
>
<Group height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
New Group
</Text>
</TouchableOpacity>
</View>
<TouchableOpacity
onPress={() => {
logout();
}}
style={styles.menuItem}
>
<User height={24} pathFill={grey} width={24} />
<Text
style={[
styles.menuTitle,
{
color: black,
},
]}
>
Sign Out
</Text>
</TouchableOpacity>
</View>
</SafeAreaView>
</View>
);
};