1
1
import React , { useState } from 'react'
2
- import { View , Pressable , StyleSheet } from 'react-native'
2
+ import { View , Pressable , StyleSheet , ViewProps } from 'react-native'
3
3
4
4
import Text from '../../components/Text'
5
5
import Dialog , { dialogStyles } from '../../components/Dialog'
6
6
import globalStyle from '../../globalStyle'
7
7
import useDarkMode from '../../context/useDarkMode'
8
8
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
+
9
47
interface DarkModeSettingProps {
10
48
value : boolean | null
11
49
setValue : ( newValue : boolean | null ) => void
12
50
}
13
51
14
52
const DarkModeSetting = ( { value, setValue } : DarkModeSettingProps ) => {
15
53
const [ modalOpen , setModalOpen ] = useState ( false )
16
- const save = ( newValue : boolean | null ) => {
17
- setValue ( newValue )
18
- setModalOpen ( false )
19
- }
20
54
const ripple = { color : '#aaa' }
21
55
const dark = useDarkMode ( )
22
56
const cancelStyle = dark
23
57
? dialogStyles . modalButtonCancelDarkText
24
58
: dialogStyles . modalButtonCancelText
25
59
return (
26
- // LOW-TODO: Should have radio buttons.
27
60
< Pressable onPress = { ( ) => setModalOpen ( true ) } android_ripple = { ripple } >
28
61
< Dialog visible = { modalOpen } onRequestClose = { ( ) => setModalOpen ( false ) } >
29
62
< Text style = { [ dialogStyles . modalTitle , styles . dialogTitle ] } >
30
63
Dark mode
31
64
</ 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 } />
33
71
< Text style = { styles . settingItem } > Enabled</ Text >
34
72
</ 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 } />
36
79
< Text style = { styles . settingItem } > Disabled</ Text >
37
80
</ 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 } />
39
87
< Text style = { styles . settingItem } > Use system default</ Text >
40
88
</ Pressable >
41
89
< View style = { dialogStyles . modalButtons } >
@@ -45,7 +93,7 @@ const DarkModeSetting = ({ value, setValue }: DarkModeSettingProps) => {
45
93
style = { dialogStyles . modalButton }
46
94
onPress = { ( ) => setModalOpen ( false ) }
47
95
>
48
- < Text style = { cancelStyle } > CANCEL </ Text >
96
+ < Text style = { cancelStyle } > CLOSE </ Text >
49
97
</ Pressable >
50
98
</ View >
51
99
</ Dialog >
@@ -63,6 +111,7 @@ const styles = StyleSheet.create({
63
111
setting : { padding : 12 , paddingLeft : 22 , paddingRight : 22 } ,
64
112
settingText : { fontSize : 18 } ,
65
113
dialogTitle : { marginBottom : 12 } ,
114
+ dialogOption : { flexDirection : 'row' } ,
66
115
settingItem : { fontSize : 18 , width : '100%' , padding : 8 } ,
67
116
settingSubtext : { fontSize : 12 , fontWeight : '400' , color : '#666' } ,
68
117
settingSubtextDark : { fontSize : 12 , fontWeight : '400' , color : '#aaa' }
0 commit comments