Skip to content

Commit ec18f0f

Browse files
author
Chris Bobbe
committed
MessageList: Switch to new React Context API, remove miscStyles.webview.
Per zulip#1946, we're moving to the new React Context API (https://reactjs.org/docs/context.html). We’re also isolating the theme colors in its own context type. So, components that consume the theme colors can and should use `static contextType = ThemeContext;` and, e.g., this.context.backgroundColor, instead of this.context.styles.backgroundColor, as was done before. This change also eliminates the need for miscStyles.webview, which was included in this.context.styles that MessageList was using, so, remove that.
1 parent ad8adff commit ec18f0f

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

src/styles/miscStyles.js

-4
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,4 @@ export default ({ color, backgroundColor }: ThemeColors) => ({
8888
// alignItems: 'stretch',
8989
backgroundColor,
9090
},
91-
webview: {
92-
borderWidth: 0,
93-
backgroundColor,
94-
},
9591
});

src/webview/MessageList.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { connectActionSheet } from '@expo/react-native-action-sheet';
99
import type {
1010
AlertWordsState,
1111
Auth,
12-
Context,
1312
Debug,
1413
Dispatch,
1514
Fetching,
@@ -25,6 +24,10 @@ import type {
2524
ThemeName,
2625
User,
2726
} from '../types';
27+
28+
import type { ThemeColors } from '../styles';
29+
import { ThemeContext } from '../styles';
30+
2831
import { connect } from '../react-redux';
2932
import {
3033
getAuth,
@@ -137,15 +140,12 @@ const assetsPath = Platform.OS === 'ios' ? './webview' : 'file:///android_asset/
137140
// [3] https://github.com/facebook/react-native/blob/0.59-stable/React/Base/RCTConvert.m#L85
138141

139142
class MessageList extends Component<Props> {
140-
context: Context;
143+
context: ThemeColors;
141144
webview: ?WebView;
142145
sendUpdateEventsIsReady: boolean;
143146
unsentUpdateEvents: WebViewUpdateEvent[] = [];
144147

145-
static contextTypes = {
146-
styles: () => null,
147-
theme: () => null,
148-
};
148+
static contextType = ThemeContext;
149149

150150
componentDidMount() {
151151
this.setupSendUpdateEvents();
@@ -209,7 +209,6 @@ class MessageList extends Component<Props> {
209209
};
210210

211211
render() {
212-
const { styles: contextStyles } = this.context;
213212
const {
214213
backgroundData,
215214
renderedMessages,
@@ -304,7 +303,8 @@ class MessageList extends Component<Props> {
304303
source={{ baseUrl, html }}
305304
originWhitelist={['file://']}
306305
onShouldStartLoadWithRequest={onShouldStartLoadWithRequest}
307-
style={contextStyles.webview}
306+
/* eslint-disable react-native/no-inline-styles */
307+
style={{ backgroundColor: this.context.backgroundColor, borderWidth: 0 }}
308308
ref={webview => {
309309
this.webview = webview;
310310
}}

0 commit comments

Comments
 (0)