-
Notifications
You must be signed in to change notification settings - Fork 775
refactor: use styled-components in comment-list-item #557
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
|
|
||
| import React, { Component } from 'react'; | ||
| import { connect } from 'react-redux'; | ||
| import { StyleSheet, View, Text, TouchableOpacity, Image } from 'react-native'; | ||
| import styled from 'styled-components/native'; | ||
| import { GithubHtmlView } from 'components'; | ||
| import { Icon } from 'react-native-elements'; | ||
| import ActionSheet from 'react-native-actionsheet'; | ||
|
|
@@ -13,71 +13,71 @@ import moment from 'moment/min/moment-with-locales.min'; | |
| import { translate } from 'utils'; | ||
| import { colors, fonts, normalize } from 'config'; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| paddingRight: 10, | ||
| paddingTop: 10, | ||
| backgroundColor: 'transparent', | ||
| }, | ||
| header: { | ||
| flexDirection: 'row', | ||
| marginLeft: 10, | ||
| alignItems: 'center', | ||
| }, | ||
| avatarContainer: { | ||
| backgroundColor: colors.greyLight, | ||
| borderRadius: 17, | ||
| width: 34, | ||
| height: 34, | ||
| }, | ||
| avatar: { | ||
| width: 34, | ||
| height: 34, | ||
| borderRadius: 17, | ||
| }, | ||
| titleSubtitleContainer: { | ||
| justifyContent: 'center', | ||
| flex: 1, | ||
| marginLeft: 10, | ||
| }, | ||
| dateContainer: { | ||
| flex: 0.15, | ||
| alignItems: 'flex-end', | ||
| justifyContent: 'center', | ||
| }, | ||
| linkDescription: { | ||
| ...fonts.fontPrimaryBold, | ||
| fontSize: normalize(13), | ||
| color: colors.primaryDark, | ||
| }, | ||
| date: { | ||
| color: colors.greyDark, | ||
| }, | ||
| commentContainer: { | ||
| paddingTop: 5, | ||
| marginLeft: 54, | ||
| borderBottomColor: colors.greyLight, | ||
| borderBottomWidth: 1, | ||
| }, | ||
| commentBottomPadding: { | ||
| paddingBottom: 15, | ||
| }, | ||
| commentText: { | ||
| fontSize: normalize(12), | ||
| color: colors.primaryDark, | ||
| }, | ||
| commentTextNone: { | ||
| ...fonts.fontPrimary, | ||
| color: colors.primaryDark, | ||
| fontStyle: 'italic', | ||
| }, | ||
| actionButtonIconContainer: { | ||
| paddingTop: 5, | ||
| paddingBottom: 10, | ||
| alignItems: 'flex-end', | ||
| justifyContent: 'center', | ||
| }, | ||
| }); | ||
| const Container = styled.View` | ||
| padding: 10px 10px 0 0; | ||
| background-color: transparent; | ||
| `; | ||
|
|
||
| const Header = styled.View` | ||
| flex-direction: row; | ||
| margin-left: 10px; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch for those shorthands properties. But shall we always add units for properties? (cc @alejandronanez)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t know. It’s up to you. I never use units for 0 in css.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should stick to unitless, that's what we've been doing in other PRs |
||
| align-items: center; | ||
| `; | ||
|
|
||
| const AvatarContainer = styled.TouchableOpacity` | ||
| background-color: ${colors.greyLight}; | ||
| border-radius: 17px; | ||
| width: 34px; | ||
| height: 34px; | ||
| `; | ||
|
|
||
| const Avatar = styled.Image` | ||
| border-radius: 17px; | ||
| width: 34px; | ||
| height: 34px; | ||
| `; | ||
|
|
||
| const TitleSubtitleContainer = styled.View` | ||
| justify-content: center; | ||
| flex: 1; | ||
| margin-left: 10px; | ||
| `; | ||
|
|
||
| const DateContainer = styled.View` | ||
| flex: 0.1; | ||
| align-items: flex-end; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const LinkDescription = styled.Text` | ||
| ${{ ...fonts.fontPrimaryBold }}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we just write as
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don’t kno. I’m not sure how this actually works. Just copied it from the other already concerted components. I handle fonts differently in my apps.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be:
EDIT: Actually, let's keep it like you did, I think it would be better to get rid of |
||
| font-size: ${normalize(13)}; | ||
| color: ${colors.primaryDark}; | ||
| `; | ||
|
|
||
| const DateLabel = styled.Text` | ||
| color: ${colors.greyDark}; | ||
| `; | ||
|
|
||
| const CommentContainer = styled.View` | ||
| padding-top: 5px; | ||
| margin-left: 54px; | ||
| border-bottom-color: ${colors.greyLight}; | ||
| border-bottom-width: 1px; | ||
| padding-bottom: ${props => (props.bottomPadding ? 15 : 0)}px; | ||
| `; | ||
|
|
||
| const CommentTextNone = styled.Text` | ||
| ${{ ...fonts.fontPrimary }}; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
| color: ${colors.primaryDark}; | ||
| font-style: italic; | ||
| `; | ||
|
|
||
| const ActionButtonIconContainer = styled.View` | ||
| padding: 5px 0; | ||
| align-items: flex-end; | ||
| justify-content: center; | ||
| `; | ||
|
|
||
| const mapStateToProps = state => ({ | ||
| authUser: state.auth.user, | ||
|
|
@@ -133,11 +133,10 @@ class CommentListItemComponent extends Component { | |
| comment.user && authUser.login === comment.user.login; | ||
|
|
||
| return ( | ||
| <View style={styles.container}> | ||
| <View style={styles.header}> | ||
| <Container> | ||
| <Header> | ||
| {comment.user && ( | ||
| <TouchableOpacity | ||
| style={styles.avatarContainer} | ||
| <AvatarContainer | ||
| onPress={() => | ||
| navigation.navigate( | ||
| authUser.login === comment.user.login | ||
|
|
@@ -148,19 +147,17 @@ class CommentListItemComponent extends Component { | |
| } | ||
| )} | ||
| > | ||
| <Image | ||
| style={styles.avatar} | ||
| <Avatar | ||
| source={{ | ||
| uri: comment.user.avatar_url, | ||
| }} | ||
| /> | ||
| </TouchableOpacity> | ||
| </AvatarContainer> | ||
| )} | ||
|
|
||
| {comment.user && ( | ||
| <View style={styles.titleSubtitleContainer}> | ||
| <Text | ||
| style={styles.linkDescription} | ||
| <TitleSubtitleContainer> | ||
| <LinkDescription | ||
| onPress={() => | ||
| navigation.navigate( | ||
| authUser.login === comment.user.login | ||
|
|
@@ -172,46 +169,39 @@ class CommentListItemComponent extends Component { | |
| )} | ||
| > | ||
| {comment.user.login} | ||
| </Text> | ||
| </View> | ||
| </LinkDescription> | ||
| </TitleSubtitleContainer> | ||
| )} | ||
|
|
||
| <View style={styles.dateContainer}> | ||
| <Text style={styles.date}> | ||
| {moment(comment.created_at).fromNow()} | ||
| </Text> | ||
| </View> | ||
| </View> | ||
|
|
||
| <View | ||
| style={[ | ||
| styles.commentContainer, | ||
| !isActionMenuEnabled && styles.commentBottomPadding, | ||
| ]} | ||
| > | ||
| <DateContainer> | ||
| <DateLabel>{moment(comment.created_at).fromNow()}</DateLabel> | ||
| </DateContainer> | ||
| </Header> | ||
|
|
||
| <CommentContainer bottomPadding={!isActionMenuEnabled}> | ||
| {commentPresent ? ( | ||
| <GithubHtmlView | ||
| source={comment.body_html} | ||
| onLinkPress={onLinkPress} | ||
| /> | ||
| ) : ( | ||
| <Text style={styles.commentTextNone}> | ||
| <CommentTextNone> | ||
| {translate('issue.main.noDescription', locale)} | ||
| </Text> | ||
| </CommentTextNone> | ||
| )} | ||
|
|
||
| {isActionMenuEnabled && ( | ||
| <View style={styles.actionButtonIconContainer}> | ||
| <ActionButtonIconContainer> | ||
| <Icon | ||
| color={colors.grey} | ||
| size={20} | ||
| name={'ellipsis-h'} | ||
| type={'font-awesome'} | ||
| onPress={this.showMenu} | ||
| /> | ||
| </View> | ||
| </ActionButtonIconContainer> | ||
| )} | ||
| </View> | ||
| </CommentContainer> | ||
|
|
||
| <ActionSheet | ||
| ref={o => { | ||
|
|
@@ -225,7 +215,7 @@ class CommentListItemComponent extends Component { | |
| cancelButtonIndex={this.commentActionSheetOptions(comment).length} | ||
| onPress={this.handlePress} | ||
| /> | ||
| </View> | ||
| </Container> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉 You contributed codes in fact.