|
@@ -7,6 +7,7 @@ import {
|
7
|
7
|
Alert,
|
8
|
8
|
FlatList,
|
9
|
9
|
KeyboardAvoidingView,
|
|
10
|
+ Platform,
|
10
|
11
|
SafeAreaView,
|
11
|
12
|
TextInput,
|
12
|
13
|
TouchableOpacity,
|
|
@@ -51,6 +52,11 @@ type Props = AbstractProps & {
|
51
|
52
|
|
52
|
53
|
type State = AbstractState & {
|
53
|
54
|
|
|
55
|
+ /**
|
|
56
|
+ * State variable to keep track of the search field value.
|
|
57
|
+ */
|
|
58
|
+ fieldValue: string,
|
|
59
|
+
|
54
|
60
|
/**
|
55
|
61
|
* True if a search is in progress, false otherwise.
|
56
|
62
|
*/
|
|
@@ -73,6 +79,7 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
73
|
79
|
defaultState = {
|
74
|
80
|
addToCallError: false,
|
75
|
81
|
addToCallInProgress: false,
|
|
82
|
+ fieldValue: '',
|
76
|
83
|
inviteItems: [],
|
77
|
84
|
searchInprogress: false,
|
78
|
85
|
selectableItems: []
|
|
@@ -101,6 +108,7 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
101
|
108
|
this._keyExtractor = this._keyExtractor.bind(this);
|
102
|
109
|
this._renderItem = this._renderItem.bind(this);
|
103
|
110
|
this._renderSeparator = this._renderSeparator.bind(this);
|
|
111
|
+ this._onClearField = this._onClearField.bind(this);
|
104
|
112
|
this._onCloseAddPeopleDialog = this._onCloseAddPeopleDialog.bind(this);
|
105
|
113
|
this._onInvite = this._onInvite.bind(this);
|
106
|
114
|
this._onPressItem = this._onPressItem.bind(this);
|
|
@@ -168,12 +176,15 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
168
|
176
|
<TextInput
|
169
|
177
|
autoCorrect = { false }
|
170
|
178
|
autoFocus = { true }
|
|
179
|
+ clearButtonMode = 'always' // iOS only
|
171
|
180
|
onChangeText = { this._onTypeQuery }
|
172
|
181
|
placeholder = {
|
173
|
182
|
this.props.t(`inviteDialog.${placeholderKey}`)
|
174
|
183
|
}
|
175
|
184
|
ref = { this._setFieldRef }
|
176
|
|
- style = { styles.searchField } />
|
|
185
|
+ style = { styles.searchField }
|
|
186
|
+ value = { this.state.fieldValue } />
|
|
187
|
+ { this._renderAndroidClearButton() }
|
177
|
188
|
</View>
|
178
|
189
|
<FlatList
|
179
|
190
|
ItemSeparatorComponent = { this._renderSeparator }
|
|
@@ -215,6 +226,22 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
215
|
226
|
return item.type === 'user' ? item.id || item.user_id : item.number;
|
216
|
227
|
}
|
217
|
228
|
|
|
229
|
+ _onClearField: () => void
|
|
230
|
+
|
|
231
|
+ /**
|
|
232
|
+ * Callback to clear the text field.
|
|
233
|
+ *
|
|
234
|
+ * @returns {void}
|
|
235
|
+ */
|
|
236
|
+ _onClearField() {
|
|
237
|
+ this.setState({
|
|
238
|
+ fieldValue: ''
|
|
239
|
+ });
|
|
240
|
+
|
|
241
|
+ // Clear search results
|
|
242
|
+ this._onTypeQuery('');
|
|
243
|
+ }
|
|
244
|
+
|
218
|
245
|
_onCloseAddPeopleDialog: () => void
|
219
|
246
|
|
220
|
247
|
/**
|
|
@@ -288,6 +315,10 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
288
|
315
|
* @returns {void}
|
289
|
316
|
*/
|
290
|
317
|
_onTypeQuery(query) {
|
|
318
|
+ this.setState({
|
|
319
|
+ fieldValue: query
|
|
320
|
+ });
|
|
321
|
+
|
291
|
322
|
clearTimeout(this.searchTimeout);
|
292
|
323
|
this.searchTimeout = setTimeout(() => {
|
293
|
324
|
this.setState({
|
|
@@ -342,6 +373,31 @@ class AddPeopleDialog extends AbstractAddPeopleDialog<Props, State> {
|
342
|
373
|
|
343
|
374
|
_renderItem: Object => ?React$Element<*>
|
344
|
375
|
|
|
376
|
+ /**
|
|
377
|
+ * Renders a button to clear the text field on Android.
|
|
378
|
+ *
|
|
379
|
+ * NOTE: For the best platform experience we use the native solution on iOS.
|
|
380
|
+ *
|
|
381
|
+ * @returns {React#Element<*>}
|
|
382
|
+ */
|
|
383
|
+ _renderAndroidClearButton() {
|
|
384
|
+ if (Platform.OS !== 'android' || !this.state.fieldValue.length) {
|
|
385
|
+ return null;
|
|
386
|
+ }
|
|
387
|
+
|
|
388
|
+ return (
|
|
389
|
+ <TouchableOpacity
|
|
390
|
+ onPress = { this._onClearField }
|
|
391
|
+ style = { styles.clearButton }>
|
|
392
|
+ <View style = { styles.clearIconContainer }>
|
|
393
|
+ <Icon
|
|
394
|
+ name = 'close'
|
|
395
|
+ style = { styles.clearIcon } />
|
|
396
|
+ </View>
|
|
397
|
+ </TouchableOpacity>
|
|
398
|
+ );
|
|
399
|
+ }
|
|
400
|
+
|
345
|
401
|
/**
|
346
|
402
|
* Renders a single item in the {@code FlatList}.
|
347
|
403
|
*
|