-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adds ListView Higher Order Component
Displays a FlashList or FlatList depending on language RTL features. Needs a little more work on the `ref` passing.
- Loading branch information
1 parent
2630214
commit 1e85d88
Showing
8 changed files
with
58 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React, { forwardRef, PropsWithoutRef } from "react" | ||
import { FlatList } from "react-native" | ||
import { isRTL } from "app/i18n" | ||
import { FlashList, FlashListProps } from "@shopify/flash-list" | ||
|
||
export interface ListViewProps<T> extends PropsWithoutRef<FlashListProps<T>> {} | ||
|
||
/** | ||
* This is a Higher Order Component meant to ease the pain of using @shopify/flash-list | ||
* when there is a chance that a user would have their device language set to an | ||
* RTL language like Arabic or Punjabi. This component will use react-native's | ||
* FlatList if the user's language is RTL or FlashList if the user's language is LTR. | ||
* | ||
* Because FlashList's props are a superset of FlatList's, you must pass estimatedItemSize | ||
* to this component if you want to use it. | ||
* | ||
* This is a temporary workaround until the FlashList component supports RTL at | ||
* which point this component can be removed and we will default to using FlashList everywhere. | ||
* | ||
* @see {@link https://github.com/Shopify/flash-list/issues/544|RTL Bug Android} | ||
* @see {@link https://github.com/Shopify/flash-list/issues/840|Flashlist Not Support RTL} | ||
* | ||
* @param props - FlashListProps | ||
* @param forwardRef - React.ForwardedRef<FlashList<T>> | ||
* @returns JSX.Element | ||
*/ | ||
export const ListView = forwardRef( | ||
<T,>(props: ListViewProps<T>, forwardRef: React.ForwardedRef<FlashList<T>>) => { | ||
const ListComponentWrapper = isRTL ? FlatList : FlashList | ||
|
||
return <ListComponentWrapper {...props} ref={forwardRef} /> | ||
}, | ||
) as <T>(props: ListViewProps<T>, ref: React.ForwardedRef<FlashList<T>>) => JSX.Element |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# ListView Component | ||
|
||
The `ListView` component is a Higher Order Component that uses [Shopify's FlashList](https://shopify.github.io/flash-list/) component to display a list unless the user's preferred language is RTL (right-to-left). This is because FlashList has [known](https://github.com/Shopify/flash-list/issues/544) [issues](https://github.com/Shopify/flash-list/issues/840) with RTL support. Once these issues with FlashList are resolved, this component will be deprecated and FlashList will be used directly. | ||
|
||
## Props | ||
|
||
The `ListView` component uses props from `FlashList` because they are a superset of `FlatList` and only require one extra prop to work for both component types. | ||
|
||
> [Please see the FlashList documentation for more information on the props that are available.](https://shopify.github.io/flash-list/docs/usage) | ||
### `estimatedItemSize` | ||
|
||
> [Please see the FlashList documentation for more information on this prop.](https://shopify.github.io/flash-list/docs/estimated-item-size) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters