Skip to content

Commit 65cad6f

Browse files
author
Chris Bobbe
committed
ChatScreen: Switch to new React Context API for theme colors.
Per zulip#1946, we're moving to the new React Context API (https://reactjs.org/docs/context.html). Use exactly the same strategy as we did for Screen, in the parent.
1 parent a593480 commit 65cad6f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

src/chat/ChatScreen.js

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,17 @@ import type { NavigationScreenProp } from 'react-navigation';
55
import { ActionSheetProvider } from '@expo/react-native-action-sheet';
66

77
import { connect } from '../react-redux';
8-
import type { Context, Dispatch, Fetching, Narrow } from '../types';
8+
import type { ThemeColors } from '../styles';
9+
import styles, { ThemeContext } from '../styles';
10+
import type { Dispatch, Fetching, Narrow } from '../types';
911
import { KeyboardAvoider, OfflineNotice, ZulipStatusBar } from '../common';
1012
import ChatNavBar from '../nav/ChatNavBar';
1113

1214
import MessageList from '../webview/MessageList';
1315
import NoMessages from '../message/NoMessages';
1416
import ComposeBox from '../compose/ComposeBox';
1517
import UnreadNotice from './UnreadNotice';
16-
import styles from '../styles';
18+
1719
import { canSendToNarrow } from '../utils/narrow';
1820
import { getLoading } from '../directSelectors';
1921
import { getFetchingForNarrow } from './fetchingSelectors';
@@ -33,6 +35,10 @@ type Props = $ReadOnly<{|
3335
|}>;
3436

3537
const componentStyles = StyleSheet.create({
38+
screen: {
39+
flex: 1,
40+
flexDirection: 'column',
41+
},
3642
/** A workaround for #3089, by letting us put MessageList first. */
3743
reverse: {
3844
flex: 1,
@@ -41,14 +47,10 @@ const componentStyles = StyleSheet.create({
4147
});
4248

4349
class ChatScreen extends PureComponent<Props> {
44-
context: Context;
45-
46-
static contextTypes = {
47-
styles: () => null,
48-
};
50+
static contextType = ThemeContext;
51+
context: ThemeColors;
4952

5053
render() {
51-
const { styles: contextStyles } = this.context;
5254
const { fetching, haveNoMessages, loading, navigation } = this.props;
5355
const { narrow } = navigation.state.params;
5456

@@ -59,7 +61,13 @@ class ChatScreen extends PureComponent<Props> {
5961

6062
return (
6163
<ActionSheetProvider>
62-
<View style={[contextStyles.screen, componentStyles.reverse]}>
64+
<View
65+
style={[
66+
componentStyles.screen,
67+
{ backgroundColor: this.context.backgroundColor },
68+
componentStyles.reverse,
69+
]}
70+
>
6371
<KeyboardAvoider style={styles.flexed} behavior="padding">
6472
<UnreadNotice narrow={narrow} />
6573
{sayNoMessages ? (

0 commit comments

Comments
 (0)