Skip to content

Commit

Permalink
Pass RNGH props to FlatList's underlying ScrollView (#1557)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakub-gonet authored Aug 13, 2021
1 parent 60ed14d commit 534bd1d
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions src/components/GestureComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ import {

import createNativeWrapper from '../handlers/createNativeWrapper';

import { NativeViewGestureHandlerProps } from '../handlers/NativeViewGestureHandler';
import {
NativeViewGestureHandlerProps,
nativeViewProps,
} from '../handlers/NativeViewGestureHandler';

export const ScrollView = createNativeWrapper<
PropsWithChildren<RNScrollViewProps>
Expand Down Expand Up @@ -52,13 +55,32 @@ export const DrawerLayoutAndroid = createNativeWrapper<
export type DrawerLayoutAndroid = typeof DrawerLayoutAndroid &
RNDrawerLayoutAndroid;

export const FlatList = React.forwardRef((props, ref) => (
<RNFlatList
ref={ref}
{...props}
renderScrollComponent={(scrollProps) => <ScrollView {...scrollProps} />}
/>
)) as <ItemT = any>(
export const FlatList = React.forwardRef((props, ref) => {
const flatListProps = {};
const scrollViewProps = {};
for (const [propName, value] of Object.entries(props)) {
// https://github.com/microsoft/TypeScript/issues/26255
if ((nativeViewProps as readonly string[]).includes(propName)) {
// @ts-ignore - this function cannot have generic type so we have to ignore this error
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
scrollViewProps[propName] = value;
} else {
// @ts-ignore - this function cannot have generic type so we have to ignore this error
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
flatListProps[propName] = value;
}
}
return (
// @ts-ignore - this function cannot have generic type so we have to ignore this error
<RNFlatList
ref={ref}
{...flatListProps}
renderScrollComponent={(scrollProps) => (
<ScrollView {...{ ...scrollProps, ...scrollViewProps }} />
)}
/>
);
}) as <ItemT = any>(
props: PropsWithChildren<
RNFlatListProps<ItemT> &
RefAttributes<FlatList<ItemT>> &
Expand Down

0 comments on commit 534bd1d

Please sign in to comment.