Skip to content

Commit 6affbd4

Browse files
committed
styles: Move styles for ComposeBox to component file.
These are used in just this one place, and they're closely bound up with the sub-component tree in the `render` method. Move them there to make both the styles and the `render` code easier to understand and to modify.
1 parent ec24d40 commit 6affbd4

File tree

2 files changed

+39
-43
lines changed

2 files changed

+39
-43
lines changed

src/compose/ComposeBox.js

+39-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow strict-local */
22
import React, { PureComponent } from 'react';
3-
import { View, TextInput, findNodeHandle } from 'react-native';
3+
import { Platform, View, TextInput, findNodeHandle } from 'react-native';
44
import { connect } from 'react-redux';
55
import TextInputReset from 'react-native-text-input-reset';
66

@@ -251,10 +251,43 @@ class ComposeBox extends PureComponent<Props, State> {
251251
}
252252
}
253253

254+
inputMarginPadding = {
255+
paddingHorizontal: 8,
256+
paddingVertical: Platform.select({
257+
ios: 8,
258+
android: 2,
259+
}),
260+
};
261+
254262
styles = {
255-
topicInput: [styles.topicInput, this.context.styles.backgroundColor],
263+
composeBox: {
264+
flexDirection: 'row',
265+
backgroundColor: 'rgba(127, 127, 127, 0.1)',
266+
},
267+
composeText: {
268+
flex: 1,
269+
paddingVertical: 8,
270+
justifyContent: 'center',
271+
},
272+
composeSendButton: {
273+
padding: 8,
274+
},
275+
topicInput: [
276+
{
277+
borderWidth: 0,
278+
borderRadius: 5,
279+
marginBottom: 8,
280+
...this.inputMarginPadding,
281+
},
282+
this.context.styles.backgroundColor,
283+
],
256284
composeTextInput: [
257-
styles.composeTextInput,
285+
{
286+
borderWidth: 0,
287+
borderRadius: 5,
288+
fontSize: 15,
289+
...this.inputMarginPadding,
290+
},
258291
this.context.styles.backgroundColor,
259292
this.context.styles.color,
260293
],
@@ -298,15 +331,15 @@ class ComposeBox extends PureComponent<Props, State> {
298331
onMessageAutocomplete={this.handleMessageAutocomplete}
299332
onTopicAutocomplete={this.handleTopicAutocomplete}
300333
/>
301-
<View style={styles.composeBox} onLayout={this.handleLayoutChange}>
334+
<View style={this.styles.composeBox} onLayout={this.handleLayoutChange}>
302335
<View style={styles.alignBottom}>
303336
<ComposeMenu
304337
destinationNarrow={this.getDestinationNarrow()}
305338
expanded={isMenuExpanded}
306339
onExpandContract={this.handleComposeMenuToggle}
307340
/>
308341
</View>
309-
<View style={styles.composeText}>
342+
<View style={this.styles.composeText}>
310343
{this.getCanSelectTopic() && (
311344
<Input
312345
style={this.styles.topicInput}
@@ -341,7 +374,7 @@ class ComposeBox extends PureComponent<Props, State> {
341374
</View>
342375
<View style={styles.alignBottom}>
343376
<FloatingActionButton
344-
style={styles.composeSendButton}
377+
style={this.styles.composeSendButton}
345378
Icon={editMessage === null ? IconSend : IconDone}
346379
size={32}
347380
disabled={message.trim().length === 0}

src/styles/composeBoxStyles.js

-37
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,8 @@
11
/* @flow strict-local */
2-
import { Platform } from 'react-native';
32

43
import { BRAND_COLOR } from './constants';
54

6-
const inputMarginPadding = {
7-
paddingHorizontal: 8,
8-
...Platform.select({
9-
ios: {
10-
paddingVertical: 8,
11-
},
12-
android: {
13-
paddingVertical: 2,
14-
},
15-
}),
16-
};
17-
185
export default {
19-
composeBox: {
20-
flexDirection: 'row',
21-
backgroundColor: 'rgba(127, 127, 127, 0.1)',
22-
},
23-
composeText: {
24-
flex: 1,
25-
paddingVertical: 8,
26-
justifyContent: 'center',
27-
},
28-
composeSendButton: {
29-
padding: 8,
30-
},
316
composeMenu: {
327
flexDirection: 'row',
338
overflow: 'hidden',
@@ -56,16 +31,4 @@ export default {
5631
flex: 1,
5732
color: 'white',
5833
},
59-
composeTextInput: {
60-
borderWidth: 0,
61-
borderRadius: 5,
62-
fontSize: 15,
63-
...inputMarginPadding,
64-
},
65-
topicInput: {
66-
borderWidth: 0,
67-
borderRadius: 5,
68-
marginBottom: 8,
69-
...inputMarginPadding,
70-
},
7134
};

0 commit comments

Comments
 (0)