@bherila/react-native-otp-inputs
Version:
One-time password inputs built in pure JS for React-Native
49 lines (47 loc) • 1.89 kB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React, { useState, useEffect, forwardRef } from 'react';
import { Platform, TextInput, View } from 'react-native';
const majorVersionIOS = parseInt(`${Platform.Version}`, 10);
const isOTPSupported = Platform.OS === 'ios' && majorVersionIOS >= 12;
const OtpInput = /*#__PURE__*/forwardRef(({
focusStyles,
handleKeyPress,
handleTextChange,
inputContainerStyles,
inputStyles,
inputValue,
placeholder,
selectTextOnFocus,
secureTextEntry,
...rest
}, ref) => {
const [focused, setFocused] = useState(false);
useEffect(() => {
var _current;
ref === null || ref === void 0 ? void 0 : (_current = ref.current) === null || _current === void 0 ? void 0 : _current.setNativeProps({
value: inputValue,
text: inputValue
});
}, [ref, inputValue]);
return /*#__PURE__*/React.createElement(View, {
style: [inputContainerStyles, focused && focusStyles]
}, /*#__PURE__*/React.createElement(TextInput, _extends({
onBlur: () => setFocused(false),
onChangeText: handleTextChange,
onFocus: () => setFocused(true),
onKeyPress: handleKeyPress,
placeholder: placeholder,
ref: ref // https://github.com/facebook/react-native/issues/18339
,
selectTextOnFocus: Platform.select({
ios: selectTextOnFocus,
android: true
}),
style: inputStyles,
textContentType: isOTPSupported ? 'oneTimeCode' : 'none',
underlineColorAndroid: "transparent",
secureTextEntry: secureTextEntry
}, rest)));
});
export default /*#__PURE__*/React.memo(OtpInput);
//# sourceMappingURL=OtpInput.js.map