Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why we didn't use
PropTypes.instanceOf(BaseFlatList)
in the end?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.
It seems we are using 'React.Component' at many of the forwarded ref component. So it should be fine to replicate the same to have consistency. I am also fine to use to this common refPropTypes created recently https://github.com/Expensify/App/blob/main/src/components/refPropTypes.js#L3
In the approval comment I had mentioned the above #20591 (comment)
It seems at multiple places in the app we are using the same behaviour. Kindly do let me know if we want to change this behaviour.
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.
hmm, I think we should try to have our prop types as tight as possible. This reference is used here for example:
App/src/libs/ReportScrollManager/index.js
Line 19 in 70bf90d
If you start passing around the type
Component
instead ofBaseFlatList
, typescript won't be able to findscrollToIndex
inComponent
.I'm not sure if this complicates things to much, then another option could be to leave this type problems for when we migrate to typescript 🤷
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.
Passing
Component
around when you know it is aFlatList
(orBaseFlatList
) feels to me like usingPropTypes.any
orPropTypes.object
(without specifying the shape of the object)... it works... but then we are missing the purpose of types (type safety)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.
@aldo-expensify I think the main solution proposed here should solve this issue. We should import and use
Flatlist
directly from RN.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.
If it works, I think its better to be more precise about the type, so using
FlatList
(orBaseFlatList
ifFlatList
is not possible) is better IMOThere 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.
@aldo-expensify then we can do the same way as done here from your example
App/src/components/InvertedFlatList/index.js
Lines 3 to 13 in 70bf90d
FlatList is imported to mention it as type. I highly doubt the
current
variable will be of typeBaseFlatList
, it will be of typeFlatList
as it was the original ref.If we do this way when we go to typescript it won't change AFAIK.
It is not a complex change and this was also one of the proposals on the same from @allroundexperts
It just I didn't want to add extra import for type and went with a consistent solution existing in the app.
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.
OOPS. Seems there where same suggestion from @allroundexperts and I also commented the same thing. (Page didn't refresh for me 😮💨 )
Yes. it is possible as mentioned here #21668 (comment)
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.
Ok!, yes use
FlatList
fromreact-native
if possible.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.
Updated @aldo-expensify @abdulrahuman5196!