UNPKG

one

Version:

One is a React framework for web, iOS, and Android apps.

68 lines (65 loc) • 2.73 kB
import { jsx } from "react/jsx-runtime"; import { useImperativeHandle, useRef } from "react"; import { Compose } from "../../compose.android.js"; import { useNativeState } from "../../syncNativeState.native.js"; import { androidImeAction, androidKeyboardType, enterKeyHintToReturnKeyType, inputModeToKeyboardType, resolveEditable, useTextInputFocus } from "./textInputShared.native.js"; function TextInput(param) { var { ref, value, onChangeText, placeholder, autoFocus, editable: editableProp, readOnly, multiline, keyboardType: keyboardTypeProp, autoCapitalize, autoCorrect, returnKeyType: returnKeyTypeProp, inputMode, enterKeyHint, onSubmitEditing, onFocus, onBlur, defaultValue, testID, style, secureTextEntry, maxLength, textAlign } = param; var editable = resolveEditable(editableProp, readOnly); var keyboardType = keyboardTypeProp !== null && keyboardTypeProp !== void 0 ? keyboardTypeProp : inputModeToKeyboardType(inputMode); var returnKeyType = returnKeyTypeProp !== null && returnKeyTypeProp !== void 0 ? returnKeyTypeProp : enterKeyHintToReturnKeyType(enterKeyHint); var initialFallbackRef = useRef(defaultValue !== null && defaultValue !== void 0 ? defaultValue : ""); var fallback = useNativeState(initialFallbackRef.current); var state = value !== null && value !== void 0 ? value : fallback; var { focused, focusRevision, focus, blur, isFocused, handleFocusChange } = useTextInputFocus({ autoFocus, editable, onFocus, onBlur }); useImperativeHandle(ref, function() { return { focus, blur, clear: function clear() { state.set(""); }, isFocused, setSelection: function setSelection(start, end) { void start; void end; console.warn("TextInput.setSelection() is not supported on Android yet: it needs a TextFieldValue-backed field. This call was ignored."); return Promise.resolve(); } }; }, [state]); return /* @__PURE__ */ jsx(Compose.TextField, { text: state, onTextChange: function onTextChange(text) { return onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(text); }, placeholder, disabled: !editable, secureText: secureTextEntry, focused, focusRevision, onFocusChange: handleFocusChange, keyboardType: keyboardType ? androidKeyboardType(keyboardType) : void 0, imeAction: returnKeyType ? androidImeAction(returnKeyType) : void 0, onSubmit: onSubmitEditing ? function() { return onSubmitEditing(state.value); } : void 0, maxLength, multiline, capitalization: autoCapitalize, autoCorrect, textAlign: textAlign === "auto" ? void 0 : textAlign, testID, style: [{ width: "100%", minHeight: 56 }, style] }); } export { TextInput }; //# sourceMappingURL=index.android.js.map