File tree Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Expand file tree Collapse file tree 3 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -349,11 +349,26 @@ export type RealmState = {|
349349/**
350350 * The theme of the app.
351351 *
352- * * auto: follow the OS theme setting
353352 * * light
354353 * * dark
354+ *
355+ * To get a ThemeName from the ThemeSetting, first check the current
356+ * OS theme by calling the React Native hook useColorScheme and pass
357+ * that to the helper function getThemeToUse.
358+ *
359+ */
360+ export type ThemeName = 'light' | 'dark' ;
361+
362+ /**
363+ * The theme setting.
364+ *
365+ * * ThemeName: either 'light' or 'dark'
366+ * * auto: follow the OS theme setting
367+ *
368+ * This value matches what is set in the SettingsScreen.
369+ *
355370 */
356- export type ThemeName = 'auto' | 'light' | 'dark ';
371+ export type ThemeSetting = ThemeName | 'auto ' ;
357372
358373/** What browser the user has set to use for opening links in messages.
359374 *
@@ -394,7 +409,7 @@ export type GlobalSettingsState = $ReadOnly<{
394409 // The user's chosen language, as an IETF BCP 47 language tag.
395410 language : string ,
396411
397- theme : ThemeName ,
412+ theme : ThemeSetting ,
398413 browser : BrowserPreference ,
399414
400415 // TODO cut this? what was it?
Original file line number Diff line number Diff line change 22import * as React from 'react' ;
33import { Platform , NativeModules } from 'react-native' ;
44import { WebView } from 'react-native-webview' ;
5+ import { getColorScheme } from 'react-native/Libraries/Utilities/Appearance' ;
56
67import { connectActionSheet } from '../react-native-action-sheet' ;
78import type {
@@ -177,9 +178,15 @@ class MessageListInner extends React.Component<Props> {
177178 . map ( element => messageListElementHtml ( { backgroundData, element, _ } ) )
178179 . join ( '' ) ;
179180 const { auth , theme } = backgroundData ;
181+ const osScheme = getColorScheme ( ) ;
182+ let themeToUse = theme ;
183+ if ( themeToUse === 'auto' ) {
184+ themeToUse = osScheme === 'light' || osScheme == null ? 'light' : 'dark' ;
185+ }
186+
180187 const html : string = getHtml (
181188 contentHtml ,
182- theme ,
189+ themeToUse ,
183190 {
184191 scrollMessageId : initialScrollMessageId ,
185192 auth,
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ import type {
1212 PerAccountState ,
1313 Subscription ,
1414 Stream ,
15- ThemeName ,
15+ ThemeSetting ,
1616 UserId ,
1717 User ,
1818 UserOrBot ,
@@ -63,7 +63,7 @@ export type BackgroundData = $ReadOnly<{|
6363 streams : Map < number , Stream> ,
6464 subscriptions : Map < number , Subscription> ,
6565 unread : UnreadState ,
66- theme : ThemeName ,
66+ theme : ThemeSetting ,
6767 twentyFourHourTime : boolean ,
6868 userSettingStreamNotification : boolean ,
6969 displayEmojiReactionUsers : boolean ,
You can’t perform that action at this time.
0 commit comments