@ant-design/react-native
Version:
基于蚂蚁金服移动设计规范的 React Native 组件库
62 lines (56 loc) • 2.44 kB
JavaScript
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';
export default function (ComposedComponent) {
var _a;
return _a = function (_React$Component) {
_inherits(_a, _React$Component);
function _a() {
_classCallCheck(this, _a);
var _this = _possibleConstructorReturn(this, (_a.__proto__ || Object.getPrototypeOf(_a)).apply(this, arguments));
_this.getValue = function () {
var _this$props = _this.props,
children = _this$props.children,
selectedValue = _this$props.selectedValue;
if (selectedValue && selectedValue.length) {
return selectedValue;
} else {
if (!children) {
return [];
}
return React.Children.map(children, function (c) {
var cc = React.Children.toArray(c.children || c.props.children);
return cc && cc[0] && cc[0].props.value;
});
}
};
_this.onChange = function (i, v, cb) {
var value = _this.getValue().concat();
value[i] = v;
if (cb) {
cb(value, i);
}
};
_this.onValueChange = function (i, v) {
_this.onChange(i, v, _this.props.onValueChange);
};
_this.onScrollChange = function (i, v) {
_this.onChange(i, v, _this.props.onScrollChange);
};
return _this;
}
_createClass(_a, [{
key: 'render',
value: function render() {
return React.createElement(ComposedComponent, _extends({}, this.props, { getValue: this.getValue, onValueChange: this.onValueChange, onScrollChange: this.props.onScrollChange && this.onScrollChange }));
}
}]);
return _a;
}(React.Component), _a.defaultProps = {
prefixCls: 'rmc-multi-picker',
onValueChange: function onValueChange() {}
}, _a;
}