Skip to content

Commit ef81fe9

Browse files
committed
Add radio button to dark mode setting dialog.
1 parent 32a378d commit ef81fe9

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

src/screens/settings/DarkModeSetting.tsx

+59-10
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,89 @@
11
import React, { useState } from 'react'
2-
import { View, Pressable, StyleSheet } from 'react-native'
2+
import { View, Pressable, StyleSheet, ViewProps } from 'react-native'
33

44
import Text from '../../components/Text'
55
import Dialog, { dialogStyles } from '../../components/Dialog'
66
import globalStyle from '../../globalStyle'
77
import useDarkMode from '../../context/useDarkMode'
88

9+
const RadioButton = (props: { style?: ViewProps; selected: boolean }) => {
10+
const darkMode = useDarkMode()
11+
return (
12+
<View
13+
style={[
14+
radioButtonStyles.outerView,
15+
darkMode ? radioButtonStyles.outerViewDark : {},
16+
props.style
17+
]}
18+
>
19+
{props.selected ? (
20+
<View
21+
style={[
22+
radioButtonStyles.innerView,
23+
darkMode ? radioButtonStyles.innerViewDark : {}
24+
]}
25+
/>
26+
) : null}
27+
</View>
28+
)
29+
}
30+
31+
const radioButtonStyles = StyleSheet.create({
32+
outerView: {
33+
margin: 8,
34+
height: 24,
35+
width: 24,
36+
borderRadius: 12,
37+
borderWidth: 2,
38+
borderColor: '#000',
39+
alignItems: 'center',
40+
justifyContent: 'center'
41+
},
42+
outerViewDark: { borderColor: '#fff' },
43+
innerViewDark: { backgroundColor: '#fff' },
44+
innerView: { height: 12, width: 12, borderRadius: 6, backgroundColor: '#000' }
45+
})
46+
947
interface DarkModeSettingProps {
1048
value: boolean | null
1149
setValue: (newValue: boolean | null) => void
1250
}
1351

1452
const DarkModeSetting = ({ value, setValue }: DarkModeSettingProps) => {
1553
const [modalOpen, setModalOpen] = useState(false)
16-
const save = (newValue: boolean | null) => {
17-
setValue(newValue)
18-
setModalOpen(false)
19-
}
2054
const ripple = { color: '#aaa' }
2155
const dark = useDarkMode()
2256
const cancelStyle = dark
2357
? dialogStyles.modalButtonCancelDarkText
2458
: dialogStyles.modalButtonCancelText
2559
return (
26-
// LOW-TODO: Should have radio buttons.
2760
<Pressable onPress={() => setModalOpen(true)} android_ripple={ripple}>
2861
<Dialog visible={modalOpen} onRequestClose={() => setModalOpen(false)}>
2962
<Text style={[dialogStyles.modalTitle, styles.dialogTitle]}>
3063
Dark mode
3164
</Text>
32-
<Pressable onPress={() => save(true)} android_ripple={ripple}>
65+
<Pressable
66+
onPress={() => setValue(true)}
67+
android_ripple={ripple}
68+
style={styles.dialogOption}
69+
>
70+
<RadioButton selected={value === true} />
3371
<Text style={styles.settingItem}>Enabled</Text>
3472
</Pressable>
35-
<Pressable onPress={() => save(false)} android_ripple={ripple}>
73+
<Pressable
74+
onPress={() => setValue(false)}
75+
android_ripple={ripple}
76+
style={styles.dialogOption}
77+
>
78+
<RadioButton selected={value === false} />
3679
<Text style={styles.settingItem}>Disabled</Text>
3780
</Pressable>
38-
<Pressable onPress={() => save(null)} android_ripple={ripple}>
81+
<Pressable
82+
onPress={() => setValue(null)}
83+
android_ripple={ripple}
84+
style={styles.dialogOption}
85+
>
86+
<RadioButton selected={value === null} />
3987
<Text style={styles.settingItem}>Use system default</Text>
4088
</Pressable>
4189
<View style={dialogStyles.modalButtons}>
@@ -45,7 +93,7 @@ const DarkModeSetting = ({ value, setValue }: DarkModeSettingProps) => {
4593
style={dialogStyles.modalButton}
4694
onPress={() => setModalOpen(false)}
4795
>
48-
<Text style={cancelStyle}>CANCEL</Text>
96+
<Text style={cancelStyle}>CLOSE</Text>
4997
</Pressable>
5098
</View>
5199
</Dialog>
@@ -63,6 +111,7 @@ const styles = StyleSheet.create({
63111
setting: { padding: 12, paddingLeft: 22, paddingRight: 22 },
64112
settingText: { fontSize: 18 },
65113
dialogTitle: { marginBottom: 12 },
114+
dialogOption: { flexDirection: 'row' },
66115
settingItem: { fontSize: 18, width: '100%', padding: 8 },
67116
settingSubtext: { fontSize: 12, fontWeight: '400', color: '#666' },
68117
settingSubtextDark: { fontSize: 12, fontWeight: '400', color: '#aaa' }

0 commit comments

Comments
 (0)