MaskedInput
Mask Input to create custom looking inputs with custom formats
(code example)
info
This component extends TextInput props.
Usageβ
Live Editor
function Example(props) { const [value, setValue] = useState('15'); const renderTimeText = useCallback((value) => { const paddedValue = _.padStart(value, 4, '0'); const hours = paddedValue.substr(0, 2); const minutes = paddedValue.substr(2, 2); return ( <Text text20 grey20 center> {hours} <Text red10>h</Text> {minutes} <Text red10>m</Text> </Text> ); }, []); const formatter = useCallback(value => value?.replace(/\D/g, ''), []); return ( <div> <MaskedInput migrate renderMaskedText={renderTimeText} formatter={formatter} keyboardType={'numeric'} maxLength={4} initialValue={value} // onChangeText={setValue} /> </div> ); }
Result
Loading...
APIβ
containerStyleβ
container style for the masked input container
ViewStyle
renderMaskedTextβ
callback for rendering the custom input out of the value returns from the actual input
React.ReactElement