-
Notifications
You must be signed in to change notification settings - Fork 41
/
UserListList.tsx
40 lines (35 loc) · 1.28 KB
/
UserListList.tsx
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
import React, { useCallback, useContext } from 'react';
import { FlatList, ListRenderItem } from 'react-native';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import type { UserStruct } from '@sendbird/uikit-utils';
import { getUserUniqId } from '@sendbird/uikit-utils';
import { UserListContexts } from '../module/moduleContext';
import type { UserListContextsType, UserListProps } from '../types';
const UserListList = <T extends UserStruct>({
users,
onRefresh,
refreshing,
renderUser,
onLoadNext,
ListEmptyComponent,
}: UserListProps<T>['List']) => {
const context = useContext(UserListContexts.List as UserListContextsType<T>['List']);
const renderItem: ListRenderItem<T> = useCallback(
({ item }) => renderUser?.(item, context.selectedUsers, context.setSelectedUsers),
[renderUser, context.selectedUsers, context.setSelectedUsers],
);
const { left, right } = useSafeAreaInsets();
return (
<FlatList
data={users}
refreshing={refreshing}
onRefresh={onRefresh}
renderItem={renderItem}
onEndReached={onLoadNext}
contentContainerStyle={{ paddingLeft: left, paddingRight: right, flexGrow: 1 }}
ListEmptyComponent={ListEmptyComponent}
keyExtractor={getUserUniqId}
/>
);
};
export default UserListList;