-
Notifications
You must be signed in to change notification settings - Fork 734
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
Conversation
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() { |
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.
Do we want to deprecate GridView
?
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.
Yes, definitely, I'll create a separate ticket for that
src/components/gridList/index.tsx
Outdated
/** | ||
* 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' |
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.
Ignored when passing 'maxItemWidth'
seems wrong
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.
Left overs from the old grid view implementation, removed
src/components/gridList/index.tsx
Outdated
const containerWidth = useMemo(() => { | ||
return (props.containerWidth ?? Constants.screenWidth) - listPadding * 2; | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [listPadding, orientation]); |
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.
Shouldn't props.containerWidth
be in the dependencies (why should listPadding
change and not containerWidth
)?
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.
Added containerWidth (the comment still relevant because of the orientation dep)
Anyway, the code has been moved to useGridLayout hook
src/components/gridList/index.tsx
Outdated
|
||
const _renderItem = useCallback((...args) => { | ||
// @ts-expect-error | ||
return <View style={[itemContainerStyle]}>{renderItem?.(...args)}</View>; |
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.
No need for the []
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.
True, removed
src/components/gridList/index.tsx
Outdated
/** | ||
* List padding (used for item size calculation) | ||
*/ | ||
listPadding?: number; |
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.
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
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.
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> |
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.
Consider using $textDangerLight
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.
Fixed
@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) |
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.
Looks good!
I left few small comments :)
src/components/gridList/index.tsx
Outdated
const {itemContainerStyle, numberOfColumns} = useGridLayout({ | ||
numColumns, | ||
itemSpacing, | ||
maxItemWidth, | ||
listPadding, | ||
keepItemSize | ||
}); |
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 forgot to pass the containerWidth
here
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.
passed 👌
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [numColumns, maxItemWidth, itemSpacing, keepItemSize ? _containerWidth : undefined]); | ||
|
||
const itemSize = useMemo(() => { |
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.
I think it's better to name it itemWidth
since it does nothing with height.
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.
renamed
return {width: itemSize /* + itemSpacing */, marginRight: itemSpacing, marginBottom: itemSpacing}; | ||
}, [itemSize, itemSpacing]); | ||
|
||
return {itemContainerStyle, numberOfColumns, itemSize}; |
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.
I see that you return the itemSize
but I don't see that we using it somewhere outside.
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.
Removed
|
||
renderItem: GridListProps<typeof products[0]>['renderItem'] = ({item}) => { | ||
return ( | ||
<Card flex> |
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.
Consider adding $textDefault
for the texts inside the card
Description
Create new GridList component based on old GridView
Changelog
Create new GridList component based on old GridView features