1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 |
|
7 | var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
8 |
|
9 | var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
10 |
|
11 | var _createClass2 = require('babel-runtime/helpers/createClass');
|
12 |
|
13 | var _createClass3 = _interopRequireDefault(_createClass2);
|
14 |
|
15 | var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
|
16 |
|
17 | var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
|
18 |
|
19 | var _inherits2 = require('babel-runtime/helpers/inherits');
|
20 |
|
21 | var _inherits3 = _interopRequireDefault(_inherits2);
|
22 |
|
23 | var _react = require('react');
|
24 |
|
25 | var _react2 = _interopRequireDefault(_react);
|
26 |
|
27 | var _reactNative = require('react-native');
|
28 |
|
29 | var _base = require('./base');
|
30 |
|
31 | var _base2 = _interopRequireDefault(_base);
|
32 |
|
33 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
|
34 |
|
35 | var InputNumber = function (_BaseComponent) {
|
36 | (0, _inherits3['default'])(InputNumber, _BaseComponent);
|
37 |
|
38 | function InputNumber() {
|
39 | (0, _classCallCheck3['default'])(this, InputNumber);
|
40 |
|
41 | var _this = (0, _possibleConstructorReturn3['default'])(this, (InputNumber.__proto__ || Object.getPrototypeOf(InputNumber)).apply(this, arguments));
|
42 |
|
43 | _this.onPressInDown = function (e) {
|
44 | _this.onPressIn('_stepDown');
|
45 | _this.down(e, true);
|
46 | };
|
47 | _this.onPressOutDown = function () {
|
48 | _this.onPressOut('_stepDown');
|
49 | _this.stop();
|
50 | };
|
51 | _this.onPressInUp = function (e) {
|
52 | _this.onPressIn('_stepUp');
|
53 | _this.up(e, true);
|
54 | };
|
55 | _this.onPressOutUp = function () {
|
56 | _this.onPressOut('_stepUp');
|
57 | _this.stop();
|
58 | };
|
59 | return _this;
|
60 | }
|
61 |
|
62 | (0, _createClass3['default'])(InputNumber, [{
|
63 | key: 'onPressIn',
|
64 | value: function onPressIn(type) {
|
65 | if (this.props.disabled) {
|
66 | return;
|
67 | }
|
68 | var styles = this.props.styles;
|
69 |
|
70 | this[type].setNativeProps({
|
71 | style: [styles.stepWrap, styles.highlightStepBorderColor]
|
72 | });
|
73 | this[type + 'Text'].setNativeProps({
|
74 | style: [styles.stepText, styles.highlightStepTextColor]
|
75 | });
|
76 | }
|
77 | }, {
|
78 | key: 'onPressOut',
|
79 | value: function onPressOut(type) {
|
80 | if (this.props.disabled) {
|
81 | return;
|
82 | }
|
83 | var styles = this.props.styles;
|
84 |
|
85 | this[type].setNativeProps({
|
86 | style: [styles.stepWrap]
|
87 | });
|
88 | this[type + 'Text'].setNativeProps({
|
89 | style: [styles.stepText]
|
90 | });
|
91 | }
|
92 | }, {
|
93 | key: 'getValueFromEvent',
|
94 | value: function getValueFromEvent(e) {
|
95 | return e.nativeEvent.text;
|
96 | }
|
97 | }, {
|
98 | key: 'render',
|
99 | value: function render() {
|
100 | var _this2 = this;
|
101 |
|
102 | var props = this.props,
|
103 | state = this.state;
|
104 | var _props = this.props,
|
105 | style = _props.style,
|
106 | upStyle = _props.upStyle,
|
107 | downStyle = _props.downStyle,
|
108 | inputStyle = _props.inputStyle,
|
109 | styles = _props.styles;
|
110 |
|
111 | var editable = !this.props.readOnly && !this.props.disabled;
|
112 | var upDisabledStyle = null;
|
113 | var downDisabledStyle = null;
|
114 | var upDisabledTextStyle = null;
|
115 | var downDisabledTextStyle = null;
|
116 | var value = +state.value;
|
117 | if (!isNaN(value)) {
|
118 | var val = Number(value);
|
119 | if (val >= props.max) {
|
120 | upDisabledStyle = styles.stepDisabled;
|
121 | upDisabledTextStyle = styles.disabledStepTextColor;
|
122 | }
|
123 | if (val <= props.min) {
|
124 | downDisabledStyle = styles.stepDisabled;
|
125 | downDisabledTextStyle = styles.disabledStepTextColor;
|
126 | }
|
127 | } else {
|
128 | upDisabledStyle = styles.stepDisabled;
|
129 | downDisabledStyle = styles.stepDisabled;
|
130 | upDisabledTextStyle = styles.disabledStepTextColor;
|
131 | downDisabledTextStyle = styles.disabledStepTextColor;
|
132 | }
|
133 | var inputDisabledStyle = null;
|
134 | if (props.disabled) {
|
135 | upDisabledStyle = styles.stepDisabled;
|
136 | downDisabledStyle = styles.stepDisabled;
|
137 | upDisabledTextStyle = styles.disabledStepTextColor;
|
138 | downDisabledTextStyle = styles.disabledStepTextColor;
|
139 | inputDisabledStyle = styles.disabledStepTextColor;
|
140 | }
|
141 | var inputDisplayValue = void 0;
|
142 | if (state.focused) {
|
143 | inputDisplayValue = '' + state.inputValue;
|
144 | } else {
|
145 | inputDisplayValue = '' + state.value;
|
146 | }
|
147 | if (inputDisplayValue === undefined) {
|
148 | inputDisplayValue = '';
|
149 | }
|
150 | return _react2['default'].createElement(
|
151 | _reactNative.View,
|
152 | { style: [styles.container, style] },
|
153 | _react2['default'].createElement(
|
154 | _reactNative.TouchableWithoutFeedback,
|
155 | { onPressIn: editable && !downDisabledStyle ? this.onPressInDown : undefined, onPressOut: editable && !downDisabledStyle ? this.onPressOutDown : undefined, accessible: true, accessibilityLabel: 'Decrease Value', accessibilityComponentType: 'button', accessibilityTraits: editable && !downDisabledStyle ? 'button' : 'disabled' },
|
156 | _react2['default'].createElement(
|
157 | _reactNative.View,
|
158 | { ref: function ref(component) {
|
159 | return _this2._stepDown = component;
|
160 | }, style: [styles.stepWrap, downDisabledStyle, downStyle] },
|
161 | _react2['default'].createElement(
|
162 | _reactNative.Text,
|
163 | { ref: function ref(component) {
|
164 | return _this2._stepDownText = component;
|
165 | }, style: [styles.stepText, downDisabledTextStyle] },
|
166 | '-'
|
167 | )
|
168 | )
|
169 | ),
|
170 | _react2['default'].createElement(_reactNative.TextInput, { style: [styles.input, inputDisabledStyle, inputStyle], value: inputDisplayValue, autoFocus: props.autoFocus, editable: editable, onFocus: this.onFocus, onEndEditing: this.onBlur, onChange: this.onChange, underlineColorAndroid: 'transparent', keyboardType: props.keyboardType }),
|
171 | _react2['default'].createElement(
|
172 | _reactNative.TouchableWithoutFeedback,
|
173 | { onPressIn: editable && !upDisabledStyle ? this.onPressInUp : undefined, onPressOut: editable && !upDisabledStyle ? this.onPressOutUp : undefined, accessible: true, accessibilityLabel: 'Increase Value', accessibilityComponentType: 'button', accessibilityTraits: editable && !upDisabledStyle ? 'button' : 'disabled' },
|
174 | _react2['default'].createElement(
|
175 | _reactNative.View,
|
176 | { ref: function ref(component) {
|
177 | return _this2._stepUp = component;
|
178 | }, style: [styles.stepWrap, upDisabledStyle, upStyle] },
|
179 | _react2['default'].createElement(
|
180 | _reactNative.Text,
|
181 | { ref: function ref(component) {
|
182 | return _this2._stepUpText = component;
|
183 | }, style: [styles.stepText, upDisabledTextStyle] },
|
184 | '+'
|
185 | )
|
186 | )
|
187 | )
|
188 | );
|
189 | }
|
190 | }]);
|
191 | return InputNumber;
|
192 | }(_base2['default']);
|
193 |
|
194 | exports['default'] = InputNumber;
|
195 | module.exports = exports['default']; |
\ | No newline at end of file |