// withHooks // noPage import esp from 'esoftplay/esp'; import React, { useEffect, useRef, useState } from "react"; import { FlatList, Modal, Platform, Pressable, TextInput, View, ViewProps } from "react-native"; export interface LibDropdownArgs { } export interface LibDropdownOption { id: string | number, value: any } export interface LibDropdownProps { value: LibDropdownOption, options: LibDropdownOption[], renderItem: (item: LibDropdownOption, index: number) => any label?: string, fixOffsetTop?: boolean, style?: ViewProps, popupStyle?: ViewProps, maxPopupHeight?: number, } /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/dropdown.md) untuk melihat dokumentasi*/ export default function m(props: LibDropdownProps) { const LibStyle = useRef(esp.mod("lib/style")).current const MAX_HEIGHT = props?.maxPopupHeight || 140; const [currentValue, setCurrentValue] = useState(); const DropdownRef = useRef(null); const [isOpen, setIsOpen] = useState(false); const [popUpSize, setPopUpSize] = useState({ width: 0, top: 0, left: 0, bottom: 0, }); useEffect(() => { setCurrentValue(props.value); setIsOpen(false); }, [props.value]); const togglePopup = () => { DropdownRef.current?.measure((_fx, _fy, _w, h, _px, py) => { setPopUpSize({ width: _w, left: _px, top: py + (props?.style?.height || 40) + (Platform.OS == 'android' ? (props.fixOffsetTop ? -LibStyle.STATUSBAR_HEIGHT : 0) : 0), bottom: py, }); }); setIsOpen(!isOpen); }; return ( setIsOpen(false)} style={{ flex: 1, alignItems: 'center' }}> idx.toString()} renderItem={({ item, index }) => props.renderItem(item, index)} /> ); }