Skip to content

Create new GridList component based on old GridView #1914

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

Merged
merged 8 commits into from
Apr 6, 2022

Conversation

ethanshar
Copy link
Collaborator

Description

Create new GridList component based on old GridView

Changelog

Create new GridList component based on old GridView features

src/index.js Outdated
@@ -69,6 +69,9 @@ export default {
get GridListItem() {
return require('./components/gridListItem').default;
},
get GridList() {
return require('./components/gridList').default;
},
get GridView() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we want to deprecate GridView?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, definitely, I'll create a separate ticket for that

/**
* whether to keep the items initial size when orientation changes,
* in which case the apt number of columns will be calculated automatically.
* Ignored when passing 'maxItemWidth'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Ignored when passing 'maxItemWidth' seems wrong

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Left overs from the old grid view implementation, removed

const containerWidth = useMemo(() => {
return (props.containerWidth ?? Constants.screenWidth) - listPadding * 2;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [listPadding, orientation]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't props.containerWidth be in the dependencies (why should listPadding change and not containerWidth)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added containerWidth (the comment still relevant because of the orientation dep)
Anyway, the code has been moved to useGridLayout hook


const _renderItem = useCallback((...args) => {
// @ts-expect-error
return <View style={[itemContainerStyle]}>{renderItem?.(...args)}</View>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

No need for the []

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, removed

/**
* List padding (used for item size calculation)
*/
listPadding?: number;
Copy link
Collaborator

Choose a reason for hiding this comment

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

The listPadding is not acting as expected, for example change the screen to use:

numColumns={2}
// maxItemWidth={140}
itemSpacing={Spacings.s10}
listPadding={Spacings.s2}

There is no padding on the right side.

Or:

numColumns={2}
// maxItemWidth={140}
itemSpacing={Spacings.s10}
// listPadding={Spacings.s2}

It looks like the right item is a little out of the screen

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Well, technically the listPadding prop goes together with setting the list contentContainerStyle with padding.
But I see your point, I think I'll inject the padding in the list myself so the user won't have to worry about it

<Text>{item.name}</Text>
<Text>{item.formattedPrice}</Text>
{item.inventory.status === 'Out of Stock' && (
<Text text90M red30>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider using $textDangerLight

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed

@ethanshar
Copy link
Collaborator Author

@M-i-k-e-l I fixed/comment everything, notice that I did a small refactor and moved the logic and calculation of the grid to useGridLayout hook (this is relevant to the next PR of the SortableGridList)

@ethanshar ethanshar requested a review from M-i-k-e-l March 24, 2022 16:43
@ethanshar ethanshar added the Important for Next Release PR that must be included in the release version label Mar 29, 2022
@ethanshar ethanshar requested review from lidord-wix and removed request for M-i-k-e-l April 3, 2022 13:45
@ethanshar ethanshar assigned lidord-wix and unassigned M-i-k-e-l Apr 3, 2022
Copy link
Contributor

@lidord-wix lidord-wix left a comment

Choose a reason for hiding this comment

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

Looks good!
I left few small comments :)

Comment on lines 19 to 25
const {itemContainerStyle, numberOfColumns} = useGridLayout({
numColumns,
itemSpacing,
maxItemWidth,
listPadding,
keepItemSize
});
Copy link
Contributor

Choose a reason for hiding this comment

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

You forgot to pass the containerWidth here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

passed 👌

// eslint-disable-next-line react-hooks/exhaustive-deps
}, [numColumns, maxItemWidth, itemSpacing, keepItemSize ? _containerWidth : undefined]);

const itemSize = useMemo(() => {
Copy link
Contributor

@lidord-wix lidord-wix Apr 5, 2022

Choose a reason for hiding this comment

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

I think it's better to name it itemWidth since it does nothing with height.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

renamed

return {width: itemSize /* + itemSpacing */, marginRight: itemSpacing, marginBottom: itemSpacing};
}, [itemSize, itemSpacing]);

return {itemContainerStyle, numberOfColumns, itemSize};
Copy link
Contributor

Choose a reason for hiding this comment

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

I see that you return the itemSize but I don't see that we using it somewhere outside.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Removed


renderItem: GridListProps<typeof products[0]>['renderItem'] = ({item}) => {
return (
<Card flex>
Copy link
Contributor

@lidord-wix lidord-wix Apr 5, 2022

Choose a reason for hiding this comment

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

Consider adding $textDefault for the texts inside the card

@ethanshar ethanshar requested a review from lidord-wix April 6, 2022 05:30
@lidord-wix lidord-wix merged commit 788afc0 into master Apr 6, 2022
@ethanshar ethanshar deleted the feat/GridListComponent branch June 13, 2022 08:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Important for Next Release PR that must be included in the release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants