Skip to content
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

Refactor Avatar Size props #1098

Merged
merged 6 commits into from
Apr 13, 2018
Merged

Refactor Avatar Size props #1098

merged 6 commits into from
Apr 13, 2018

Conversation

Gregjarvez
Copy link
Collaborator

fixes #1095

@codecov
Copy link

codecov bot commented Apr 11, 2018

Codecov Report

Merging #1098 into next will increase coverage by 1.25%.
The diff coverage is 40%.

Impacted file tree graph

@@            Coverage Diff             @@
##             next    #1098      +/-   ##
==========================================
+ Coverage   55.57%   56.82%   +1.25%     
==========================================
  Files          33       33              
  Lines         610      586      -24     
  Branches      110      102       -8     
==========================================
- Hits          339      333       -6     
+ Misses        217      205      -12     
+ Partials       54       48       -6
Impacted Files Coverage Δ
src/avatar/Avatar.js 16.12% <40%> (+5.71%) ⬆️
src/icons/Icon.js 100% <0%> (+7.14%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d906775...366b76c. Read the comment docs.

Copy link
Collaborator

@xavier-villelegier xavier-villelegier left a comment

Choose a reason for hiding this comment

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

I better like this way, much more simple. Thanks @Gregjarvez ! 💯 🔥

Can you please update the docs too ?
And if you feel like a rockstar, you can update the typescript definition too 🎸 😎

showEditButton: false,
onEditPress: null,
width: 34,
height: 34,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe use your DEFAULT_SIZES object here, to have only one source for the sizes

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I will do that @xavier-villelegier 😀typescript 😍

Copy link
Collaborator

@xavier-villelegier xavier-villelegier left a comment

Choose a reason for hiding this comment

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

Almost there 💪

const iconDimension = DEFAULT_SIZES[size];

if (iconDimension) {
[width, height] = iconDimension;
Copy link
Collaborator

@xavier-villelegier xavier-villelegier Apr 11, 2018

Choose a reason for hiding this comment

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

This will fail if size is not one of 'small', 'medium', 'large', 'xlarge' (You can't use this syntax if iconDimension is undefined). You should use the small size as a fallback if the size is not correct (const iconDimension = DEFAULT_SIZES[size] || DEFAULT_SIZES.small).

Of course this messes up your condition if (iconDimension) that will always be true as there is a fallback, so you need to tweak that too to be sure that if the user passes width or height it will be taken instead of default size

Copy link
Collaborator

Choose a reason for hiding this comment

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

I was just about to type this on the way to work :D Good job. Think we can set small as true by default.

Is there any reason we explicitly have height and width as props. If the avatar is either a circle or rectangle that means that width and height will always be the same no? If so size could either be 'small', 'medium', 'large', 'xlarge' or a number.

Copy link
Collaborator

@xavier-villelegier xavier-villelegier Apr 11, 2018

Choose a reason for hiding this comment

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

@Gregjarvez
I think the idea of @iRoachie to have either a string or a number is cool. We can get rid of 6 props and simplify everything.
You can just have something like width = typeof props.size === 'number' ? props.size : DEFAULT_SIZES[size][0] || DEFAULT_SIZES.small[0] (doesn't have to be exactly this but you got the idea), same goes for the height. Be sure you also set small as the defaultProps for size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fantastic. so which props do we get rid of apart from width and height

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh was just talking about 'small', 'medium', 'large', 'xlarge', 'width', 'height'. 6 become 1 props 🔥

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oh ok. I will get that done soon !!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@iRoachie @xavier-villelegier I did the changes required seem to work
https://snack.expo.io/rJ_bq9isz
changed code

// iRoachie mentioned avatar is either a circle or a square. one number will work fine
const DEFAULT_SIZES = {
  small: 34,
  medium: 50,
  large: 75,
  xlarge: 150,
};
//size is `small` by default in defaultProps
 let { size } = props;

const iconDimension = typeof size === 'number' ? size : DEFAULT_SIZES[size];

let height;
let width = (height = iconDimension);

Copy link
Collaborator

Choose a reason for hiding this comment

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

@Gregjarvez Just add a fallback on the small size for iconDimension (DEFAULT_SIZES[size] || DEFAULT_SIZES.small) in case you typed an invalid string size

Copy link
Collaborator

Choose a reason for hiding this comment

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

Otherwise it looks good to me

@iRoachie iRoachie changed the title rewrite avatar size prop Refactor Avatar Size props Apr 11, 2018
docs/avatar.md Outdated

| Type | Default |
| :------------: | :-----: |
| object (style) | none |
| string(`small`, `medium`, `large`, `xlarge`) | `small` |
Copy link
Collaborator

Choose a reason for hiding this comment

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

type would be string(small, medium, large, xlarge) OR number

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah I changed that for the next pul request

src/index.d.ts Outdated
* Extra-large sized icon
*/
xlarge?: boolean;
size?: 'small' | 'medium' | 'large' | 'xlarge '
Copy link
Collaborator

Choose a reason for hiding this comment

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

Also needs to update here

Copy link
Collaborator

@xavier-villelegier xavier-villelegier left a comment

Choose a reason for hiding this comment

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

👏 👏


let { width, height } = props;
const iconDimension = typeof size === 'number' ? size : DEFAULT_SIZES[size];
Copy link
Collaborator

@iRoachie iRoachie Apr 11, 2018

Choose a reason for hiding this comment

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

You forgot the change from @xavier-villelegier. This will still fail if I pass in size="bob"

Copy link
Collaborator Author

@Gregjarvez Gregjarvez Apr 11, 2018

Choose a reason for hiding this comment

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

oh yeh sorry about that. I was thinking propTypes will fail it
`PropTypes.Oneof(['small', '....'])

default to small even with size="bob"?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea but propTypes is just a warning, it doesn't stop the app from trying to load. If we don't provide a fallback it'll red screen (crash)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that is done

@iRoachie
Copy link
Collaborator

LGTM let's ship it

Copy link
Collaborator

@Monte9 Monte9 left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -185,24 +171,10 @@ export interface AvatarProps {
iconStyle?: StyleProp<TextStyle>;

/**
* Small sized icon
* Size of Avatar
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just one small change!

Add a new line here and put @default "small"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sure

@iRoachie iRoachie merged commit fe1edb7 into react-native-elements:next Apr 13, 2018
@Gregjarvez Gregjarvez deleted the avatar-size-prop branch April 13, 2018 13:34
Monte9 pushed a commit that referenced this pull request May 6, 2018
* Remove any occurence of `isRequired` #960

* fix(Title) Move disabled style (#1070)

* fix(Title) Move disabled style

* reorder styles

* fix(types): ButtonGroup - Add selectedButtonStyle

Replace selectedBackgroundColor with selectedButtonStyle

* Run prettier on some stray files

* Fix typo in listitem.md (#1078)

* Fix typo in listitem.md

'checkbox' corrected to 'checkBox'

* fix checkBox typo in versioned docs listitem.md

* Allowed Badge to accept any component as the Container component (#1061)

* Button group use platform touchable  (#1087)

* buttongroup platform specific touchable

* move component prop logic defaultprops

* Add WeChat color to SocialIcon (#1092)

* (ListItem) Fix checkmark platform sizing (#1090)

* Fix Overlay children typing

* docs(Avatar): Add size props

small, medium, large, xlarge

* docs(ListItem): Change avatar to leftAvatar

Add props descriptions to beta4 docs. Fixes #1069

* fix(Avatar): Re-add missing `imageProps` prop

* Dismiss overlay by touching backdrop (#1094)

* Dismiss Overlay by clicking outside of Overlay Modal

* updated overlay docs

* rename overlayBackgroundpress to onBackdropPress

* updated overlay snapshot

* fix overlay prop type

* Add `onBackdropPress` to Overlay

* Fix Icon style when using TouchableNativeFeedback (#1104)

* add encasing view and update test

* add encasing view and update test

* Refactor Avatar Size props (#1098)

* rewrite avatar size prop

* updated docs

* updated typescript definitions

* updated docs, ts and size prop logic

* fallback for icon dimension

* @default docs

* Add raised prop back to Button component (#1108)

* Bump docusarus version

* docs(website): Fix small bug in listitem docs header

* docs(website): Set default version shown as 0.19.0

* docs(website): Replace main icon with svg

* Add backdropPress example to docs (#1116)

* Use v0.19.0 as default version (#1101)

* Revert website default version (#1103)

* Use v0.19.0 as default version

* Revert "Use v0.19.0 as default version"

This reverts commit 1caeefd.

* Revert "Use v0.19.0 as default version"

This reverts commit 1caeefd.

* Add descriptions for ListItem props in v1.0.0-beta4 docs (#1118)

* Remove weird duplicate in beta4 docs [ci skip]

* button opacity layer border on button press (#1107)

* Opacity layer borderRadius on Button press

* borderRadius to containerStyle.borderRadius

* containerStyle.borderRadius  -> buttonStyle.borderRadadius😄

* docs(Card) Button icon needs to be a component (#1132)

* Button icon needs to be a component

* Use icon element instead of object for Card docs

* ci(travis) Pin version of node

Node 10 currently breaks builds cause of missing whitelist console in react native jest setup. jestjs/jest#2567 (comment) Pinning node version until react-native/jest bumps

* Cleanup definitons [ci-skip]

* Bounce Form elements (#1146)

* Refactor and make uniform all SearchBars (#1135)

* Remove useless flex

* Refactor default SearchBar

* Add renderIcon helper

* Use helper for default SearchBar

* Use renderIcon in Input

* Add back input icons containers

* Improve renderIcon helper

* Remove useless import

* Use renderIcon for iOS searchbar

* Use renderIcon for Android searchbar

* Update SearchBar and Input docs

* Update this.clear call

* Remove useless onCancel on default searchbar

* Remove useless hasFocus on default props

* Update tests

* Fix tests with new props

* Use renderNode + refactor nodeType

* Fix typo + link to Input props

* Use `false` instead of `null` [ci-skip]

* docs(Input) Typo it should be labelStyle not labelString

* docs(ListItem) onPress component should be TouchableOpacity (#1152)

* Typo?

It seems that a touchableopacity is added - not a touchablehighlight.

shouldn't a touchablehighlight be used here?
* https://medium.com/differential/better-cross-platform-react-native-components-cb8aadeba472
* https://stackoverflow.com/questions/39123357/when-to-use-touchablenativefeedback-touchablehighlight-or-touchableopacity

thanks!

* typo

* Fix depth collision with Button and Overlay (#1113)

* Update Overlay snapshots

* Add Cancel Button Props Object for iOS (#1159)

* docs(website): Set default version shown as 0.19.0 (#1156)

* ci(travis) Pin version of node (#1158)

Node 10 currently breaks builds cause of missing whitelist console in react native jest setup. jestjs/jest#2567 (comment) Pinning node version until react-native/jest bumps

* enhancment(searchBar): add 'cancelButtonColor' to search bar component

This give a user the abilty to change the color of the text for iOS cancel button

* enhancement(searchBar) add 'cancelButtonProps' prop

Users can now pass the normal React Native Button props to the cancel button.

* Add iOS only to docs

* Fix typo in input docs #1041

* Add FormValidationMessage in imports #1144

* (Button) Doc improvement: remove duplicate item (#1167)

for 0.19.0 `Button`
the `loading` item in props list is duplicate

* Create helpers export

* Cleanup SearchBar typings and docs (#1169)

* (types) Cleanup searchbar definitions

* docs(SearchBar): Add inputContainerStyle

Closes #1123

* types (SearchBar) SearchBarAndroid should extend from SearchBarPlatform

* Fix yarn merge conflict [ci-skip]

* Apply renderNode for Button (#1170)

* Update docs

* Use renderNode helper

* Update button icon type

* Update types

* docs(website): Add Troubleshooting section (#1171)

* docs(website): Add Troubleshooting section

* Add more complex steps for font issues

* Bump version to v1.0.0-beta5

* Create new website version
martinezguillaume pushed a commit that referenced this pull request May 17, 2018
* rewrite avatar size prop

* updated docs

* updated typescript definitions

* updated docs, ts and size prop logic

* fallback for icon dimension

* @default docs
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