@momo-kits/stepper 0.0.18-beta-2 → 0.0.19-beta-2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Stepper.js +44 -23
- package/package.json +1 -1
package/Stepper.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React, {Component} from 'react';
|
|
2
|
-
import {View, StyleSheet, TextInput} from 'react-native';
|
|
2
|
+
import {View, StyleSheet, TextInput, Keyboard} from 'react-native';
|
|
3
3
|
import PropTypes from 'prop-types';
|
|
4
4
|
import {Text, Colors, Image, TouchableOpacity} from '@momo-kits/core';
|
|
5
|
+
import {max, min} from 'react-native-reanimated';
|
|
5
6
|
|
|
6
7
|
const minus =
|
|
7
8
|
'https://img.mservice.io/momo_app_v2/new_version/img/appx_icon/24_navigation_minus_circle.png';
|
|
@@ -122,6 +123,22 @@ export default class Quantity extends Component {
|
|
|
122
123
|
};
|
|
123
124
|
}
|
|
124
125
|
|
|
126
|
+
componentDidMount() {
|
|
127
|
+
Keyboard.addListener(
|
|
128
|
+
'keyboardDidHide',
|
|
129
|
+
this.checkData(
|
|
130
|
+
this.state.value,
|
|
131
|
+
'increase',
|
|
132
|
+
this.props.min,
|
|
133
|
+
this.props.max,
|
|
134
|
+
),
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
componentWillUnmount() {
|
|
139
|
+
Keyboard.removeAllListeners('keyboardDidHide');
|
|
140
|
+
}
|
|
141
|
+
|
|
125
142
|
static getDerivedStateFromProps(nextProps, prevState) {
|
|
126
143
|
const {value = undefined} = this?.props || {};
|
|
127
144
|
if (prevState.ownUpdate) {
|
|
@@ -150,26 +167,29 @@ export default class Quantity extends Component {
|
|
|
150
167
|
};
|
|
151
168
|
|
|
152
169
|
setValue = (newValue = 0, type) => {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
);
|
|
164
|
-
};
|
|
170
|
+
this.setState(
|
|
171
|
+
{
|
|
172
|
+
value: newValue,
|
|
173
|
+
ownUpdate: true,
|
|
174
|
+
},
|
|
175
|
+
() => {
|
|
176
|
+
this.onChangeValue(newValue, type);
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
};
|
|
165
180
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
181
|
+
checkData = (value, type, min, max) => () => {
|
|
182
|
+
if (value < min) {
|
|
183
|
+
this.setState({value: min, ownUpdate: true}, () => {
|
|
184
|
+
this.onChangeValue(value, type);
|
|
185
|
+
});
|
|
186
|
+
} else if (value > max) {
|
|
187
|
+
this.setState({value: max, ownUpdate: true}, () => {
|
|
188
|
+
this.onChangeValue(value, type);
|
|
189
|
+
});
|
|
172
190
|
}
|
|
191
|
+
|
|
192
|
+
console.log(value, min, max);
|
|
173
193
|
};
|
|
174
194
|
|
|
175
195
|
onPress =
|
|
@@ -178,10 +198,10 @@ export default class Quantity extends Component {
|
|
|
178
198
|
const {isChangeValue, onConditionCheck} = this.props;
|
|
179
199
|
const {value} = this.state;
|
|
180
200
|
const type = isIncrease ? 'increase' : 'decrease';
|
|
181
|
-
if (isChangeValue) {
|
|
201
|
+
if (isChangeValue && value !== '') {
|
|
182
202
|
const newValue = isIncrease
|
|
183
|
-
? value + this.getValue('increase', step)
|
|
184
|
-
: value - this.getValue('decrease', step);
|
|
203
|
+
? parseInt(value) + this.getValue('increase', step)
|
|
204
|
+
: parseInt(value) - this.getValue('decrease', step);
|
|
185
205
|
if (typeof onConditionCheck === 'function') {
|
|
186
206
|
const passCondition = onConditionCheck(newValue, type);
|
|
187
207
|
if (passCondition) {
|
|
@@ -199,7 +219,6 @@ export default class Quantity extends Component {
|
|
|
199
219
|
const {value} = this.state;
|
|
200
220
|
const {
|
|
201
221
|
style,
|
|
202
|
-
max,
|
|
203
222
|
valueStyle,
|
|
204
223
|
size,
|
|
205
224
|
tintColor,
|
|
@@ -211,6 +230,7 @@ export default class Quantity extends Component {
|
|
|
211
230
|
step,
|
|
212
231
|
} = this.props;
|
|
213
232
|
const {min} = this.props || 1;
|
|
233
|
+
const {max} = this.props || 999;
|
|
214
234
|
if (isSingle && value === 0) {
|
|
215
235
|
return (
|
|
216
236
|
<View style={[styles.container, style]}>
|
|
@@ -246,6 +266,7 @@ export default class Quantity extends Component {
|
|
|
246
266
|
keyboardType="number-pad"
|
|
247
267
|
editable={!disabled}
|
|
248
268
|
onChangeText={text => this.setValue(text)}
|
|
269
|
+
onEndEditing={this.checkData(value, 'increase', min, max)}
|
|
249
270
|
/>
|
|
250
271
|
) : (
|
|
251
272
|
<TextComp weight="bold" style={styles.text}>
|