Skip to content

Commit e80677d

Browse files
authored
fix ios dark changes (keybase#24981)
1 parent d249118 commit e80677d

21 files changed

Lines changed: 283 additions & 191 deletions

‎shared/actions/config-gen.tsx‎

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎shared/actions/config/index.tsx‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,8 +477,6 @@ const loadDarkPrefs = async () => {
477477
const preference = v.s || undefined
478478

479479
switch (preference) {
480-
case undefined:
481-
return ConfigGen.createSetDarkModePreference({preference})
482480
case 'system':
483481
return ConfigGen.createSetDarkModePreference({preference})
484482
case 'alwaysDark':

‎shared/actions/json/config.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
"isInit?": "boolean"
136136
},
137137
"setDarkModePreference": {
138-
"preference": ["'system'", "'alwaysDark'", "'alwaysLight'", "undefined"]
138+
"preference": ["'system'", "'alwaysDark'", "'alwaysLight'"]
139139
},
140140
"setSystemDarkMode": {"dark": "boolean"},
141141
"updateHTTPSrvInfo": {

‎shared/app/index.native.tsx‎

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {Provider, useDispatch} from 'react-redux'
1010
import {SafeAreaProvider} from 'react-native-safe-area-context'
1111
import {makeEngine} from '../engine'
1212
import {GestureHandlerRootView} from 'react-native-gesture-handler'
13-
import debounce from 'lodash/debounce'
1413

1514
type ConfigureStore = ReturnType<typeof configureStore>
1615
let _hotCS: ConfigureStore | undefined
@@ -21,21 +20,26 @@ module.hot?.accept(() => {
2120

2221
const NativeEventsToRedux = () => {
2322
const dispatch = useDispatch()
23+
const appStateRef = React.useRef('unknown')
2424

2525
React.useEffect(() => {
2626
const appStateChangeSub = AppState.addEventListener('change', nextAppState => {
27+
appStateRef.current = nextAppState
2728
nextAppState !== 'unknown' &&
2829
nextAppState !== 'extension' &&
2930
dispatch(ConfigGen.createMobileAppState({nextAppState}))
30-
})
3131

32-
// must be debounced due to ios calling this multiple times for snapshots
33-
const darkSub = Appearance.addChangeListener(
34-
debounce(() => {
32+
if (nextAppState === 'active') {
3533
dispatch(ConfigGen.createSetSystemDarkMode({dark: Appearance.getColorScheme() === 'dark'}))
36-
}, 100)
37-
)
34+
}
35+
})
3836

37+
// only watch dark changes if in foreground due to ios calling this to take snapshots
38+
const darkSub = Appearance.addChangeListener(() => {
39+
if (appStateRef.current === 'active') {
40+
dispatch(ConfigGen.createSetSystemDarkMode({dark: Appearance.getColorScheme() === 'dark'}))
41+
}
42+
})
3943
const linkingSub = Linking.addEventListener('url', ({url}: {url: string}) => {
4044
dispatch(DeeplinksGen.createLink({link: url}))
4145
})

‎shared/common-adapters/radio-button.native.tsx‎

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react'
22
import ClickableBox from './clickable-box'
33
import Text from './text'
44
import * as Styles from '../styles'
5-
import {Props} from './radio-button'
5+
import type {Props} from './radio-button'
66

77
const Kb = {
88
ClickableBox,
@@ -12,43 +12,35 @@ const Kb = {
1212
export const RADIOBUTTON_SIZE = 22
1313
export const RADIOBUTTON_MARGIN = 8
1414

15-
type ExtraProps = {disabled?: boolean; selected: boolean}
16-
const RadioOuterCircle = Styles.styled(ClickableBox)(
17-
{
18-
backgroundColor: Styles.globalColors.white,
19-
borderRadius: 100,
20-
borderWidth: 1,
21-
height: RADIOBUTTON_SIZE,
22-
marginRight: RADIOBUTTON_MARGIN,
23-
position: 'relative' as const,
24-
width: RADIOBUTTON_SIZE,
25-
},
26-
({disabled, selected}: ExtraProps) => ({
27-
borderColor: selected ? Styles.globalColors.blue : Styles.globalColors.black_20,
28-
opacity: disabled ? 0.4 : 1,
29-
})
15+
const RadioOuterCircle = (p: {disabled: boolean; selected: boolean; children: React.ReactNode}) => (
16+
<Kb.ClickableBox
17+
style={Styles.collapseStyles([
18+
styles.outer,
19+
{
20+
borderColor: p.selected ? Styles.globalColors.blue : Styles.globalColors.black_20,
21+
opacity: p.disabled ? 0.4 : 1,
22+
},
23+
])}
24+
>
25+
{p.children}
26+
</Kb.ClickableBox>
3027
)
3128

32-
const RadioInnerCircle = Styles.styled(ClickableBox)(
33-
{
34-
borderColor: Styles.globalColors.white,
35-
borderRadius: 10,
36-
borderWidth: 5,
37-
left: 5,
38-
position: 'absolute',
39-
top: 5,
40-
},
41-
({selected}: ExtraProps) => ({
42-
borderColor: selected ? Styles.globalColors.blue : Styles.globalColors.white,
43-
})
29+
const RadioInnerCircle = (p: {selected: boolean}) => (
30+
<Kb.ClickableBox
31+
style={Styles.collapseStyles([
32+
styles.inner,
33+
{borderColor: p.selected ? Styles.globalColors.blue : Styles.globalColors.white},
34+
])}
35+
/>
4436
)
4537

4638
const RadioButton = ({disabled, label, onSelect, selected, style}: Props) => (
4739
<Kb.ClickableBox
4840
style={{...styles.container, ...style}}
4941
onClick={disabled ? undefined : () => onSelect(!selected)}
5042
>
51-
<RadioOuterCircle disabled={disabled} selected={selected}>
43+
<RadioOuterCircle disabled={disabled ?? false} selected={selected}>
5244
<RadioInnerCircle selected={selected} />
5345
</RadioOuterCircle>
5446
{typeof label === 'string' ? (
@@ -70,6 +62,23 @@ const styles = Styles.styleSheetCreate(
7062
paddingBottom: Styles.globalMargins.xtiny,
7163
paddingTop: Styles.globalMargins.xtiny,
7264
},
65+
inner: {
66+
borderColor: Styles.globalColors.white,
67+
borderRadius: 10,
68+
borderWidth: 5,
69+
left: 5,
70+
position: 'absolute',
71+
top: 5,
72+
},
73+
outer: {
74+
backgroundColor: Styles.globalColors.white,
75+
borderRadius: 100,
76+
borderWidth: 1,
77+
height: RADIOBUTTON_SIZE,
78+
marginRight: RADIOBUTTON_MARGIN,
79+
position: 'relative' as const,
80+
width: RADIOBUTTON_SIZE,
81+
},
7382
} as const)
7483
)
7584

0 commit comments

Comments
 (0)