Skip to content

Commit 2915169

Browse files
theme: add ThemeSetting type and calc ThemeName in MessageList
In addition to the ThemeName type, this adds a ThemeSetting type that matches the setting from the SettingsScreen. In order to make the MessageList correctly follow the ThemeSetting, we compute a ThemeName in MessageList based off of the ThemeSetting and the current OS theme. Fixes #4009.
1 parent 51bc424 commit 2915169

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

src/reduxTypes.js

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff 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?

src/webview/MessageList.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import * as React from 'react';
33
import { Platform, NativeModules } from 'react-native';
44
import { WebView } from 'react-native-webview';
5+
import { getColorScheme } from 'react-native/Libraries/Utilities/Appearance';
56

67
import { connectActionSheet } from '../react-native-action-sheet';
78
import 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,

src/webview/backgroundData.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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,

0 commit comments

Comments
 (0)