-
Notifications
You must be signed in to change notification settings - Fork 283
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
CellRendererComponent prop #362
Conversation
We only need As part of this PR we should also define the type of props that are passed to CellContainer which will make it easier for the community to tweak it and create awesome stuff. e.g, data, x, y, height, width, extendedState |
This would have been fine if it was not necessary for the custom view to be the first child - but it is for // This does not work
const createCellRenderer = () => {
const cellRenderer: React.FC = (props) => {
return (
<CellContainer>
<Animated.View layout={Layout.duration(3000)}>
{props.children}
</Animated.View>
</CellContainer>
);
};
return cellRenderer;
};
// This works
const createCellRenderer = () => {
const cellRenderer: React.FC = (props) => {
return (
<Animated.View layout={Layout.duration(3000)}>
<CellContainer>{props.children}</CellContainer>
</Animated.View>
);
};
return cellRenderer;
};
...
CellRendererComponent={cellRenderer}
... I have not tried out other use-cases but it's plausible they will have the same limitation - if that's the case, we hit the issues outlined originally in the PR description. If we could return |
Since CellContainer is a native component with a view backing it. AnimatedCellContainer should easy to build. E.g, createAnimatedComponent(CellContainer) |
You're right, that does work. To make TS satisfied, I had to change the type here to If we are ok with abandoning TS checks for the Wdyt, @naqvitalha? |
Worst case scenario, if they don't add the |
I'm ok with the dynamic check, if possible. This could throw a warning to the devs. |
Yes, that's correct. |
@fortmarek There is no way to type JSX right? If there isn't then I guess we can just call it out in comments that return type should be CellContainer. |
231c3fb
to
3dda0d2
Compare
Yes, that's correct. I think this is ready for review now. If the root native component in the renderer native view hierarchy is not It still might not allow all use-cases since there might be cases where you don't want the root component of |
android/src/main/kotlin/com/shopify/reactnative/flash_list/AutoLayoutView.kt
Outdated
Show resolved
Hide resolved
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 changes looks good in theory. Is there any way to easily test it in fixture?
Just to check if things render correctly, you can follow this example. Or you can use this commit for layout animation - it won't work 100 % correctly since it clashes with recycling - but it's not something we want to perfect on our side. We're good with this being possible in theory. Eventually, we could add a more sophisticated example (e.g. using the draggable functionality that Shopify Mobile aims to build) |
48bdac9
to
4e29ba6
Compare
@naqvitalha please, have another look at this 🙏 |
src/FlashListProps.ts
Outdated
* Each cell is rendered using this element. | ||
* Can be a React Component Class, or a render function. | ||
* The root component should always be a `CellContainer` which is also the default component used. | ||
* Ensure that the original `props` are passed to the returned `CellContainer`. |
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.
We can also add some documentation to CellContainer mentioning that it's just a View and can be used with createAnimatedComponent. Mentioning some of its useful props can also be beneficial like x, y, height, width, data
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: bfa8fe7
This looks good. It'll be great to have some more details about CellContainer added |
I like the idea |
src/FlashList.tsx
Outdated
@@ -421,8 +421,12 @@ class FlashList<T> extends React.PureComponent< | |||
}; | |||
|
|||
private itemContainer = (props: any, parentProps: any) => { | |||
console.log(props); |
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.
Let's remove logs from 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.
Let's mention index prop which is important for accessing data and remove logs from library code.
Description
Fixes #360
We currently don't support
CelllRendererComponent
. It can be used for various use-cases, such as reanimated support.In
VirtualizedList
, the component (if available) is used to wrap the cells (see here).However, in
FlashList
we need the wrapping view to beCellContainer
. There are multiple solutions, neither of them ideal:CellContainer
can wrapCellRendererComponent
-> most of the use-cases forCellRendererComponent
leverage that the components are at the same level, so this won't work (e.g. layout animations don't trigger this way). This way, there's not much difference between moving the view fromCellRendererComponent
torenderItem
CellRendererComponent
can wrapCellContainer
-> this will breakAutoLayoutView
since it assumesCellContainer
is on the top level. The adjustments would also be done onCellContainer
and notCellRendererComponent
leading to additional bugsCellRendererComponent
must return a component thatextends CellContainer
. This solution does work well but returning an element extendingCellContainer
constraints the usage. For example, for reanimated support, you need to return component created withAnimated.createAnimatedComponent(CellContainer)
. This is not going to be of typeCellContainer
As mentioned, all of these options have flaws. The first option will bring us the closest to
FlatList
if we are able to solve the issues of findingCellContainer
in the view hierarchy and then adjustingCellRendererComponent
instead ofCellContainer
. The last option is the easiest to implement (as showcased by this PR) but afaict, brings a lot of limitations.Reviewers’ hat-rack 🎩
Screenshots or videos (if needed)
Checklist