import React from "react"; import { FlashListProps, FlashList } from "@shopify/flash-list"; import { FlatListProps } from "react-native"; import { FlatList as FlatListComponent } from "react-native-gesture-handler"; import FlatList from "../FlatList"; type ListComponentType = "FlatList" | "FlashList"; interface AdditionalSwipeableListProps { disableScrollWhenSwiping?: boolean; listComponent?: ListComponentType; } export type FlatListSwipeableListProps = FlatListProps & AdditionalSwipeableListProps; export type FlashListSwipeableListProps = FlashListProps & AdditionalSwipeableListProps; type SwipeableListContextType = { onStartSwiping: () => void; onStopSwiping: () => void; }; export const SwipeableListContext = React.createContext({ onStartSwiping: () => {}, onStopSwiping: () => {}, }); const SwipeableList = React.forwardRef( ( { disableScrollWhenSwiping = true, listComponent = "FlatList", ...rest }: FlashListSwipeableListProps | FlatListSwipeableListProps, ref: React.Ref> ) => { const [isSwiping, setIsSwiping] = React.useState(false); const onStartSwiping = () => { setIsSwiping(true); }; const onStopSwiping = () => { setIsSwiping(false); }; rest.scrollEnabled = disableScrollWhenSwiping ? !isSwiping : true; const renderListComponent = () => { switch (listComponent) { case "FlatList": return ( } {...(rest as FlatListProps)} /> ); case "FlashList": return ( )} /> ); } }; return ( <>{renderListComponent()} ); } ); export default SwipeableList;