UNPKG

@ant-design/react-native

Version:

基于蚂蚁金服移动设计规范的 React Native 组件库

71 lines (63 loc) 2.27 kB
import _extends from 'babel-runtime/helpers/extends'; import _classCallCheck from 'babel-runtime/helpers/classCallCheck'; import _createClass from 'babel-runtime/helpers/createClass'; import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn'; import _inherits from 'babel-runtime/helpers/inherits'; import React from 'react'; import { TextInput } from 'react-native'; var Input = function (_React$Component) { _inherits(Input, _React$Component); function Input(props) { _classCallCheck(this, Input); var _this = _possibleConstructorReturn(this, (Input.__proto__ || Object.getPrototypeOf(Input)).call(this, props)); _this.focus = function () { if (_this.inputRef) { _this.inputRef.focus(); } }; _this.clear = function () { if (_this.inputRef) { _this.inputRef.clear(); } }; // todos: remove focused in next major version. _this.state = { focused: props.focused || false }; return _this; } _createClass(Input, [{ key: 'UNSAFE_componentWillReceiveProps', value: function UNSAFE_componentWillReceiveProps(nextProps) { if (nextProps.focused !== this.state.focused) { this.setState({ focused: nextProps.focused }); } } }, { key: 'componentDidMount', value: function componentDidMount() { if (this.inputRef && (this.props.autoFocus || this.props.focused)) { this.inputRef.focus(); } } }, { key: 'componentDidUpdate', value: function componentDidUpdate() { if (this.inputRef && this.props.focused) { this.inputRef.focus(); } } }, { key: 'render', value: function render() { var _this2 = this; return React.createElement(TextInput, _extends({ ref: function ref(el) { return _this2.inputRef = el; }, underlineColorAndroid: 'transparent' }, this.props)); } }]); return Input; }(React.Component); export default Input;