Use a three-state radio button for color mode
parent
da0ed7e002
commit
85dfef87ab
|
@ -229,14 +229,19 @@ function onPressInner(
|
||||||
} else if (
|
} else if (
|
||||||
!e.defaultPrevented && // onPress prevented default
|
!e.defaultPrevented && // onPress prevented default
|
||||||
// @ts-ignore Web only -prf
|
// @ts-ignore Web only -prf
|
||||||
!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey) && // ignore clicks with modifier keys
|
!(e.metaKey || e.altKey || e.shiftKey) && // ignore clicks with modifier keys
|
||||||
// @ts-ignore Web only -prf
|
// @ts-ignore Web only -prf
|
||||||
(e.button == null || e.button === 0) && // ignore everything but left clicks
|
(e.button == null || e.button === 0) && // ignore everything but left clicks
|
||||||
// @ts-ignore Web only -prf
|
// @ts-ignore Web only -prf
|
||||||
[undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle "target=_blank" etc.
|
[undefined, null, '', 'self'].includes(e.currentTarget?.target) // let browser handle "target=_blank" etc.
|
||||||
) {
|
) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
shouldHandle = true
|
if (e.ctrlKey && Platform.OS === 'web') {
|
||||||
|
shouldHandle = false
|
||||||
|
window.open(href, '_blank')
|
||||||
|
} else {
|
||||||
|
shouldHandle = true
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldHandle) {
|
if (shouldHandle) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, {ComponentProps} from 'react'
|
import React, {ComponentProps} from 'react'
|
||||||
import {
|
import {
|
||||||
Linking,
|
Linking,
|
||||||
|
Pressable,
|
||||||
SafeAreaView,
|
SafeAreaView,
|
||||||
StyleProp,
|
StyleProp,
|
||||||
StyleSheet,
|
StyleSheet,
|
||||||
|
@ -125,10 +126,13 @@ export const DrawerContent = observer(() => {
|
||||||
Linking.openURL(FEEDBACK_FORM_URL)
|
Linking.openURL(FEEDBACK_FORM_URL)
|
||||||
}, [track])
|
}, [track])
|
||||||
|
|
||||||
const onColorModePress = React.useCallback(() => {
|
const onColorModePress = React.useCallback(
|
||||||
track('Menu:ItemClicked', {url: '#cycleColorMode'})
|
(mode: string) => {
|
||||||
store.shell.setColorMode(nextColorMode())
|
track('Menu:ItemClicked', {url: '#cycleColorMode'})
|
||||||
}, [track, store])
|
store.shell.setColorMode(mode)
|
||||||
|
},
|
||||||
|
[track, store],
|
||||||
|
)
|
||||||
|
|
||||||
// rendering
|
// rendering
|
||||||
// =
|
// =
|
||||||
|
@ -291,23 +295,33 @@ export const DrawerContent = observer(() => {
|
||||||
<View style={s.flex1} />
|
<View style={s.flex1} />
|
||||||
<View style={styles.footer}>
|
<View style={styles.footer}>
|
||||||
{!isWeb && (
|
{!isWeb && (
|
||||||
<TouchableOpacity
|
<View>
|
||||||
accessibilityRole="button"
|
<Text type="sm" style={[pal.textLight, styles.colorModeText]}>
|
||||||
accessibilityLabel="Cycle color mode"
|
Set color theme
|
||||||
accessibilityHint={modeAccessibilityText[store.shell.colorMode]}
|
</Text>
|
||||||
onPress={onColorModePress}
|
<View style={styles.selectableBtns}>
|
||||||
style={[
|
<SelectableBtn
|
||||||
styles.footerBtn,
|
current={store.shell.colorMode}
|
||||||
theme.colorScheme === 'light'
|
value="system"
|
||||||
? pal.btn
|
label="System"
|
||||||
: styles.footerBtnDarkMode,
|
left
|
||||||
]}>
|
onChange={onColorModePress}
|
||||||
<MoonIcon
|
/>
|
||||||
size={22}
|
<SelectableBtn
|
||||||
style={pal.text as StyleProp<ViewStyle>}
|
current={store.shell.colorMode}
|
||||||
strokeWidth={2}
|
value="light"
|
||||||
/>
|
label="Light"
|
||||||
</TouchableOpacity>
|
onChange={onColorModePress}
|
||||||
|
/>
|
||||||
|
<SelectableBtn
|
||||||
|
current={store.shell.colorMode}
|
||||||
|
value="dark"
|
||||||
|
label="Dark"
|
||||||
|
right
|
||||||
|
onChange={onColorModePress}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
)}
|
)}
|
||||||
<TouchableOpacity
|
<TouchableOpacity
|
||||||
accessibilityRole="link"
|
accessibilityRole="link"
|
||||||
|
@ -428,6 +442,45 @@ const InviteCodes = observer(() => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
interface SelectableBtnProps {
|
||||||
|
current: string
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
left?: boolean
|
||||||
|
right?: boolean
|
||||||
|
onChange: (v: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectableBtn({
|
||||||
|
current,
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
onChange,
|
||||||
|
}: SelectableBtnProps) {
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const palPrimary = usePalette('inverted')
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
style={[
|
||||||
|
styles.selectableBtn,
|
||||||
|
left && styles.selectableBtnLeft,
|
||||||
|
right && styles.selectableBtnRight,
|
||||||
|
pal.border,
|
||||||
|
current === value ? palPrimary.view : pal.view,
|
||||||
|
]}
|
||||||
|
onPress={() => onChange(value)}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={value}
|
||||||
|
accessibilityHint={`Set color theme to ${value}`}>
|
||||||
|
<Text style={current === value ? palPrimary.text : pal.text}>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
view: {
|
view: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
|
@ -502,6 +555,46 @@ const styles = StyleSheet.create({
|
||||||
marginRight: 6,
|
marginRight: 6,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
colorModeText: {
|
||||||
|
marginLeft: 10,
|
||||||
|
marginBottom: 6,
|
||||||
|
},
|
||||||
|
|
||||||
|
selectableBtns: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
marginLeft: 10,
|
||||||
|
},
|
||||||
|
selectableBtn: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'center',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderLeftWidth: 0,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 10,
|
||||||
|
},
|
||||||
|
selectableBtnLeft: {
|
||||||
|
borderTopLeftRadius: 8,
|
||||||
|
borderBottomLeftRadius: 8,
|
||||||
|
borderLeftWidth: 1,
|
||||||
|
},
|
||||||
|
selectableBtnRight: {
|
||||||
|
borderTopRightRadius: 8,
|
||||||
|
borderBottomRightRadius: 8,
|
||||||
|
},
|
||||||
|
|
||||||
|
btn: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '100%',
|
||||||
|
borderRadius: 32,
|
||||||
|
padding: 14,
|
||||||
|
backgroundColor: colors.gray1,
|
||||||
|
},
|
||||||
|
toggleBtn: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
},
|
||||||
|
|
||||||
footer: {
|
footer: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'row',
|
||||||
justifyContent: 'space-between',
|
justifyContent: 'space-between',
|
||||||
|
|
|
@ -1,43 +1,20 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import {observer} from 'mobx-react-lite'
|
import {observer} from 'mobx-react-lite'
|
||||||
import {StyleSheet, TouchableOpacity, View} from 'react-native'
|
import {Pressable, StyleSheet, TouchableOpacity, View} from 'react-native'
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {DesktopSearch} from './Search'
|
import {DesktopSearch} from './Search'
|
||||||
import {Text} from 'view/com/util/text/Text'
|
import {Text} from 'view/com/util/text/Text'
|
||||||
import {TextLink} from 'view/com/util/Link'
|
import {TextLink} from 'view/com/util/Link'
|
||||||
import {FEEDBACK_FORM_URL} from 'lib/constants'
|
import {FEEDBACK_FORM_URL} from 'lib/constants'
|
||||||
import {s} from 'lib/styles'
|
import {colors, s} from 'lib/styles'
|
||||||
import {useStores} from 'state/index'
|
import {useStores} from 'state/index'
|
||||||
import {pluralize} from 'lib/strings/helpers'
|
import {pluralize} from 'lib/strings/helpers'
|
||||||
import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle'
|
|
||||||
import {MoonIcon} from 'lib/icons'
|
|
||||||
import {formatCount} from 'view/com/util/numeric/format'
|
import {formatCount} from 'view/com/util/numeric/format'
|
||||||
|
|
||||||
export const DesktopRightNav = observer(function DesktopRightNav() {
|
export const DesktopRightNav = observer(function DesktopRightNav() {
|
||||||
const store = useStores()
|
const store = useStores()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const colorModes = ['light', 'dark', 'system']
|
|
||||||
const modeAccessibilityText = {
|
|
||||||
light: 'Sets display to light mode',
|
|
||||||
dark: 'Sets display to dark mode',
|
|
||||||
system: 'Sets display to system default',
|
|
||||||
}
|
|
||||||
const modeHelpText = {
|
|
||||||
light: 'Light Theme',
|
|
||||||
dark: 'Dark Theme',
|
|
||||||
system: 'System Default Theme',
|
|
||||||
}
|
|
||||||
|
|
||||||
const nextColorMode = () => {
|
|
||||||
return colorModes[
|
|
||||||
(colorModes.indexOf(store.shell.colorMode) + 1) % colorModes.length
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
const onModePress = React.useCallback(() => {
|
|
||||||
store.shell.setColorMode(nextColorMode())
|
|
||||||
}, [store])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={[styles.rightNav, pal.view]}>
|
<View style={[styles.rightNav, pal.view]}>
|
||||||
|
@ -76,19 +53,31 @@ export const DesktopRightNav = observer(function DesktopRightNav() {
|
||||||
</View>
|
</View>
|
||||||
<InviteCodes />
|
<InviteCodes />
|
||||||
<View>
|
<View>
|
||||||
<TouchableOpacity
|
<Text type="sm" style={[pal.textLight, styles.colorModeText]}>
|
||||||
style={[styles.cycleColorModeToggle]}
|
Set color theme
|
||||||
onPress={onModePress}
|
</Text>
|
||||||
accessibilityRole="button"
|
<View style={styles.selectableBtns}>
|
||||||
accessibilityLabel="Cycle color mode"
|
<SelectableBtn
|
||||||
accessibilityHint={modeAccessibilityText[nextColorMode()]}>
|
current={store.shell.colorMode}
|
||||||
<View style={[pal.viewLight, styles.cycleColorModeToggleIcon]}>
|
value="system"
|
||||||
<MoonIcon size={18} style={pal.textLight} />
|
label="System"
|
||||||
</View>
|
left
|
||||||
<Text type="sm" style={pal.textLight}>
|
onChange={(v: string) => store.shell.setColorMode(v)}
|
||||||
{modeHelpText[store.shell.colorMode]}
|
/>
|
||||||
</Text>
|
<SelectableBtn
|
||||||
</TouchableOpacity>
|
current={store.shell.colorMode}
|
||||||
|
value="light"
|
||||||
|
label="Light"
|
||||||
|
onChange={(v: string) => store.shell.setColorMode(v)}
|
||||||
|
/>
|
||||||
|
<SelectableBtn
|
||||||
|
current={store.shell.colorMode}
|
||||||
|
value="dark"
|
||||||
|
label="Dark"
|
||||||
|
right
|
||||||
|
onChange={(v: string) => store.shell.setColorMode(v)}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
|
@ -132,6 +121,45 @@ const InviteCodes = observer(() => {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
interface SelectableBtnProps {
|
||||||
|
current: string
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
left?: boolean
|
||||||
|
right?: boolean
|
||||||
|
onChange: (v: string) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
function SelectableBtn({
|
||||||
|
current,
|
||||||
|
value,
|
||||||
|
label,
|
||||||
|
left,
|
||||||
|
right,
|
||||||
|
onChange,
|
||||||
|
}: SelectableBtnProps) {
|
||||||
|
const pal = usePalette('default')
|
||||||
|
const palPrimary = usePalette('inverted')
|
||||||
|
return (
|
||||||
|
<Pressable
|
||||||
|
style={[
|
||||||
|
styles.selectableBtn,
|
||||||
|
left && styles.selectableBtnLeft,
|
||||||
|
right && styles.selectableBtnRight,
|
||||||
|
pal.border,
|
||||||
|
current === value ? palPrimary.view : pal.view,
|
||||||
|
]}
|
||||||
|
onPress={() => onChange(value)}
|
||||||
|
accessibilityRole="button"
|
||||||
|
accessibilityLabel={value}
|
||||||
|
accessibilityHint={`Set color theme to ${value}`}>
|
||||||
|
<Text style={current === value ? palPrimary.text : pal.text}>
|
||||||
|
{label}
|
||||||
|
</Text>
|
||||||
|
</Pressable>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
rightNav: {
|
rightNav: {
|
||||||
position: 'absolute',
|
position: 'absolute',
|
||||||
|
@ -174,4 +202,44 @@ const styles = StyleSheet.create({
|
||||||
height: 26,
|
height: 26,
|
||||||
borderRadius: 15,
|
borderRadius: 15,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
colorModeText: {
|
||||||
|
marginLeft: 10,
|
||||||
|
marginBottom: 6,
|
||||||
|
},
|
||||||
|
|
||||||
|
selectableBtns: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
marginLeft: 10,
|
||||||
|
},
|
||||||
|
selectableBtn: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
justifyContent: 'center',
|
||||||
|
borderWidth: 1,
|
||||||
|
borderLeftWidth: 0,
|
||||||
|
paddingHorizontal: 10,
|
||||||
|
paddingVertical: 10,
|
||||||
|
},
|
||||||
|
selectableBtnLeft: {
|
||||||
|
borderTopLeftRadius: 8,
|
||||||
|
borderBottomLeftRadius: 8,
|
||||||
|
borderLeftWidth: 1,
|
||||||
|
},
|
||||||
|
selectableBtnRight: {
|
||||||
|
borderTopRightRadius: 8,
|
||||||
|
borderBottomRightRadius: 8,
|
||||||
|
},
|
||||||
|
|
||||||
|
btn: {
|
||||||
|
flexDirection: 'row',
|
||||||
|
alignItems: 'center',
|
||||||
|
justifyContent: 'center',
|
||||||
|
width: '100%',
|
||||||
|
borderRadius: 32,
|
||||||
|
padding: 14,
|
||||||
|
backgroundColor: colors.gray1,
|
||||||
|
},
|
||||||
|
toggleBtn: {
|
||||||
|
paddingHorizontal: 0,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue