Skip to content

Commit 774b491

Browse files
theme: MessageList get theme data from context instead of props
Change the way `MessageList` updates its theme. It now gets its ThemeData information from the `ThemeContext` instead of its props.
1 parent 3980dca commit 774b491

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/styles/theme.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Context } from 'react';
55
import type { ThemeName } from '../reduxTypes';
66

77
export type ThemeData = {|
8+
themeName: ThemeName,
89
color: string,
910
backgroundColor: string,
1011
cardColor: string,
@@ -13,6 +14,7 @@ export type ThemeData = {|
1314

1415
export const themeData: {| [name: ThemeName | 'light']: ThemeData |} = {
1516
night: {
17+
themeName: 'night',
1618
color: 'hsl(210, 11%, 85%)',
1719
backgroundColor: 'hsl(212, 28%, 18%)',
1820
cardColor: 'hsl(212, 31%, 21%)',
@@ -21,6 +23,7 @@ export const themeData: {| [name: ThemeName | 'light']: ThemeData |} = {
2123
dividerColor: 'hsla(0, 0%, 100%, 0.12)',
2224
},
2325
light: {
26+
themeName: 'default',
2427
color: 'hsl(0, 0%, 20%)',
2528
backgroundColor: 'white',
2629
cardColor: 'hsl(0, 0%, 97%)',

src/webview/MessageList.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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';
65

76
import { connectActionSheet } from '../react-native-action-sheet';
87
import type {
@@ -17,6 +16,8 @@ import type {
1716
EditMessage,
1817
} from '../types';
1918
import { assumeSecretlyGlobalState } from '../reduxTypes';
19+
import type { ThemeData } from '../styles';
20+
import { ThemeContext } from '../styles';
2021
import { connect } from '../react-redux';
2122
import {
2223
getCurrentTypingUsers,
@@ -38,7 +39,6 @@ import { caseNarrow, isConversationNarrow } from '../utils/narrow';
3839
import { type BackgroundData, getBackgroundData } from './backgroundData';
3940
import { ensureUnreachable } from '../generics';
4041
import { renderSinglePageWebView } from './SinglePageWebView';
41-
import { getThemeToUse } from '../settings/settingsSelectors';
4242

4343
type OuterProps = $ReadOnly<{|
4444
narrow: Narrow,
@@ -125,6 +125,9 @@ const webviewAssetsUrl = new URL('webview/', assetsUrl);
125125
const baseUrl = new URL('index.html', webviewAssetsUrl);
126126

127127
class MessageListInner extends React.Component<Props> {
128+
static contextType = ThemeContext;
129+
context: ThemeData;
130+
128131
webviewRef = React.createRef<React$ElementRef<typeof WebView>>();
129132
sendInboundEventsIsReady: boolean;
130133
unsentInboundEvents: WebViewInboundEvent[] = [];
@@ -178,12 +181,10 @@ class MessageListInner extends React.Component<Props> {
178181
const contentHtml = messageListElementsForShownMessages
179182
.map(element => messageListElementHtml({ backgroundData, element, _ }))
180183
.join('');
181-
const { auth, theme } = backgroundData;
182-
const osScheme = getColorScheme();
183-
const themeToUse = getThemeToUse(theme, osScheme);
184+
const { auth } = backgroundData;
184185
const html: string = getHtml(
185186
contentHtml,
186-
themeToUse,
187+
this.context.themeName,
187188
{
188189
scrollMessageId: initialScrollMessageId,
189190
auth,

0 commit comments

Comments
 (0)