Bläddra i källkod

feat: add possibility to clear invite search field

master
Bettenbuk Zoltan 5 år sedan
förälder
incheckning
d7483f07e3

+ 57
- 1
react/features/invite/components/add-people-dialog/native/AddPeopleDialog.js Visa fil

7
     Alert,
7
     Alert,
8
     FlatList,
8
     FlatList,
9
     KeyboardAvoidingView,
9
     KeyboardAvoidingView,
10
+    Platform,
10
     SafeAreaView,
11
     SafeAreaView,
11
     TextInput,
12
     TextInput,
12
     TouchableOpacity,
13
     TouchableOpacity,
51
 
52
 
52
 type State = AbstractState & {
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
      * True if a search is in progress, false otherwise.
61
      * True if a search is in progress, false otherwise.
56
      */
62
      */
73
     defaultState = {
79
     defaultState = {
74
         addToCallError: false,
80
         addToCallError: false,
75
         addToCallInProgress: false,
81
         addToCallInProgress: false,
82
+        fieldValue: '',
76
         inviteItems: [],
83
         inviteItems: [],
77
         searchInprogress: false,
84
         searchInprogress: false,
78
         selectableItems: []
85
         selectableItems: []
101
         this._keyExtractor = this._keyExtractor.bind(this);
108
         this._keyExtractor = this._keyExtractor.bind(this);
102
         this._renderItem = this._renderItem.bind(this);
109
         this._renderItem = this._renderItem.bind(this);
103
         this._renderSeparator = this._renderSeparator.bind(this);
110
         this._renderSeparator = this._renderSeparator.bind(this);
111
+        this._onClearField = this._onClearField.bind(this);
104
         this._onCloseAddPeopleDialog = this._onCloseAddPeopleDialog.bind(this);
112
         this._onCloseAddPeopleDialog = this._onCloseAddPeopleDialog.bind(this);
105
         this._onInvite = this._onInvite.bind(this);
113
         this._onInvite = this._onInvite.bind(this);
106
         this._onPressItem = this._onPressItem.bind(this);
114
         this._onPressItem = this._onPressItem.bind(this);
168
                             <TextInput
176
                             <TextInput
169
                                 autoCorrect = { false }
177
                                 autoCorrect = { false }
170
                                 autoFocus = { true }
178
                                 autoFocus = { true }
179
+                                clearButtonMode = 'always' // iOS only
171
                                 onChangeText = { this._onTypeQuery }
180
                                 onChangeText = { this._onTypeQuery }
172
                                 placeholder = {
181
                                 placeholder = {
173
                                     this.props.t(`inviteDialog.${placeholderKey}`)
182
                                     this.props.t(`inviteDialog.${placeholderKey}`)
174
                                 }
183
                                 }
175
                                 ref = { this._setFieldRef }
184
                                 ref = { this._setFieldRef }
176
-                                style = { styles.searchField } />
185
+                                style = { styles.searchField }
186
+                                value = { this.state.fieldValue } />
187
+                            { this._renderAndroidClearButton() }
177
                         </View>
188
                         </View>
178
                         <FlatList
189
                         <FlatList
179
                             ItemSeparatorComponent = { this._renderSeparator }
190
                             ItemSeparatorComponent = { this._renderSeparator }
215
         return item.type === 'user' ? item.id || item.user_id : item.number;
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
     _onCloseAddPeopleDialog: () => void
245
     _onCloseAddPeopleDialog: () => void
219
 
246
 
220
     /**
247
     /**
288
      * @returns {void}
315
      * @returns {void}
289
      */
316
      */
290
     _onTypeQuery(query) {
317
     _onTypeQuery(query) {
318
+        this.setState({
319
+            fieldValue: query
320
+        });
321
+
291
         clearTimeout(this.searchTimeout);
322
         clearTimeout(this.searchTimeout);
292
         this.searchTimeout = setTimeout(() => {
323
         this.searchTimeout = setTimeout(() => {
293
             this.setState({
324
             this.setState({
342
 
373
 
343
     _renderItem: Object => ?React$Element<*>
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
      * Renders a single item in the {@code FlatList}.
402
      * Renders a single item in the {@code FlatList}.
347
      *
403
      *

+ 25
- 2
react/features/invite/components/add-people-dialog/native/styles.js Visa fil

7
 export const LIGHT_GREY = 'rgb(209, 219, 232)';
7
 export const LIGHT_GREY = 'rgb(209, 219, 232)';
8
 export const ICON_SIZE = 15;
8
 export const ICON_SIZE = 15;
9
 
9
 
10
+const FIELD_COLOR = 'rgb(240, 243, 247)';
11
+
10
 export default {
12
 export default {
11
     avatar: {
13
     avatar: {
12
         backgroundColor: LIGHT_GREY
14
         backgroundColor: LIGHT_GREY
21
         flex: 1
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
     dialogWrapper: {
47
     dialogWrapper: {
25
         alignItems: 'stretch',
48
         alignItems: 'stretch',
26
         backgroundColor: ColorPalette.white,
49
         backgroundColor: ColorPalette.white,
56
     },
79
     },
57
 
80
 
58
     searchField: {
81
     searchField: {
59
-        backgroundColor: 'rgb(240, 243, 247)',
82
+        backgroundColor: FIELD_COLOR,
60
         borderBottomRightRadius: 10,
83
         borderBottomRightRadius: 10,
61
         borderTopRightRadius: 10,
84
         borderTopRightRadius: 10,
62
         color: DARK_GREY,
85
         color: DARK_GREY,
86
 
109
 
87
     searchIconWrapper: {
110
     searchIconWrapper: {
88
         alignItems: 'center',
111
         alignItems: 'center',
89
-        backgroundColor: 'rgb(240, 243, 247)',
112
+        backgroundColor: FIELD_COLOR,
90
         borderBottomLeftRadius: 10,
113
         borderBottomLeftRadius: 10,
91
         borderTopLeftRadius: 10,
114
         borderTopLeftRadius: 10,
92
         flexDirection: 'row',
115
         flexDirection: 'row',

Laddar…
Avbryt
Spara