Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions src/WheelPicker.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import React, { ComponentType, MutableRefObject, useEffect, useMemo, useRef, useState } from 'react';
import {
StyleProp,
TextStyle,
Expand Down Expand Up @@ -30,6 +30,7 @@ interface Props {
visibleRest?: number;
decelerationRate?: 'normal' | 'fast' | number;
flatListProps?: Omit<FlatListProps<string | null>, 'data' | 'renderItem'>;
flatListComponent?: ComponentType<FlatListProps<string | null> | { ref: MutableRefObject<any> }>
}

const WheelPicker: React.FC<Props> = ({
Expand All @@ -48,8 +49,9 @@ const WheelPicker: React.FC<Props> = ({
decelerationRate = 'fast',
containerProps = {},
flatListProps = {},
flatListComponent = null
}) => {
const flatListRef = useRef<FlatList>(null);
const flatListRef = useRef<any>(null);
const [scrollY] = useState(new Animated.Value(0));

const containerHeight = (1 + visibleRest * 2) * itemHeight;
Expand Down Expand Up @@ -113,6 +115,8 @@ const WheelPicker: React.FC<Props> = ({
});
}, [selectedIndex]);

const CustomFlatList = flatListComponent || Animated.FlatList<string | null>

return (
<View
style={[styles.container, { height: containerHeight }, containerStyle]}
Expand All @@ -128,8 +132,7 @@ const WheelPicker: React.FC<Props> = ({
},
]}
/>
<Animated.FlatList<string | null>
{...flatListProps}
<CustomFlatList
ref={flatListRef}
style={styles.scrollView}
showsVerticalScrollIndicator={false}
Expand Down Expand Up @@ -163,6 +166,7 @@ const WheelPicker: React.FC<Props> = ({
visibleRest={visibleRest}
/>
)}
{...flatListProps}
/>
</View>
);
Expand Down