refactor: Updated section-list styles to used styled-components#608
Conversation
fix: Updated contributors list
|
Please advise on how could this be improved, I did find it confusing trying to convert the View for TopHeader, List and ListItem as styled components don't play nicely with react-native-elements. Thanks. |
chinesedfan
left a comment
There was a problem hiding this comment.
@jamesg1 Good job! Glad to see that you notice RNE problems, @machour will try to fix it.
| }; | ||
|
|
||
| const Section = styled.View` | ||
| margin-top: 15px; |
There was a problem hiding this comment.
Please keep unitless for simple properties.
There was a problem hiding this comment.
I changed it to margin: 15 0 0 and this didn't work? What do you mean by unitless? We are writing css within styled components so margin: 15 or margin-top: 15 isn't valid.
There was a problem hiding this comment.
@jamesg1 If you use unitless shorthands properties in styled components, like margin: 15 0 0 or margin: 15, it will crash. But for simple properties, like margin-top: 15, it is OK.
I have to admit that it is a little ambiguous. Real CSS needs units, while RN doesn't need. But how about styled components in RN? For now, we prefer RN more.
| padding: 15px; | ||
| `; | ||
| const LoadingIcon = styled(ActivityIndicator)` | ||
| margin: 20px 0px; |
There was a problem hiding this comment.
Of course, shorthands properties need units, but except for 0. So here can be changed as margin: 20px 0;.
.all-contributorsrc
Outdated
| "name": "James G", | ||
| "avatar_url": "https://avatars3.githubusercontent.com/u/3621147?v=4", | ||
| "profile": "https://github.com/jamesg1", | ||
| "contributions": [] |
There was a problem hiding this comment.
You can select code as your contributions. :)
|
@chinesedfan I've made those requested changes, Thanks |
|
Hey @jamesg1! Putting this PR on hold until I'm done, then I'll be happy to help you with this one if needed |
machour
left a comment
There was a problem hiding this comment.
Hey @jamesg1, we now use the new react-native-elements version which plays way nicer with styled-components 👌
Left you a comment to show you how to style one of them for example.
Could you take care of converting the remaining old styles to styled components? Let me know if you need any help with that!
| listDisplay = <LoadingIcon animating={loading} />; | ||
| } else if (noItems) { | ||
| listDisplay = ( | ||
| <ListItem |
There was a problem hiding this comment.
Can now be styled like this:
const SectionListItem = styled(ListItem).attrs({
titleStyle: {
color: colors.black,
...fonts.fontPrimary,
}
})``;There was a problem hiding this comment.
Thanks @machour I'll take a look, I was on vacation.
There was a problem hiding this comment.
@machour Updated code accordingly, check it out 👍
…tionlist-styled-comp # Conflicts: # .all-contributorsrc # CONTRIBUTORS.md # README.md # src/components/section-list.component.js
|
@machour @chinesedfan Sorry for the delay updated this PR with some changes 👍 |
chinesedfan
left a comment
There was a problem hiding this comment.
@jamesg1 Welcome back! But I am afraid you need to re-run your codes and update the screenshots comparison.
| containerStyle: { | ||
| margin-top: 0; | ||
| border-bottom-color: ${colors.grey}, | ||
| border-bottom-width: 1, |
There was a problem hiding this comment.
Those attributes should be object style, instead of css style.
| const TitleView = styled.View` | ||
| padding: 15px; | ||
| `; | ||
| const SectionList = styled(List).attrs({ |
There was a problem hiding this comment.
SectionList is already used as exported component name.
| const SectionListItem = styled(ListItem).attrs({ | ||
| titleStyle: { | ||
| color: colors.black, | ||
| ${fonts.fontPrimary}, |
| border-color: ${colors.primaryDark}; | ||
| border-width: 1; | ||
| border-radius: 3; | ||
| padding: 5px 10px; |
There was a problem hiding this comment.
These fields should be attr buttonStyle.
| textStyle={fonts.fontPrimarySemiBold} | ||
| fontSize={13} | ||
| color={showButton ? colors.primaryDark : colors.white} | ||
| buttonStyle={styles.button} |
There was a problem hiding this comment.
Besides buttonStyle, please move other props like textStyle/fontSize/color to styled-components attrs, too.
Waiting on updated screenshots to perform a new review
chinesedfan
left a comment
There was a problem hiding this comment.
@jamesg1 I am not sure whether you are ready. I leave some comments to remind.
| margin-top: 15; | ||
| `; | ||
| const Header = styled.View` | ||
| flex: auto; |
There was a problem hiding this comment.
Does flex: auto the same with flex: 1?
There was a problem hiding this comment.
I couldn't get flex: 1 to work it would result in the content below overlapping the header.
There was a problem hiding this comment.
Hmm, the original code uses flex: 1. Never mind, maybe you discovered a bug and fixed. We can help you check it.
There was a problem hiding this comment.
This is what I get with flex: 1.

flex: 0 seemed to fix the flexbox issues.

Also flex-grow: 0; flex-basis: 0; also looked good.

I've gone with flex-grow: 0; flex-basis: 0;
There was a problem hiding this comment.
@jamesg1 Interesting. flex: 1 of styled-components really results in weird UI, while the original code works well.
But the initial values are flex-grow: 0; flex-shrink: 1; flex-basis: auto;. You can delete flex-grow: 0; flex-basis: 0;.
There was a problem hiding this comment.
I deleted flex-grow: 0; flex-basis: 0; on Header styling.
Thanks
| backgroundColor: colors.white, | ||
| borderColor: colors.primaryDark, | ||
| borderWidth: 1, | ||
| borderRadius: 3, |
There was a problem hiding this comment.
Yeah sorry was a typo.
| borderRadius: 3, | ||
| paddingVertical: 5, | ||
| paddingHorizontal: 10, | ||
| ...fonts.fontPrimaryBold, |
There was a problem hiding this comment.
fonts.fontPrimaryBold belongs to attr textStyle, and other attrs(fontSize/color) are missing.
There was a problem hiding this comment.
color={showButton ? colors.primaryDark : colors.white} didn't make sense as showButton will always be true if we are showing the button as its checked before rendering the button showButton &&. Would colour go in buttonStyle or textStyle?
I tried to get fontSize into buttonStyle initially. Will move it to textStyle
There was a problem hiding this comment.
Would colour go in buttonStyle or textStyle?
Neither. It belongs to an attr iteself, as well as fontSize.
const StyledButton = styled(Button).attrs({
textStyle: {},
fontSize: 13,
color: colors.primaryDark,
buttonStyle: {},
}``;
There was a problem hiding this comment.
Yeah awesome made the change!
|
Updated PR with styling changes and screenshots. Thanks 👍 |
|
@jamesg1 the screenshots looks weird in the header (time overlapping with your avatar) is that when you're scrolling down? |
|
Yeah its because its scrolled. Good pickup I'll fix them now. |

Screenshots
Description
Converted some of section-list to use Styled-components.