import React, { useState, useEffect, useMemo } from "react"; import { DateRangePicker as YzDateRangePicker } from "@yz1311/react-native-wheel-picker"; import { BottomSheet, Button } from "heroui-native"; import { View, Text } from "react-native"; import dayjs from "dayjs"; import { toDate } from "@/utils/time"; interface DateRangePickerProps { startDate: Date | string; endDate: Date | string; show?: boolean; onClose?: () => void; onConfirm?: (start: string, end: string) => void; } export default function DateRangePicker({ startDate, endDate, show = false, onClose, onConfirm, }: DateRangePickerProps) { const [tempStart, setTempStart] = useState(() => toDate(startDate)); const [tempEnd, setTempEnd] = useState(() => toDate(endDate)); useEffect(() => { setTempStart(toDate(startDate)); setTempEnd(toDate(endDate)); }, [startDate, endDate]); const isOpen = show; const handleClose = () => { onClose?.(); }; const handleCancel = () => { setTempStart(toDate(startDate)); setTempEnd(toDate(endDate)); handleClose(); }; const handleConfirm = () => { const start = dayjs(tempStart).format("YYYY-MM-DD"); const end = dayjs(tempEnd).format("YYYY-MM-DD"); onConfirm?.(start, end); handleClose(); }; const key = useMemo( () => `${dayjs(startDate).format("YYYY-MM-DD")}_${dayjs(endDate).format("YYYY-MM-DD")}`, [startDate, endDate], ); return ( { if (!v) handleClose(); }} > {/* Header */} 选择日期区间 {/* Range Picker */} { setTempStart(start); setTempEnd(end); }} /> ); }