@momo-kits/auto-complete 0.0.59-beta → 0.0.59-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/AutoComplete.js +149 -94
- package/package.json +14 -14
- package/publish.sh +2 -2
package/AutoComplete.js
CHANGED
|
@@ -6,12 +6,16 @@ import {
|
|
|
6
6
|
StyleSheet,
|
|
7
7
|
UIManager,
|
|
8
8
|
View,
|
|
9
|
-
Platform
|
|
9
|
+
Platform,
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import { get } from 'lodash';
|
|
12
12
|
import PropTypes from 'prop-types';
|
|
13
13
|
import {
|
|
14
|
-
ValueUtil,
|
|
14
|
+
ValueUtil,
|
|
15
|
+
NumberUtils,
|
|
16
|
+
Colors,
|
|
17
|
+
Text,
|
|
18
|
+
RNGestureHandler,
|
|
15
19
|
} from '@momo-kits/core';
|
|
16
20
|
|
|
17
21
|
const { TouchableOpacity } = RNGestureHandler;
|
|
@@ -31,26 +35,34 @@ export default class AutoComplete extends Component {
|
|
|
31
35
|
measure() {
|
|
32
36
|
try {
|
|
33
37
|
if (this.hashmapRefs) {
|
|
34
|
-
Object.keys(this.hashmapRefs)
|
|
35
|
-
.
|
|
36
|
-
|
|
37
|
-
|
|
38
|
+
Object.keys(this.hashmapRefs).forEach((key) => {
|
|
39
|
+
if (Platform.OS === 'android') {
|
|
40
|
+
UIManager.measureLayoutRelativeToParent(
|
|
41
|
+
findNodeHandle(this.hashmapRefs[key]),
|
|
42
|
+
(e) => {
|
|
43
|
+
console.error(e);
|
|
44
|
+
},
|
|
45
|
+
(x, y, width, height) => {
|
|
38
46
|
this.hashmapPosition[key] = {
|
|
39
47
|
x,
|
|
40
48
|
y: y + height,
|
|
41
|
-
width
|
|
49
|
+
width,
|
|
42
50
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
},
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
UIManager.measure(
|
|
55
|
+
findNodeHandle(this.hashmapRefs[key]),
|
|
56
|
+
(x, y, width, height) => {
|
|
46
57
|
this.hashmapPosition[key] = {
|
|
47
58
|
x,
|
|
48
59
|
y: y + height,
|
|
49
|
-
width
|
|
60
|
+
width,
|
|
50
61
|
};
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
}
|
|
62
|
+
},
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
});
|
|
54
66
|
}
|
|
55
67
|
} catch (e) {
|
|
56
68
|
console.log(`try catch :: ${e}`);
|
|
@@ -66,8 +78,22 @@ export default class AutoComplete extends Component {
|
|
|
66
78
|
|
|
67
79
|
getValueByKey = (key, value) => {
|
|
68
80
|
const splitKey = key.split('-');
|
|
69
|
-
return splitKey.length > 1
|
|
70
|
-
|
|
81
|
+
return splitKey.length > 1
|
|
82
|
+
? splitKey.reduce(
|
|
83
|
+
(result, item, index) =>
|
|
84
|
+
(result =
|
|
85
|
+
result +
|
|
86
|
+
value[item] +
|
|
87
|
+
(index === splitKey.length - 1
|
|
88
|
+
? ''
|
|
89
|
+
: !!value[item]
|
|
90
|
+
? ' '
|
|
91
|
+
: '')),
|
|
92
|
+
'',
|
|
93
|
+
)
|
|
94
|
+
: key === 'phone'
|
|
95
|
+
? NumberUtils.formatPhoneNumberVN(value[key])
|
|
96
|
+
: value[key];
|
|
71
97
|
};
|
|
72
98
|
|
|
73
99
|
/**
|
|
@@ -78,36 +104,50 @@ export default class AutoComplete extends Component {
|
|
|
78
104
|
if (components) {
|
|
79
105
|
return React.Children.map(components, (child) => {
|
|
80
106
|
if (!child?.props) return child;
|
|
81
|
-
if (
|
|
107
|
+
if (
|
|
108
|
+
child?.props?.children &&
|
|
109
|
+
React.Children.count(child?.props?.children) > 0 &&
|
|
110
|
+
child.type.name !== Text
|
|
111
|
+
) {
|
|
82
112
|
// component have children -> clone it and all it's children
|
|
83
113
|
return React.cloneElement(child, {
|
|
84
|
-
children: this.cloneChildren(child.props.children)
|
|
114
|
+
children: this.cloneChildren(child.props.children),
|
|
85
115
|
});
|
|
86
116
|
}
|
|
87
117
|
|
|
88
|
-
const {
|
|
89
|
-
|
|
90
|
-
keyAutoComplete,
|
|
91
|
-
onFocus,
|
|
92
|
-
onEndEditing
|
|
93
|
-
} = child.props;
|
|
118
|
+
const { onChangeText, keyAutoComplete, onFocus, onEndEditing } =
|
|
119
|
+
child.props;
|
|
94
120
|
if (keyAutoComplete) {
|
|
95
121
|
// Update props when component have keyAutoComplete
|
|
96
122
|
if (this.selectedItem) {
|
|
97
|
-
this.hashmapInputValue[keyAutoComplete] =
|
|
123
|
+
this.hashmapInputValue[keyAutoComplete] =
|
|
124
|
+
this.getValueByKey(
|
|
125
|
+
keyAutoComplete,
|
|
126
|
+
this.selectedItem,
|
|
127
|
+
); // this.selectedItem[keyAutoComplete];
|
|
98
128
|
return React.cloneElement(child, {
|
|
99
|
-
ref: (view) =>
|
|
100
|
-
|
|
129
|
+
ref: (view) =>
|
|
130
|
+
(this.hashmapRefs[keyAutoComplete] = view),
|
|
131
|
+
onChangeText: (text) =>
|
|
132
|
+
this.changeTextHandle(
|
|
133
|
+
child,
|
|
134
|
+
text,
|
|
135
|
+
onChangeText,
|
|
136
|
+
),
|
|
101
137
|
onFocus: (e) => this.focusHandle(e, child, onFocus),
|
|
102
138
|
// value: this.getValueByKey(keyAutoComplete, this.selectedItem),
|
|
103
|
-
onEndEditing: (e) =>
|
|
139
|
+
onEndEditing: (e) =>
|
|
140
|
+
this.endFocusHandle(e, onEndEditing),
|
|
104
141
|
});
|
|
105
142
|
}
|
|
106
143
|
return React.cloneElement(child, {
|
|
107
|
-
ref: (view) =>
|
|
108
|
-
|
|
144
|
+
ref: (view) =>
|
|
145
|
+
(this.hashmapRefs[keyAutoComplete] = view),
|
|
146
|
+
onChangeText: (text) =>
|
|
147
|
+
this.changeTextHandle(child, text, onChangeText),
|
|
109
148
|
onFocus: (e) => this.focusHandle(e, child, onFocus),
|
|
110
|
-
onEndEditing: (e) =>
|
|
149
|
+
onEndEditing: (e) =>
|
|
150
|
+
this.endFocusHandle(e, onEndEditing),
|
|
111
151
|
});
|
|
112
152
|
}
|
|
113
153
|
return child;
|
|
@@ -118,11 +158,11 @@ export default class AutoComplete extends Component {
|
|
|
118
158
|
}
|
|
119
159
|
|
|
120
160
|
render() {
|
|
121
|
-
const {
|
|
122
|
-
style = {},
|
|
123
|
-
} = this.props;
|
|
161
|
+
const { style = {} } = this.props;
|
|
124
162
|
const suggest = get(this.state, 'suggest', {});
|
|
125
|
-
const childrenWithProps = this.cloneChildren(
|
|
163
|
+
const childrenWithProps = this.cloneChildren(
|
|
164
|
+
get(this.props, 'children', null),
|
|
165
|
+
);
|
|
126
166
|
return (
|
|
127
167
|
<View style={[{ zIndex: 1 }, style]}>
|
|
128
168
|
{childrenWithProps}
|
|
@@ -135,14 +175,15 @@ export default class AutoComplete extends Component {
|
|
|
135
175
|
const keyAutoComplete = get(child.props, 'keyAutoComplete', '');
|
|
136
176
|
const isShowAutoComplete = get(child.props, 'isShowAutoComplete', true);
|
|
137
177
|
const { data } = this.props;
|
|
138
|
-
const dataOutput =
|
|
178
|
+
const dataOutput =
|
|
179
|
+
data && data.length > 0 && this.filter(data, keyAutoComplete, text);
|
|
139
180
|
if (this.hashmapRefs[keyAutoComplete]) {
|
|
140
181
|
this.setState({
|
|
141
182
|
suggest: {
|
|
142
183
|
data: dataOutput,
|
|
143
184
|
position: this.hashmapPosition[keyAutoComplete],
|
|
144
|
-
isShowAutoComplete
|
|
145
|
-
}
|
|
185
|
+
isShowAutoComplete,
|
|
186
|
+
},
|
|
146
187
|
});
|
|
147
188
|
}
|
|
148
189
|
};
|
|
@@ -194,62 +235,56 @@ export default class AutoComplete extends Component {
|
|
|
194
235
|
.toLowerCase()
|
|
195
236
|
.trim()
|
|
196
237
|
.replace(/\s/g, '');
|
|
197
|
-
return (
|
|
198
|
-
valueStrFormated.indexOf(queryFormated) !== -1
|
|
199
|
-
);
|
|
238
|
+
return valueStrFormated.indexOf(queryFormated) !== -1;
|
|
200
239
|
});
|
|
201
240
|
};
|
|
202
241
|
|
|
203
242
|
renderSuggest(suggest) {
|
|
204
243
|
const { numSuggest } = this.props;
|
|
205
|
-
if (
|
|
244
|
+
if (
|
|
245
|
+
suggest &&
|
|
246
|
+
suggest.data &&
|
|
247
|
+
suggest.data.length > 0 &&
|
|
248
|
+
suggest.isShowAutoComplete
|
|
249
|
+
) {
|
|
206
250
|
const { x = 0, y = 0, width = 0 } = suggest.position || {};
|
|
207
251
|
const sliceData = suggest.data.slice(0, numSuggest);
|
|
208
252
|
|
|
209
253
|
return (
|
|
210
|
-
<View
|
|
211
|
-
[
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
}
|
|
254
|
+
<View
|
|
255
|
+
style={[
|
|
256
|
+
styles.containerSuggest,
|
|
257
|
+
{
|
|
258
|
+
left: x,
|
|
259
|
+
top: y,
|
|
260
|
+
width,
|
|
261
|
+
},
|
|
262
|
+
]}>
|
|
263
|
+
{sliceData.map((item, index) => (
|
|
264
|
+
<View key={index.toString()}>
|
|
265
|
+
{this.renderItem({ item, index })}
|
|
266
|
+
{index !== sliceData.length - 1 &&
|
|
267
|
+
this.renderSeparator()}
|
|
268
|
+
</View>
|
|
269
|
+
))}
|
|
226
270
|
</View>
|
|
227
|
-
|
|
228
271
|
);
|
|
229
272
|
}
|
|
230
273
|
return null;
|
|
231
274
|
}
|
|
232
275
|
|
|
233
276
|
renderItem = ({ item, index }) => {
|
|
234
|
-
const {
|
|
235
|
-
renderSuggestItem
|
|
236
|
-
} = this.props;
|
|
277
|
+
const { renderSuggestItem } = this.props;
|
|
237
278
|
return (
|
|
238
279
|
<TouchableOpacity onPress={() => this.onPressItemSuggest(item)}>
|
|
239
|
-
{
|
|
240
|
-
(
|
|
241
|
-
|
|
242
|
-
: this.renderSuggestItemDefault({ item, index })
|
|
243
|
-
}
|
|
280
|
+
{renderSuggestItem && typeof renderSuggestItem === 'function'
|
|
281
|
+
? renderSuggestItem({ item, index })
|
|
282
|
+
: this.renderSuggestItemDefault({ item, index })}
|
|
244
283
|
</TouchableOpacity>
|
|
245
284
|
);
|
|
246
285
|
};
|
|
247
286
|
|
|
248
|
-
renderSeparator = () =>
|
|
249
|
-
<View
|
|
250
|
-
style={styles.separator}
|
|
251
|
-
/>
|
|
252
|
-
);
|
|
287
|
+
renderSeparator = () => <View style={styles.separator} />;
|
|
253
288
|
|
|
254
289
|
renderSuggestItemDefault = ({ item }) => {
|
|
255
290
|
const { title, value } = item;
|
|
@@ -265,21 +300,34 @@ export default class AutoComplete extends Component {
|
|
|
265
300
|
this.selectedItem = item;
|
|
266
301
|
// Loop hashRef to update value of child
|
|
267
302
|
Object.keys(this.hashmapRefs).forEach((key) => {
|
|
268
|
-
if (
|
|
269
|
-
|
|
303
|
+
if (
|
|
304
|
+
this.hashmapRefs[key].setText &&
|
|
305
|
+
typeof this.hashmapRefs[key].setText === 'function'
|
|
306
|
+
)
|
|
307
|
+
this.hashmapRefs[key].setText(
|
|
308
|
+
this.getValueByKey(key, this.selectedItem),
|
|
309
|
+
);
|
|
310
|
+
if (
|
|
311
|
+
this.hashmapRefs[key].setValue &&
|
|
312
|
+
typeof this.hashmapRefs[key].setValue === 'function'
|
|
313
|
+
)
|
|
314
|
+
this.hashmapRefs[key].setValue(
|
|
315
|
+
this.getValueByKey(key, this.selectedItem),
|
|
316
|
+
);
|
|
270
317
|
});
|
|
271
318
|
|
|
272
|
-
const {
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
319
|
+
const { onSelected } = this.props;
|
|
320
|
+
this.setState(
|
|
321
|
+
{
|
|
322
|
+
suggest: {},
|
|
323
|
+
},
|
|
324
|
+
() => {
|
|
325
|
+
if (onSelected && typeof onSelected === 'function') {
|
|
326
|
+
onSelected(item);
|
|
327
|
+
}
|
|
328
|
+
this.selectedItem = null;
|
|
329
|
+
},
|
|
330
|
+
);
|
|
283
331
|
};
|
|
284
332
|
|
|
285
333
|
isShowingSuggest = () => {
|
|
@@ -288,11 +336,14 @@ export default class AutoComplete extends Component {
|
|
|
288
336
|
};
|
|
289
337
|
|
|
290
338
|
hideSuggest = () => {
|
|
291
|
-
this.setState(
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
339
|
+
this.setState(
|
|
340
|
+
{
|
|
341
|
+
suggest: {},
|
|
342
|
+
},
|
|
343
|
+
() => {
|
|
344
|
+
this.selectedItem = null;
|
|
345
|
+
},
|
|
346
|
+
);
|
|
296
347
|
};
|
|
297
348
|
}
|
|
298
349
|
|
|
@@ -315,7 +366,7 @@ const styles = StyleSheet.create({
|
|
|
315
366
|
shadowColor: '#000000',
|
|
316
367
|
shadowOffset: {
|
|
317
368
|
width: 0,
|
|
318
|
-
height: 1
|
|
369
|
+
height: 1,
|
|
319
370
|
},
|
|
320
371
|
shadowRadius: 1,
|
|
321
372
|
elevation: 2,
|
|
@@ -325,12 +376,16 @@ const styles = StyleSheet.create({
|
|
|
325
376
|
height: 1,
|
|
326
377
|
width: '100%',
|
|
327
378
|
backgroundColor: Colors.placeholder,
|
|
328
|
-
marginVertical: 10
|
|
329
|
-
}
|
|
379
|
+
marginVertical: 10,
|
|
380
|
+
},
|
|
330
381
|
});
|
|
331
382
|
|
|
332
383
|
AutoComplete.propTypes = {
|
|
333
|
-
style: PropTypes.oneOfType([
|
|
384
|
+
style: PropTypes.oneOfType([
|
|
385
|
+
PropTypes.array,
|
|
386
|
+
PropTypes.object,
|
|
387
|
+
PropTypes.number,
|
|
388
|
+
]),
|
|
334
389
|
data: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
335
390
|
renderSuggestItem: PropTypes.func,
|
|
336
391
|
onSelected: PropTypes.func.isRequired,
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@momo-kits/auto-complete",
|
|
3
|
+
"version": "0.0.59-beta.2",
|
|
4
|
+
"private": false,
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"dependencies": {},
|
|
7
|
+
"peerDependencies": {
|
|
8
|
+
"react": "16.9.0",
|
|
9
|
+
"react-native": ">=0.55",
|
|
10
|
+
"@momo-kits/core": ">=0.0.4-beta",
|
|
11
|
+
"lodash": "^4.17.15",
|
|
12
|
+
"prop-types": "^15.7.2"
|
|
13
|
+
},
|
|
14
|
+
"devDependencies": {},
|
|
15
|
+
"license": "MoMo"
|
|
16
16
|
}
|
package/publish.sh
CHANGED
|
@@ -21,9 +21,9 @@ rsync -r --verbose --exclude '*.mdx' --exclude '*Demo.js' --exclude 'props-type
|
|
|
21
21
|
#npm login
|
|
22
22
|
#publish dist to npm
|
|
23
23
|
cd dist
|
|
24
|
-
npm publish --access=public
|
|
24
|
+
npm publish --tag beta --access=public
|
|
25
25
|
cd ..
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/auto-complete new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/auto-complete"}'
|
|
29
|
+
#curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/auto-complete new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/auto-complete"}'
|