|
| 1 | +import React, { useContext } from 'react'; |
| 2 | +import { I18nManager, Pressable, ScrollView, View } from 'react-native'; |
| 3 | + |
| 4 | +import { Icon, Switch, Text } from '@sendbird/uikit-react-native-foundation'; |
| 5 | + |
| 6 | +import { UIKitLocalConfigsContext } from '../context/uikitLocalConfigs'; |
| 7 | + |
| 8 | +const Divider = () => <View style={{ height: 1, backgroundColor: '#dcdcdc' }} />; |
| 9 | + |
| 10 | +const UIKitLocalConfigsScreen = () => { |
| 11 | + const { localConfigs, setLocalConfigs } = useContext(UIKitLocalConfigsContext); |
| 12 | + return ( |
| 13 | + <ScrollView |
| 14 | + style={{ backgroundColor: 'white' }} |
| 15 | + contentContainerStyle={{ |
| 16 | + flexGrow: 1, |
| 17 | + paddingHorizontal: 16, |
| 18 | + paddingVertical: 12, |
| 19 | + gap: 20, |
| 20 | + backgroundColor: 'white', |
| 21 | + }} |
| 22 | + > |
| 23 | + <Switchable |
| 24 | + title={'RTL'} |
| 25 | + description={'Right to left, please restart the app to apply the changes'} |
| 26 | + value={localConfigs.rtl} |
| 27 | + onChange={(value) => { |
| 28 | + I18nManager.forceRTL(value); |
| 29 | + setLocalConfigs((prev) => ({ ...prev, rtl: value })); |
| 30 | + }} |
| 31 | + /> |
| 32 | + <Divider /> |
| 33 | + |
| 34 | + <Selectable |
| 35 | + title={'Reply Type'} |
| 36 | + value={localConfigs.replyType} |
| 37 | + values={['none', 'thread', 'quote_reply']} |
| 38 | + onChange={(value) => setLocalConfigs((prev) => ({ ...prev, replyType: value }))} |
| 39 | + /> |
| 40 | + {localConfigs.replyType === 'thread' && ( |
| 41 | + <View style={{ marginStart: 12, flexDirection: 'row' }}> |
| 42 | + <View style={{ width: 4, height: '100%', backgroundColor: '#dcdcdc', marginEnd: 12 }} /> |
| 43 | + <Selectable |
| 44 | + title={'Reply Select Type'} |
| 45 | + value={localConfigs.threadReplySelectType} |
| 46 | + values={['thread', 'parent']} |
| 47 | + onChange={(value) => setLocalConfigs((prev) => ({ ...prev, threadReplySelectType: value }))} |
| 48 | + /> |
| 49 | + </View> |
| 50 | + )} |
| 51 | + </ScrollView> |
| 52 | + ); |
| 53 | +}; |
| 54 | + |
| 55 | +const Switchable = ({ |
| 56 | + title, |
| 57 | + description, |
| 58 | + value, |
| 59 | + onChange, |
| 60 | +}: { |
| 61 | + value: boolean; |
| 62 | + onChange: (value: boolean) => void; |
| 63 | + title?: string; |
| 64 | + description?: string; |
| 65 | +}) => { |
| 66 | + return ( |
| 67 | + <View style={{ flexDirection: 'column', alignItems: 'flex-start', gap: 8 }}> |
| 68 | + {!!title && <Text h2>{title}</Text>} |
| 69 | + {!!description && <Text caption2>{description}</Text>} |
| 70 | + |
| 71 | + <Switch value={value} onChangeValue={onChange} /> |
| 72 | + </View> |
| 73 | + ); |
| 74 | +}; |
| 75 | + |
| 76 | +interface SelectableProps<T> { |
| 77 | + value: T; |
| 78 | + values: T[]; |
| 79 | + onChange: (value: T) => void; |
| 80 | + title?: string; |
| 81 | +} |
| 82 | +const Selectable = <T extends string>({ title, values, value, onChange }: SelectableProps<T>) => { |
| 83 | + return ( |
| 84 | + <View style={{ flexDirection: 'column', alignItems: 'flex-start', gap: 8 }}> |
| 85 | + {!!title && <Text h2>{title}</Text>} |
| 86 | + <View style={{ flexDirection: 'row', alignItems: 'center' }}> |
| 87 | + {values.map((v) => ( |
| 88 | + <Pressable |
| 89 | + key={v} |
| 90 | + onPress={() => onChange(v)} |
| 91 | + style={{ flexDirection: 'row', alignItems: 'center', gap: 4, marginEnd: 8 }} |
| 92 | + > |
| 93 | + <Icon icon={value === v ? 'checkbox-on' : 'checkbox-off'} size={24} /> |
| 94 | + <Text caption1>{v}</Text> |
| 95 | + </Pressable> |
| 96 | + ))} |
| 97 | + </View> |
| 98 | + </View> |
| 99 | + ); |
| 100 | +}; |
| 101 | + |
| 102 | +export default UIKitLocalConfigsScreen; |
0 commit comments