UNPKG

one

Version:

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

73 lines (70 loc) • 3.38 kB
import { jsx } from "react/jsx-runtime"; import { useImperativeHandle, useRef } from "react"; import { SecureField, TextField } from "../../generated/Controls.native.js"; import { useNativeState } from "../../syncNativeState.native.js"; import { applyMaxLength, autoCompleteToTextContentType, enterKeyHintToReturnKeyType, inputModeToKeyboardType, iosKeyboardType, iosSubmitLabel, 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, autoComplete, maxLength } = 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(secureTextEntry ? "TextInput.setSelection() was ignored: SwiftUI's SecureField doesn't expose programmatic selection. Remove `secureTextEntry` if you need to apply selection changes." : "TextInput.setSelection() is not supported on iOS yet: it needs a UITextField-backed field. This call was ignored."); return Promise.resolve(); } }; }, [secureTextEntry, state]); var handleTextChange = function handleTextChange2(text) { var next = applyMaxLength(text, maxLength); if (next !== text) state.set(next); onChangeText === null || onChangeText === void 0 ? void 0 : onChangeText(next); }; var handleSubmit = function handleSubmit2() { onSubmitEditing === null || onSubmitEditing === void 0 ? void 0 : onSubmitEditing(state.value); }; var fieldProps = { text: state, onTextChange: handleTextChange, focused, onFocusChange: handleFocusChange, focusRevision, onSubmit: onSubmitEditing ? handleSubmit : void 0, prompt: placeholder, disabled: !editable, submitLabel: returnKeyType ? iosSubmitLabel(returnKeyType) : void 0, textInputAutocapitalization: autoCapitalize === "none" ? "never" : autoCapitalize, autocorrectionDisabled: autoCorrect === false, keyboardType: keyboardType ? iosKeyboardType(keyboardType) : void 0, textContentType: autoCompleteToTextContentType(autoComplete), testID, style }; if (secureTextEntry) { return /* @__PURE__ */ jsx(SecureField, { ...fieldProps }); } return /* @__PURE__ */ jsx(TextField, { ...fieldProps, axis: multiline ? "vertical" : "horizontal" }); } export { TextInput }; //# sourceMappingURL=index.ios.js.map