Skip to content

Commit 88d427c

Browse files
Chris Bobbechrisbobbe
Chris Bobbe
authored andcommitted
theme: Remove remaining consumers of legacy Context for styles.
Continuing the work of recent commits toward zulip#1946. These last few consumers are simply using `background` or `backgroundColor` from the old style context, and no theme-independent styles, so, fix them together in one commit. Then, to help verify that all consumers are removed: Atomically, in this commit, remove the default-exported function of `miscStyles`, and its only call site, at `stylesFromTheme`. `stylesFromTheme` is the single point where all the data is collected and distributed as `styles` via the legacy Context API. (A similar removal, for `navStyles`, is bfdde6f.)
1 parent 550d19a commit 88d427c

File tree

7 files changed

+34
-62
lines changed

7 files changed

+34
-62
lines changed

src/common/Popup.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import React, { PureComponent } from 'react';
33
import type { Node as React$Node } from 'react';
44
import { View, StyleSheet } from 'react-native';
55

6-
import type { Context } from '../types';
6+
import type { ThemeColors } from '../styles';
7+
import { ThemeContext } from '../styles';
78

89
const styles = StyleSheet.create({
910
popup: {
@@ -22,15 +23,14 @@ type Props = $ReadOnly<{|
2223
|}>;
2324

2425
export default class Popup extends PureComponent<Props> {
25-
context: Context;
26-
27-
static contextTypes = {
28-
styles: () => null,
29-
};
26+
static contextType = ThemeContext;
27+
context: ThemeColors;
3028

3129
render() {
3230
return (
33-
<View style={[this.context.styles.backgroundColor, styles.popup]}>{this.props.children}</View>
31+
<View style={[{ backgroundColor: this.context.backgroundColor }, styles.popup]}>
32+
{this.props.children}
33+
</View>
3434
);
3535
}
3636
}

src/common/SectionHeader.js

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import React, { PureComponent } from 'react';
33
import { StyleSheet, View } from 'react-native';
44

5-
import type { Context } from '../types';
5+
import type { ThemeColors } from '../styles';
6+
import { ThemeContext } from '../styles';
67
import Label from './Label';
78

89
const styles = StyleSheet.create({
@@ -17,16 +18,13 @@ type Props = $ReadOnly<{|
1718
|}>;
1819

1920
export default class SectionHeader extends PureComponent<Props> {
20-
context: Context;
21-
22-
static contextTypes = {
23-
styles: () => null,
24-
};
21+
static contextType = ThemeContext;
22+
context: ThemeColors;
2523

2624
render() {
2725
const { text } = this.props;
2826
return (
29-
<View style={[styles.header, this.context.styles.backgroundColor]}>
27+
<View style={[styles.header, { backgroundColor: this.context.backgroundColor }]}>
3028
<Label text={text} />
3129
</View>
3230
);

src/compose/ComposeBox.js

+9-10
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ import { Platform, View, TextInput, findNodeHandle } from 'react-native';
44
import type { LayoutEvent } from 'react-native/Libraries/Types/CoreEventTypes';
55
import TextInputReset from 'react-native-text-input-reset';
66

7+
import type { ThemeColors } from '../styles';
8+
import { ThemeContext } from '../styles';
79
import type {
810
Auth,
9-
Context,
1011
Narrow,
1112
EditMessage,
1213
InputSelection,
@@ -102,17 +103,14 @@ export const updateTextInput = (textInput: ?TextInput, text: string): void => {
102103
};
103104

104105
class ComposeBox extends PureComponent<Props, State> {
105-
context: Context;
106+
static contextType = ThemeContext;
107+
context: ThemeColors;
106108

107109
messageInput: ?TextInput = null;
108110
topicInput: ?TextInput = null;
109111

110112
inputBlurTimeoutId: ?TimeoutID = null;
111113

112-
static contextTypes = {
113-
styles: () => null,
114-
};
115-
116114
state = {
117115
isMessageFocused: false,
118116
isTopicFocused: false,
@@ -322,15 +320,13 @@ class ComposeBox extends PureComponent<Props, State> {
322320
borderRadius: 5,
323321
marginBottom: 8,
324322
...this.inputMarginPadding,
325-
...this.context.styles.backgroundColor,
326323
},
327324
composeTextInput: {
328325
borderWidth: 0,
329326
borderRadius: 5,
330327
fontSize: 15,
331328
flexShrink: 1,
332329
...this.inputMarginPadding,
333-
...this.context.styles.backgroundColor,
334330
},
335331
};
336332

@@ -384,7 +380,7 @@ class ComposeBox extends PureComponent<Props, State> {
384380
<View style={this.styles.composeText}>
385381
{this.getCanSelectTopic() && (
386382
<Input
387-
style={this.styles.topicInput}
383+
style={[this.styles.topicInput, { backgroundColor: this.context.backgroundColor }]}
388384
underlineColorAndroid="transparent"
389385
placeholder="Topic"
390386
defaultValue={topic}
@@ -400,7 +396,10 @@ class ComposeBox extends PureComponent<Props, State> {
400396
)}
401397
<Input
402398
multiline={!isMenuExpanded}
403-
style={this.styles.composeTextInput}
399+
style={[
400+
this.styles.composeTextInput,
401+
{ backgroundColor: this.context.backgroundColor },
402+
]}
404403
underlineColorAndroid="transparent"
405404
placeholder={placeholder}
406405
defaultValue={message}

src/main/MainScreenWithTabs.js

+5-10
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,18 @@
22
import React, { PureComponent } from 'react';
33
import { View } from 'react-native';
44

5-
import type { Context } from '../types';
5+
import type { ThemeColors } from '../styles';
6+
import styles, { ThemeContext } from '../styles';
67
import { OfflineNotice, ZulipStatusBar } from '../common';
78
import MainTabs from './MainTabs';
8-
import styles from '../styles';
99

1010
export default class MainScreenWithTabs extends PureComponent<{||}> {
11-
context: Context;
12-
13-
static contextTypes = {
14-
styles: () => null,
15-
};
11+
static contextType = ThemeContext;
12+
context: ThemeColors;
1613

1714
render() {
18-
const { styles: contextStyles } = this.context;
19-
2015
return (
21-
<View style={[styles.flexed, contextStyles.backgroundColor]}>
16+
<View style={[styles.flexed, { backgroundColor: this.context.backgroundColor }]}>
2217
<ZulipStatusBar />
2318
<OfflineNotice />
2419
<MainTabs />

src/pm-conversations/PmConversationsCard.js

+6-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
import React, { PureComponent } from 'react';
44
import { View, StyleSheet } from 'react-native';
55

6-
import type { Context, Dispatch, PmConversationData, UserOrBot } from '../types';
6+
import type { ThemeColors } from '../styles';
7+
import { ThemeContext } from '../styles';
8+
import type { Dispatch, PmConversationData, UserOrBot } from '../types';
79
import { connect } from '../react-redux';
810
import { Label, ZulipButton, LoadingBanner } from '../common';
911
import { IconPeople, IconSearch } from '../common/Icons';
@@ -40,18 +42,14 @@ type Props = $ReadOnly<{|
4042
* The "PMs" page in the main tabs navigation.
4143
* */
4244
class PmConversationsCard extends PureComponent<Props> {
43-
context: Context;
44-
45-
static contextTypes = {
46-
styles: () => null,
47-
};
45+
static contextType = ThemeContext;
46+
context: ThemeColors;
4847

4948
render() {
50-
const { styles: contextStyles } = this.context;
5149
const { dispatch, conversations, usersByEmail } = this.props;
5250

5351
return (
54-
<View style={[styles.container, contextStyles.background]}>
52+
<View style={[styles.container, { backgroundColor: this.context.backgroundColor }]}>
5553
<View style={styles.row}>
5654
<ZulipButton
5755
secondary

src/styles/miscStyles.js

-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
/* @flow strict-local */
2-
import type { ThemeColors } from './theme';
32
import { CONTROL_SIZE } from './constants';
43

54
export const statics = {
@@ -54,12 +53,3 @@ export const statics = {
5453
justifyContent: 'flex-end',
5554
},
5655
};
57-
58-
export default ({ color, backgroundColor }: ThemeColors) => ({
59-
backgroundColor: {
60-
backgroundColor,
61-
},
62-
background: {
63-
backgroundColor,
64-
},
65-
});

src/styles/theme.js

+2-10
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import type { Context } from 'react';
44
import { StyleSheet } from 'react-native';
55

66
import type { ThemeName } from '../types';
7-
import miscStyles from './miscStyles';
87

98
export type ThemeColors = {|
109
color: string,
@@ -13,9 +12,7 @@ export type ThemeColors = {|
1312
dividerColor: string,
1413
|};
1514

16-
export type AppStyles = $ReadOnly<{|
17-
...$Call<typeof miscStyles, ThemeColors>,
18-
|}>;
15+
export type AppStyles = $ReadOnly<{||}>;
1916

2017
export const themeColors: { [string]: ThemeColors } = {
2118
night: {
@@ -39,9 +36,4 @@ themeColors.default = themeColors.light;
3936

4037
export const ThemeContext: Context<ThemeColors> = React.createContext(themeColors.default);
4138

42-
export const stylesFromTheme = (name: ThemeName) => {
43-
const colors = themeColors[name];
44-
return StyleSheet.create({
45-
...miscStyles(colors),
46-
});
47-
};
39+
export const stylesFromTheme = (name: ThemeName) => StyleSheet.create({});

0 commit comments

Comments
 (0)