Skip to content

Commit 6567aa3

Browse files
josenaranjoHoussein Djirdeh
authored andcommitted
refactor(styles): IssueDescription component styles update (#563)
* refactor(styles): IssueDescription component styles update Migrating StyleSheet styles to styled components 532 * fix(styles): Fix StateBadge tests StateBadge component will have some styles trough props. Revert to use StyleSheet in this case. #532
1 parent df8d612 commit 6567aa3

File tree

1 file changed

+124
-111
lines changed

1 file changed

+124
-111
lines changed
Lines changed: 124 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import React, { Component } from 'react';
2-
import { StyleSheet, View, ActivityIndicator } from 'react-native';
2+
import { StyleSheet, ActivityIndicator } from 'react-native';
33
import { ListItem } from 'react-native-elements';
44
import Parse from 'parse-diff';
55
import moment from 'moment/min/moment-with-locales.min';
6+
import styled from 'styled-components/native';
67

78
import {
89
StateBadge,
@@ -12,63 +13,70 @@ import {
1213
Button,
1314
} from 'components';
1415
import { translate } from 'utils';
15-
import { colors, fonts, normalize } from 'config';
16+
import { colors, styledFonts, normalize } from 'config';
1617
import { v3 } from 'api';
1718

1819
const styles = StyleSheet.create({
19-
headerContainer: {
20-
flexDirection: 'row',
21-
alignItems: 'center',
22-
justifyContent: 'center',
23-
paddingRight: 10,
24-
},
25-
borderBottom: {
26-
borderBottomWidth: 1,
27-
borderBottomColor: colors.greyLight,
28-
},
29-
title: {
30-
color: colors.primaryDark,
31-
...fonts.fontPrimarySemiBold,
32-
},
33-
titleSmall: {
34-
color: colors.primaryDark,
35-
...fonts.fontPrimarySemiBold,
36-
fontSize: normalize(10),
37-
},
38-
listItemContainer: {
39-
borderBottomWidth: 0,
40-
flex: 1,
41-
},
42-
diffBlocksContainer: {
43-
flexDirection: 'row',
44-
alignItems: 'center',
45-
justifyContent: 'flex-end',
46-
paddingRight: 10,
47-
paddingBottom: 10,
48-
},
4920
badge: {
5021
alignItems: 'flex-end',
5122
justifyContent: 'center',
5223
},
53-
labelButtonGroup: {
54-
flexWrap: 'wrap',
55-
flexDirection: 'row',
56-
marginLeft: 54,
57-
paddingBottom: 15,
58-
},
59-
assigneesSection: {
60-
marginLeft: 54,
61-
paddingBottom: 5,
62-
},
63-
mergeButtonContainer: {
64-
flex: 1,
65-
flexDirection: 'row',
66-
justifyContent: 'center',
67-
alignItems: 'center',
68-
paddingVertical: 15,
69-
},
7024
});
7125

26+
const HeaderContainer = styled.View`
27+
flex-direction: row;
28+
align-items: center;
29+
justify-content: center;
30+
padding-right: 10;
31+
`;
32+
33+
const ContainerBorderBottom = styled.View`
34+
border-bottom-width: 1;
35+
border-bottom-color: ${colors.greyLight};
36+
`;
37+
38+
const ListItemStyled = styled(ListItem)`
39+
color: ${colors.primaryDark}
40+
font-family: ${styledFonts.fontPrimarySemiBold}
41+
`;
42+
43+
const ListItemURL = ListItemStyled.extend`
44+
font-size: ${normalize(10)};
45+
`;
46+
47+
const ListItemIssueTitle = ListItemStyled.extend`
48+
border-bottom-width: 0;
49+
flex: 1;
50+
`;
51+
52+
const DiffBlocksContainer = styled.View`
53+
flex-direction: row;
54+
align-items: center;
55+
justify-content: flex-end;
56+
padding-right: 10;
57+
padding-bottom: 10;
58+
`;
59+
60+
const LabelButtonGroup = styled.View`
61+
flex-wrap: wrap;
62+
flex-direction: row;
63+
margin-left: 54;
64+
padding-bottom: 15;
65+
`;
66+
67+
const AssigneesSection = styled.View`
68+
margin-left: 54;
69+
padding-bottom: 5;
70+
`;
71+
72+
const MergeButtonContainer = styled.View`
73+
flex: 1;
74+
flex-direction: row;
75+
justify-content: center;
76+
align-items: center;
77+
padding-vertical: 15;
78+
`;
79+
7280
export class IssueDescription extends Component {
7381
props: {
7482
issue: Object,
@@ -114,11 +122,10 @@ export class IssueDescription extends Component {
114122
});
115123

116124
return (
117-
<View style={(styles.container, styles.borderBottom)}>
118-
{issue.repository_url &&
119-
<ListItem
125+
<ContainerBorderBottom>
126+
{issue.repository_url && (
127+
<ListItemURL
120128
title={issue.repository_url.replace(`${v3.root}/repos/`, '')}
121-
titleStyle={styles.titleSmall}
122129
leftIcon={{
123130
name: 'repo',
124131
size: 17,
@@ -127,14 +134,13 @@ export class IssueDescription extends Component {
127134
}}
128135
onPress={() => onRepositoryPress(issue.repository_url)}
129136
hideChevron
130-
/>}
137+
/>
138+
)}
131139

132-
<View style={styles.headerContainer}>
133-
<ListItem
140+
<HeaderContainer>
141+
<ListItemIssueTitle
134142
title={issue.title}
135-
titleStyle={styles.title}
136143
subtitle={moment(issue.created_at).fromNow()}
137-
containerStyle={styles.listItemContainer}
138144
leftIcon={{
139145
name: issue.pull_request ? 'git-pull-request' : 'issue-opened',
140146
size: 36,
@@ -146,69 +152,76 @@ export class IssueDescription extends Component {
146152

147153
{!issue.pull_request ||
148154
(issue.pull_request &&
149-
!isPendingCheckMerge &&
150-
<StateBadge
151-
style={styles.badge}
152-
issue={issue}
153-
isMerged={isMerged && issue.pull_request}
154-
locale={locale}
155-
/>)}
156-
</View>
155+
!isPendingCheckMerge && (
156+
<StateBadge
157+
style={styles.badge}
158+
issue={issue}
159+
isMerged={isMerged && issue.pull_request}
160+
locale={locale}
161+
/>
162+
))}
163+
</HeaderContainer>
157164

158-
{issue.pull_request &&
159-
<View style={styles.diffBlocksContainer}>
160-
{isPendingDiff &&
161-
<ActivityIndicator animating={isPendingDiff} size="small" />}
165+
{issue.pull_request && (
166+
<DiffBlocksContainer>
167+
{isPendingDiff && (
168+
<ActivityIndicator animating={isPendingDiff} size="small" />
169+
)}
162170

163171
{!isPendingDiff &&
164-
(lineAdditions !== 0 || lineDeletions !== 0) &&
165-
<DiffBlocks
166-
additions={lineAdditions}
167-
deletions={lineDeletions}
168-
showNumbers
169-
onPress={() =>
170-
navigation.navigate('PullDiff', {
171-
title: translate('repository.pullDiff.title', locale),
172-
locale,
173-
diff,
174-
})}
175-
/>}
176-
</View>}
172+
(lineAdditions !== 0 || lineDeletions !== 0) && (
173+
<DiffBlocks
174+
additions={lineAdditions}
175+
deletions={lineDeletions}
176+
showNumbers
177+
onPress={() =>
178+
navigation.navigate('PullDiff', {
179+
title: translate('repository.pullDiff.title', locale),
180+
locale,
181+
diff,
182+
})}
183+
/>
184+
)}
185+
</DiffBlocksContainer>
186+
)}
177187

178188
{issue.labels &&
179-
issue.labels.length > 0 &&
180-
<View style={styles.labelButtonGroup}>
181-
{this.renderLabelButtons(issue.labels)}
182-
</View>}
189+
issue.labels.length > 0 && (
190+
<LabelButtonGroup>
191+
{this.renderLabelButtons(issue.labels)}
192+
</LabelButtonGroup>
193+
)}
183194
{issue.assignees &&
184-
issue.assignees.length > 0 &&
185-
<View style={styles.assigneesSection}>
186-
<MembersList
187-
title={translate('issue.main.assignees', locale)}
188-
members={issue.assignees}
189-
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
190-
smallTitle
191-
navigation={navigation}
192-
/>
193-
</View>}
195+
issue.assignees.length > 0 && (
196+
<AssigneesSection>
197+
<MembersList
198+
title={translate('issue.main.assignees', locale)}
199+
members={issue.assignees}
200+
containerStyle={{ marginTop: 0, paddingTop: 0, paddingLeft: 0 }}
201+
smallTitle
202+
navigation={navigation}
203+
/>
204+
</AssigneesSection>
205+
)}
194206

195207
{issue.pull_request &&
196208
!isMerged &&
197209
issue.state === 'open' &&
198-
userHasPushPermission &&
199-
<View style={styles.mergeButtonContainer}>
200-
<Button
201-
type={isMergeable ? 'success' : 'default'}
202-
icon={{ name: 'git-merge', type: 'octicon' }}
203-
disabled={!isMergeable}
204-
onPress={() =>
205-
navigation.navigate('PullMerge', {
206-
title: translate('issue.pullMerge.title', locale),
207-
})}
208-
title={translate('issue.main.mergeButton', locale)}
209-
/>
210-
</View>}
211-
</View>
210+
userHasPushPermission && (
211+
<MergeButtonContainer>
212+
<Button
213+
type={isMergeable ? 'success' : 'default'}
214+
icon={{ name: 'git-merge', type: 'octicon' }}
215+
disabled={!isMergeable}
216+
onPress={() =>
217+
navigation.navigate('PullMerge', {
218+
title: translate('issue.pullMerge.title', locale),
219+
})}
220+
title={translate('issue.main.mergeButton', locale)}
221+
/>
222+
</MergeButtonContainer>
223+
)}
224+
</ContainerBorderBottom>
212225
);
213226
}
214227
}

0 commit comments

Comments
 (0)