// withHooks // noPage import { useEffect, useRef, useState } from 'react'; import { TextInput, View, ViewStyle } from 'react-native'; export interface LibPinProps { length: number, onChangePin: (pin: string) => void boxStyle?: ViewStyle, overrideKeyboard?: boolean, pinValue?: string, pinStyle?: ViewStyle } /** Klik [disini](https://github.com/dev-esoftplay/mobile-docs/blob/main/modules/lib/pin.md) untuk melihat dokumentasi*/ export default function m(props: LibPinProps): any { const [pin, setPin] = useState([]) const input = useRef(null) useEffect(() => { const timer = setTimeout(() => { input?.current?.focus() ; clearTimeout(timer)}, 100); setPin(props?.pinValue?.split?.('')) props.onChangePin(props?.pinValue || '') }, [props.pinValue]) return ( { new Array(props.length).fill('').map((_, i) => ( {!!pin?.[i] && } )) } { !props.overrideKeyboard && { if (t.length == props.length) { input.current?.blur() } let _t: string[] = t.split('') setPin(_t) props.onChangePin(t) }} maxLength={props.length} /> } ) }