// withHooks // noPage import { LibScrollpicker } from 'esoftplay/cache/lib/scrollpicker/import'; import { LibStyle } from 'esoftplay/cache/lib/style/import'; import useSafeState from 'esoftplay/state'; import { LinearGradient } from 'expo-linear-gradient'; import React, { useEffect, useRef } from 'react'; import { Text, TouchableOpacity, View } from 'react-native'; type TimeFormat= `${number}:${number}:${number}` export interface LibTimepickerProps { /* hh:mm:ss */ selectedTime: TimeFormat, onTimeChange: (second: TimeFormat) => void, /* hh:mm:ss */ minTime?: TimeFormat, /* hh:mm:ss */ maxTime?: TimeFormat, mode?: 24 | 12, /* hh:mm:ss */ type?: "hour" | "hourMinute" | "hourMinuteSecond" } /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/timepicker.md) untuk melihat dokumentasi*/ export default function m(props: LibTimepickerProps): any { const _mode = props.mode || 24 const refHour = useRef(null) const refMinute = useRef(null) const refSecond = useRef(null) const t24 = _mode == 12 ? ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11"] : ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"] const t60 = ["00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59"] const time = { hours: t24, minutes: t60, seconds: t60 } const minTime = props.minTime const maxTime = props.maxTime const type = props.type || "hourMinuteSecond" const [selectedTime, setSelectedTime] = useSafeState(props.selectedTime || minTime) let sHour = selectedTime.split(':')[0] let sMinute = selectedTime.split(':')[1] let sSecond = selectedTime.split(':')[2] let showHour = (type == 'hour') || (type == 'hourMinute') || (type == 'hourMinuteSecond'); let showHourMinute = (type == 'hourMinuteSecond') || (type == 'hourMinute'); let showHourMinuteSecond = type == 'hourMinuteSecond'; function scrollTo(time: string) { refHour?.current?.scrollToIndex(t24.indexOf(time.split(':')[0])) refMinute?.current?.scrollToIndex(t60.indexOf(time.split(':')[1])) refSecond?.current?.scrollToIndex(t60.indexOf(time.split(':')[2])) } useEffect(() => { if (selectedTime) { let toTime: any = null if (maxTime && selectedTime > maxTime) { toTime = maxTime; } else if (minTime && selectedTime < minTime) { toTime = minTime; } if (toTime != null) { scrollTo(toTime); setSelectedTime(toTime); } } }, [selectedTime]) function itemRenderer(data: any, index: number, isSelected: boolean) { return ( {data} ) } return ( { props.onTimeChange(selectedTime) }} > Done setSelectedTime(value + ':' + sMinute + ":" + sSecond)} /> : setSelectedTime(sHour + ':' + value + ":" + sSecond)} /> : setSelectedTime(sHour + ':' + sMinute + ":" + value)} /> ) }