@hyext-beyond/hy-ui-native
Version:
A native lib polyfill for huya miniapp
38 lines • 1.86 kB
JavaScript
function _extends() { _extends = Object.assign ? Object.assign.bind() : 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, { useCallback } from "react";
import { TouchableOpacity, Text } from "react-native";
import { processMaxLength, processMaxValue } from "../../common/utils";
import { showInputBar } from "../../modules/showInputBar";
var inputStyle = {
padding: 0,
fontSize: 14,
textAlignVertical: "center",
width: "100%"
};
var containerStyle = {
backgroundColor: "#fff",
flexDirection: "row",
alignItems: "center",
height: 30
};
export function MockInput(props) {
var _props$contentProps, _props$contentProps2;
var handleInput = useCallback(function () {
showInputBar({
text: props.value,
placeholder: props.placeholder
}).then(function (res) {
props.onChange(processMaxValue(processMaxLength(res.text, props.maxLength), props.maxValue));
});
}, [props]);
return /*#__PURE__*/React.createElement(TouchableOpacity, {
style: [containerStyle, props.style],
onPress: handleInput
}, props.value !== null && props.value != "" ? /*#__PURE__*/React.createElement(Text, _extends({
style: [inputStyle, props.inputStyle]
}, (_props$contentProps = props.contentProps) !== null && _props$contentProps !== void 0 ? _props$contentProps : {}), props.value) : /*#__PURE__*/React.createElement(Text, _extends({
style: [inputStyle, props.inputStyle, {
color: props.placeholderTextColor || "#ddd"
}]
}, (_props$contentProps2 = props.contentProps) !== null && _props$contentProps2 !== void 0 ? _props$contentProps2 : {}), props.placeholder || "请输入"));
}