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

[1/2] Make FlatList permissive of ArrayLike data #36236

Closed
wants to merge 1 commit into from

Commits on Feb 22, 2023

  1. Make FlatList permissive of ArrayLike data (facebook#36236)

    Summary:
    Pull Request resolved: facebook#36236
    
    D38198351 (facebook@d574ea3) addedd a guard to FlatList, to no-op if passed `data` that was not an array. This broke functionality where Realm had documented using `Realm.Results` with FlatList. `Real.Results` is an array-like JSI object, but not actually an array, and fails any `Array.isArray()` checks.
    
    This change loosens the FlatList contract, to explicitly allow array-like non-array entities. The requirement align to Flow `ArrayLike`, which allows both arrays, and objects which provide a length and indexer. Flow `$ArrayLike` currently also requires an iterator, but this is seemingly a mistake in the type definition, and not enforced.
    
    Though `Realm.Results` has all the methods of TS `ReadonlyArray`, RN has generally assumes its array inputs will pass `Array.isArray()`. This includes any array props still being checked [via prop-types](https://github.com/facebook/prop-types/blob/044efd7a108556c7660f6b62092756666e39d74b/factoryWithTypeCheckers.js#L548).
    
    This change intentionally does not yet change the parameter type of `getItemLayout()`, which is already too loose (allowing mutable arrays). Changing this is a breaking change, that would be disruptive to backport, so we separate it into a different commit that will be landed as part of 0.72 (see next diff in the stack).
    
    Changelog:
    [General][Changed] - Make FlatList permissive of ArrayLike data
    
    Differential Revision: D43465654
    
    fbshipit-source-id: 73acd565a51dd7dce693fcab9ed06b63284c97df
    NickGerleman authored and facebook-github-bot committed Feb 22, 2023
    Configuration menu
    Copy the full SHA
    c318f27 View commit details
    Browse the repository at this point in the history