瀏覽代碼

feat: add possibility to clear invite search field

master
Bettenbuk Zoltan 5 年之前
父節點
當前提交
d7483f07e3

+ 57
- 1
react/features/invite/components/add-people-dialog/native/AddPeopleDialog.js 查看文件

@@ -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
      *

+ 25
- 2
react/features/invite/components/add-people-dialog/native/styles.js 查看文件

@@ -7,6 +7,8 @@ export const DARK_GREY = 'rgb(28, 32, 37)';
7 7
 export const LIGHT_GREY = 'rgb(209, 219, 232)';
8 8
 export const ICON_SIZE = 15;
9 9
 
10
+const FIELD_COLOR = 'rgb(240, 243, 247)';
11
+
10 12
 export default {
11 13
     avatar: {
12 14
         backgroundColor: LIGHT_GREY
@@ -21,6 +23,27 @@ export default {
21 23
         flex: 1
22 24
     },
23 25
 
26
+    clearButton: {
27
+        alignItems: 'center',
28
+        justifyContent: 'center',
29
+        marginLeft: 5
30
+    },
31
+
32
+    clearIcon: {
33
+        color: DARK_GREY,
34
+        fontSize: 18,
35
+        textAlign: 'center'
36
+    },
37
+
38
+    clearIconContainer: {
39
+        alignItems: 'center',
40
+        backgroundColor: FIELD_COLOR,
41
+        borderRadius: 12,
42
+        justifyContent: 'center',
43
+        height: 24,
44
+        width: 24
45
+    },
46
+
24 47
     dialogWrapper: {
25 48
         alignItems: 'stretch',
26 49
         backgroundColor: ColorPalette.white,
@@ -56,7 +79,7 @@ export default {
56 79
     },
57 80
 
58 81
     searchField: {
59
-        backgroundColor: 'rgb(240, 243, 247)',
82
+        backgroundColor: FIELD_COLOR,
60 83
         borderBottomRightRadius: 10,
61 84
         borderTopRightRadius: 10,
62 85
         color: DARK_GREY,
@@ -86,7 +109,7 @@ export default {
86 109
 
87 110
     searchIconWrapper: {
88 111
         alignItems: 'center',
89
-        backgroundColor: 'rgb(240, 243, 247)',
112
+        backgroundColor: FIELD_COLOR,
90 113
         borderBottomLeftRadius: 10,
91 114
         borderTopLeftRadius: 10,
92 115
         flexDirection: 'row',

Loading…
取消
儲存