Skip to content

refactor: Updated section-list styles to used styled-components#608

Merged
machour merged 11 commits intogitpoint:masterfrom
jamesg1:feature/migrate-sectionlist-styled-comp
Feb 23, 2018
Merged

refactor: Updated section-list styles to used styled-components#608
machour merged 11 commits intogitpoint:masterfrom
jamesg1:feature/migrate-sectionlist-styled-comp

Conversation

@jamesg1
Copy link
Copy Markdown
Contributor

@jamesg1 jamesg1 commented Oct 30, 2017

Question Response
Version? v1.4.0
Devices tested? iPhone 6 and iPhone 8
Bug fix? yes
New feature? no
Includes tests? no
All Tests pass? yes/no
Related ticket? #532

Screenshots

Before After
before after

Description

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

@jamesg1
Copy link
Copy Markdown
Contributor Author

jamesg1 commented Oct 30, 2017

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.

@jamesg1 jamesg1 changed the title fix: Updated section-list styles to used styled-components refactor: Updated section-list styles to used styled-components Oct 30, 2017
@coveralls
Copy link
Copy Markdown

Coverage Status

Coverage increased (+0.2%) to 39.553% when pulling 49cb192 on jamesg1:feature/migrate-sectionlist-styled-comp into 753f60c on gitpoint:master.

Copy link
Copy Markdown
Member

@chinesedfan chinesedfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesg1 Good job! Glad to see that you notice RNE problems, @machour will try to fix it.

};

const Section = styled.View`
margin-top: 15px;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep unitless for simple properties.

Copy link
Copy Markdown
Contributor Author

@jamesg1 jamesg1 Oct 31, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, shorthands properties need units, but except for 0. So here can be changed as margin: 20px 0;.

"name": "James G",
"avatar_url": "https://avatars3.githubusercontent.com/u/3621147?v=4",
"profile": "https://github.com/jamesg1",
"contributions": []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can select code as your contributions. :)

@jamesg1
Copy link
Copy Markdown
Contributor Author

jamesg1 commented Oct 31, 2017

@chinesedfan I've made those requested changes, Thanks

@coveralls
Copy link
Copy Markdown

coveralls commented Oct 31, 2017

Coverage Status

Coverage increased (+0.3%) to 44.511% when pulling cab7e08 on jamesg1:feature/migrate-sectionlist-styled-comp into 0eef067 on gitpoint:master.

@machour
Copy link
Copy Markdown
Member

machour commented Nov 4, 2017

Hey @jamesg1! react-native-elements 0.18.1 was published yesterday and I'm working on a PR to upgrade to it and fix all the problems introduced with styled components.

Putting this PR on hold until I'm done, then I'll be happy to help you with this one if needed

machour
machour previously requested changes Nov 7, 2017
Copy link
Copy Markdown
Member

@machour machour left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can now be styled like this:

const SectionListItem = styled(ListItem).attrs({
  titleStyle: {
     color: colors.black,
      ...fonts.fontPrimary,
  }
})``;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @machour I'll take a look, I was on vacation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@machour Updated code accordingly, check it out 👍

@jamesg1
Copy link
Copy Markdown
Contributor Author

jamesg1 commented Feb 19, 2018

@machour @chinesedfan Sorry for the delay updated this PR with some changes 👍

Copy link
Copy Markdown
Member

@chinesedfan chinesedfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Those attributes should be object style, instead of css style.

const TitleView = styled.View`
padding: 15px;
`;
const SectionList = styled(List).attrs({
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SectionList is already used as exported component name.

const SectionListItem = styled(ListItem).attrs({
titleStyle: {
color: colors.black,
${fonts.fontPrimary},
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Object grammer here.

border-color: ${colors.primaryDark};
border-width: 1;
border-radius: 3;
padding: 5px 10px;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields should be attr buttonStyle.

textStyle={fonts.fontPrimarySemiBold}
fontSize={13}
color={showButton ? colors.primaryDark : colors.white}
buttonStyle={styles.button}
Copy link
Copy Markdown
Member

@chinesedfan chinesedfan Feb 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides buttonStyle, please move other props like textStyle/fontSize/color to styled-components attrs, too.

@machour machour dismissed their stale review February 21, 2018 10:05

Waiting on updated screenshots to perform a new review

Copy link
Copy Markdown
Member

@chinesedfan chinesedfan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jamesg1 I am not sure whether you are ready. I leave some comments to remind.

margin-top: 15;
`;
const Header = styled.View`
flex: auto;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does flex: auto the same with flex: 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't get flex: 1 to work it would result in the content below overlapping the header.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the original code uses flex: 1. Never mind, maybe you discovered a bug and fixed. We can help you check it.

Copy link
Copy Markdown
Contributor Author

@jamesg1 jamesg1 Feb 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is what I get with flex: 1.
![flex 1 screenshot](https://user-images.githubusercontent.com/3621147/36538300-9be10206-181e-11e8-8c23-15615282c553.png =250x)

flex: 0 seemed to fix the flexbox issues.
![flex 0 screenshot](https://user-images.githubusercontent.com/3621147/36538413-10f191d2-181f-11e8-9c09-a4ff5ef18e36.png =250x)

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

I've gone with flex-grow: 0; flex-basis: 0;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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;.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I deleted flex-grow: 0; flex-basis: 0; on Header styling.
Thanks

backgroundColor: colors.white,
borderColor: colors.primaryDark,
borderWidth: 1,
borderRadius: 3,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing this line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah sorry was a typo.

borderRadius: 3,
paddingVertical: 5,
paddingHorizontal: 10,
...fonts.fontPrimaryBold,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fonts.fontPrimaryBold belongs to attr textStyle, and other attrs(fontSize/color) are missing.

Copy link
Copy Markdown
Contributor Author

@jamesg1 jamesg1 Feb 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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: {},
}``;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah awesome made the change!

@jamesg1
Copy link
Copy Markdown
Contributor Author

jamesg1 commented Feb 22, 2018

Updated PR with styling changes and screenshots. Thanks 👍

@machour
Copy link
Copy Markdown
Member

machour commented Feb 22, 2018

@jamesg1 the screenshots looks weird in the header (time overlapping with your avatar) is that when you're scrolling down?

@jamesg1
Copy link
Copy Markdown
Contributor Author

jamesg1 commented Feb 22, 2018

Yeah its because its scrolled. Good pickup I'll fix them now.

@machour
Copy link
Copy Markdown
Member

machour commented Feb 23, 2018

Working as expected on Android 🎉
screenshot_1519373220

@machour machour merged commit 8c3d75c into gitpoint:master Feb 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants