-
Notifications
You must be signed in to change notification settings - Fork 373
Expand file tree
/
Copy pathNewGroupChannelAddMemberScreen.tsx
More file actions
160 lines (142 loc) · 4.49 KB
/
NewGroupChannelAddMemberScreen.tsx
File metadata and controls
160 lines (142 loc) · 4.49 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
import React, { useCallback } from 'react';
import { FlatList, StyleSheet, TextInput, TouchableOpacity, View } from 'react-native';
import { Search, useTheme } from 'stream-chat-react-native';
import { RightArrow } from '../icons/RightArrow';
import { ScreenHeader } from '../components/ScreenHeader';
import { UserGridItem } from '../components/UserSearch/UserGridItem';
import { UserSearchResults } from '../components/UserSearch/UserSearchResults';
import { useAppContext } from '../context/AppContext';
import { useUserSearchContext } from '../context/UserSearchContext';
import { useLegacyColors } from '../theme/useLegacyColors';
import type { NativeStackNavigationProp } from '@react-navigation/native-stack';
import type { StackNavigatorParamList } from '../types';
const styles = StyleSheet.create({
container: {
flex: 1,
},
flatList: { paddingBottom: 16 },
inputBox: {
flex: 1,
fontSize: 14,
includeFontPadding: false, // for android vertical text centering
padding: 0, // removal of default text input padding on android
paddingHorizontal: 16,
paddingTop: 0, // removal of iOS top padding for weird centering
textAlignVertical: 'center', // for android vertical text centering
},
inputBoxContainer: {
alignItems: 'center',
borderRadius: 18,
borderWidth: 1,
flexDirection: 'row',
marginHorizontal: 8,
marginTop: 8,
paddingHorizontal: 10,
paddingVertical: 8,
},
navigationButton: {
paddingRight: 8,
},
userGridItemContainer: { marginHorizontal: 8, width: 64 },
});
type RightArrowButtonProps = {
disabled?: boolean;
onPress?: () => void;
};
const RightArrowButton: React.FC<RightArrowButtonProps> = (props) => {
const { disabled, onPress } = props;
return (
<TouchableOpacity disabled={disabled} onPress={onPress} style={styles.navigationButton}>
<RightArrow height={24} width={24} />
</TouchableOpacity>
);
};
export type NewGroupChannelAddMemberScreenNavigationProp = NativeStackNavigationProp<
StackNavigatorParamList,
'NewGroupChannelAddMemberScreen'
>;
type Props = {
navigation: NewGroupChannelAddMemberScreenNavigationProp;
};
export const NewGroupChannelAddMemberScreen: React.FC<Props> = ({ navigation }) => {
const { chatClient } = useAppContext();
const {
theme: { semantics },
} = useTheme();
const { black, grey, white } = useLegacyColors();
const { onChangeSearchText, onFocusInput, removeUser, reset, searchText, selectedUsers } =
useUserSearchContext();
const onBackPress = useCallback(() => {
reset();
if (!navigation.canGoBack()) {
navigation.reset({ index: 0, routes: [{ name: 'MessagingScreen' }] });
return;
}
navigation.goBack();
}, [navigation, reset]);
const onRightArrowPress = () => {
if (selectedUsers.length === 0) {
return;
}
navigation.navigate('NewGroupChannelAssignNameScreen');
};
if (!chatClient) {
return null;
}
return (
<View style={styles.container}>
<ScreenHeader
onBack={onBackPress}
// eslint-disable-next-line react/no-unstable-nested-components
RightContent={() => (
<RightArrowButton disabled={selectedUsers.length === 0} onPress={onRightArrowPress} />
)}
titleText='Add Group Members'
/>
<View>
<View
style={[
styles.inputBoxContainer,
{
backgroundColor: white,
borderColor: semantics.borderCoreDefault,
marginBottom: selectedUsers.length === 0 ? 8 : 16,
},
]}
>
<Search pathFill={black} />
<TextInput
onChangeText={onChangeSearchText}
onFocus={onFocusInput}
placeholder='Search'
placeholderTextColor={grey}
style={[
styles.inputBox,
{
color: black,
},
]}
value={searchText}
/>
</View>
<FlatList
data={selectedUsers}
horizontal
keyExtractor={(item, index) => `${item.id}-${index}`}
renderItem={({ index, item: user }) => (
<View style={styles.userGridItemContainer}>
<UserGridItem
onPress={() => {
removeUser(index);
}}
user={user}
/>
</View>
)}
style={selectedUsers.length ? styles.flatList : {}}
/>
</View>
<UserSearchResults />
</View>
);
};