Skip to content

Commit 0eef067

Browse files
ArjunHoussein Djirdeh
authored andcommitted
refactor(ui): Migrate search screen to styled components (#710)
* refactor(ui): Migrate to styled components migrate search screen to styled components fix #532 * refactor: remove unnecessary enclosing View tag * fix(*): fix lint
1 parent 600f179 commit 0eef067

File tree

2 files changed

+81
-116
lines changed

2 files changed

+81
-116
lines changed

ios/GitPoint.xcodeproj/project.pbxproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
};
66
objectVersion = 46;
77
objects = {
8-
98
/* Begin PBXBuildFile section */
109
00C302E51ABCBA2D00DB3ED1 /* libRCTActionSheet.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302AC1ABCB8CE00DB3ED1 /* libRCTActionSheet.a */; };
1110
00C302E71ABCBA2D00DB3ED1 /* libRCTGeolocation.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C302BA1ABCB90400DB3ED1 /* libRCTGeolocation.a */; };

src/search/screens/search.screen.js

Lines changed: 81 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,7 @@
22
import React, { Component } from 'react';
33
import { connect } from 'react-redux';
44
import { bindActionCreators } from 'redux';
5-
import {
6-
StyleSheet,
7-
Text,
8-
View,
9-
FlatList,
10-
Dimensions,
11-
Platform,
12-
} from 'react-native';
5+
import { FlatList, Dimensions, Platform } from 'react-native';
136
import { ButtonGroup } from 'react-native-elements';
147

158
import {
@@ -19,6 +12,7 @@ import {
1912
LoadingContainer,
2013
SearchBar,
2114
} from 'components';
15+
import styled from 'styled-components';
2216
import { colors, fonts, normalize } from 'config';
2317
import { isIphoneX, translate } from 'utils';
2418
import { searchRepos, searchUsers } from '../index';
@@ -40,29 +34,44 @@ const mapDispatchToProps = dispatch =>
4034
dispatch
4135
);
4236

43-
const styles = StyleSheet.create({
44-
searchBarWrapper: {
45-
flexDirection: 'row',
46-
...Platform.select({
47-
ios: {
48-
marginTop: isIphoneX() ? 30 : 20,
49-
},
50-
android: {
51-
marginTop: 5,
52-
},
53-
}),
54-
},
55-
searchContainer: {
56-
width: Dimensions.get('window').width,
57-
backgroundColor: colors.white,
58-
flex: 1,
59-
height: 55,
60-
justifyContent: 'center',
61-
},
62-
list: {
63-
marginTop: 0,
64-
},
65-
buttonGroupContainer: {
37+
const SearchBarWrapper = styled.View`
38+
flex-direction: row;
39+
margin-top: ${Platform.select({
40+
ios: isIphoneX() ? 30 : 20,
41+
android: 5,
42+
})};
43+
`;
44+
45+
const SearchContainer = styled.View`
46+
width: ${Dimensions.get('window').width};
47+
background-color: ${colors.white};
48+
flex: 1;
49+
height: 55;
50+
justify-content: center;
51+
`;
52+
53+
const ListContainer = styled.View`
54+
border-top-color: ${colors.greyLight};
55+
border-top-width: ${props => (props.noBorderTopWidth ? 0 : 1)};
56+
margin-bottom: 105;
57+
`;
58+
59+
const TextContainer = styled.View`
60+
flex: 1;
61+
align-items: center;
62+
justify-content: center;
63+
`;
64+
65+
const SearchInfoText = styled.Text`
66+
font-size: ${normalize(18)};
67+
text-align: center;
68+
${fonts.fontPrimary};
69+
`;
70+
71+
const StyledButtonGroup = styled(ButtonGroup).attrs({
72+
textStyle: { ...fonts.fontPrimaryBold },
73+
selectedTextStyle: { color: colors.black },
74+
containerStyle: {
6675
height: 30,
6776
...Platform.select({
6877
ios: {
@@ -75,38 +84,7 @@ const styles = StyleSheet.create({
7584
},
7685
}),
7786
},
78-
buttonGroupText: {
79-
...fonts.fontPrimaryBold,
80-
},
81-
buttonGroupTextSelected: {
82-
color: colors.black,
83-
},
84-
loadingIndicatorContainer: {
85-
justifyContent: 'center',
86-
alignItems: 'center',
87-
},
88-
textContainer: {
89-
flex: 1,
90-
alignItems: 'center',
91-
justifyContent: 'center',
92-
},
93-
searchTitle: {
94-
fontSize: normalize(18),
95-
textAlign: 'center',
96-
...fonts.fontPrimary,
97-
},
98-
searchCancelButton: {
99-
color: colors.black,
100-
},
101-
listContainer: {
102-
borderTopColor: colors.greyLight,
103-
borderTopWidth: 1,
104-
marginBottom: 105,
105-
},
106-
noBorderTopWidth: {
107-
borderTopWidth: 0,
108-
},
109-
});
87+
})``;
11088

11189
class Search extends Component {
11290
props: {
@@ -215,37 +193,32 @@ class Search extends Component {
215193

216194
return (
217195
<ViewContainer>
218-
<View>
219-
<View style={styles.searchBarWrapper}>
220-
<View style={styles.searchContainer}>
221-
<SearchBar
222-
textColor={colors.primaryDark}
223-
textFieldBackgroundColor={colors.greyLight}
224-
showsCancelButton={this.state.searchFocus}
225-
onFocus={() => this.setState({ searchFocus: true })}
226-
onCancelButtonPress={() =>
227-
this.setState({ searchStart: false, query: '' })
228-
}
229-
onSearchButtonPress={text => {
230-
this.search(text);
231-
}}
232-
hideBackground
233-
/>
234-
</View>
235-
</View>
236-
237-
<ButtonGroup
238-
onPress={this.switchQueryType}
239-
selectedIndex={this.state.searchType}
240-
buttons={[
241-
translate('search.main.repositoryButton', locale),
242-
translate('search.main.userButton', locale),
243-
]}
244-
textStyle={styles.buttonGroupText}
245-
selectedTextStyle={styles.buttonGroupTextSelected}
246-
containerStyle={styles.buttonGroupContainer}
247-
/>
248-
</View>
196+
<SearchBarWrapper>
197+
<SearchContainer>
198+
<SearchBar
199+
textColor={colors.primaryDark}
200+
textFieldBackgroundColor={colors.greyLight}
201+
showsCancelButton={this.state.searchFocus}
202+
onFocus={() => this.setState({ searchFocus: true })}
203+
onCancelButtonPress={() =>
204+
this.setState({ searchStart: false, query: '' })
205+
}
206+
onSearchButtonPress={text => {
207+
this.search(text);
208+
}}
209+
hideBackground
210+
/>
211+
</SearchContainer>
212+
</SearchBarWrapper>
213+
214+
<StyledButtonGroup
215+
onPress={this.switchQueryType}
216+
selectedIndex={this.state.searchType}
217+
buttons={[
218+
translate('search.main.repositoryButton', locale),
219+
translate('search.main.userButton', locale),
220+
]}
221+
/>
249222

250223
{isPendingSearchRepos &&
251224
searchType === 0 && (
@@ -254,7 +227,6 @@ class Search extends Component {
254227
text={translate('search.main.searchingMessage', locale, {
255228
query,
256229
})}
257-
style={styles.marginSpacing}
258230
/>
259231
)}
260232

@@ -265,59 +237,53 @@ class Search extends Component {
265237
text={translate('search.main.searchingMessage', locale, {
266238
query,
267239
})}
268-
style={styles.marginSpacing}
269240
/>
270241
)}
271242

272243
{searchStart &&
273244
noResults && (
274-
<View
275-
style={[
276-
styles.listContainer,
277-
isPending && styles.noBorderTopWidth,
278-
]}
279-
>
245+
<ListContainer noBorderTopWidth={isPending}>
280246
<FlatList
281247
data={searchType === 0 ? repos : users}
282248
keyExtractor={this.keyExtractor}
283249
renderItem={this.renderItem}
284250
/>
285-
</View>
251+
</ListContainer>
286252
)}
287253

288254
{!searchStart && (
289-
<View style={styles.textContainer}>
290-
<Text style={styles.searchTitle}>
255+
<TextContainer>
256+
<SearchInfoText>
291257
{translate('search.main.searchMessage', locale, {
292258
type:
293259
searchType === 0
294260
? translate('search.main.repository', locale)
295261
: translate('search.main.user', locale),
296262
})}
297-
</Text>
298-
</View>
263+
</SearchInfoText>
264+
</TextContainer>
299265
)}
300266

301267
{searchStart &&
302268
!isPendingSearchRepos &&
303269
repos.length === 0 &&
304270
searchType === 0 && (
305-
<View style={styles.textContainer}>
306-
<Text style={styles.searchTitle}>
271+
<TextContainer>
272+
<SearchInfoText>
307273
{translate('search.main.noRepositoriesFound', locale)}
308-
</Text>
309-
</View>
274+
</SearchInfoText>
275+
</TextContainer>
310276
)}
311277

312278
{searchStart &&
313279
!isPendingSearchUsers &&
314280
users.length === 0 &&
315281
searchType === 1 && (
316-
<View style={styles.textContainer}>
317-
<Text style={styles.searchTitle}>
282+
<TextContainer>
283+
<SearchInfoText>
318284
{translate('search.main.noUsersFound', locale)}
319-
</Text>
320-
</View>
285+
</SearchInfoText>
286+
</TextContainer>
321287
)}
322288
</ViewContainer>
323289
);

0 commit comments

Comments
 (0)