one
Version:
One is a React framework for web, iOS, and Android apps.
94 lines (92 loc) • 4.46 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all) __defProp(target, name, {
get: all[name],
enumerable: true
});
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var index_ios_exports = {};
__export(index_ios_exports, { TextInput: () => TextInput });
module.exports = __toCommonJS(index_ios_exports);
var import_jsx_runtime = require("react/jsx-runtime");
var import_react = require("react");
var import_Controls = require("../../generated/Controls.native.js");
var import_syncNativeState = require("../../syncNativeState.native.js");
var import_textInputShared = require("./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 = (0, import_textInputShared.resolveEditable)(editableProp, readOnly);
var keyboardType = keyboardTypeProp !== null && keyboardTypeProp !== void 0 ? keyboardTypeProp : (0, import_textInputShared.inputModeToKeyboardType)(inputMode);
var returnKeyType = returnKeyTypeProp !== null && returnKeyTypeProp !== void 0 ? returnKeyTypeProp : (0, import_textInputShared.enterKeyHintToReturnKeyType)(enterKeyHint);
var initialFallbackRef = (0, import_react.useRef)(defaultValue !== null && defaultValue !== void 0 ? defaultValue : "");
var fallback = (0, import_syncNativeState.useNativeState)(initialFallbackRef.current);
var state = value !== null && value !== void 0 ? value : fallback;
var { focused, focusRevision, focus, blur, isFocused, handleFocusChange } = (0, import_textInputShared.useTextInputFocus)({
autoFocus,
editable,
onFocus,
onBlur
});
(0, import_react.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 = (0, import_textInputShared.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 ? (0, import_textInputShared.iosSubmitLabel)(returnKeyType) : void 0,
textInputAutocapitalization: autoCapitalize === "none" ? "never" : autoCapitalize,
autocorrectionDisabled: autoCorrect === false,
keyboardType: keyboardType ? (0, import_textInputShared.iosKeyboardType)(keyboardType) : void 0,
textContentType: (0, import_textInputShared.autoCompleteToTextContentType)(autoComplete),
testID,
style
};
if (secureTextEntry) {
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Controls.SecureField, { ...fieldProps });
}
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_Controls.TextField, {
...fieldProps,
axis: multiline ? "vertical" : "horizontal"
});
}