|
@@ -1,4 +1,5 @@
|
1
|
1
|
// @flow
|
|
2
|
+
|
2
|
3
|
import React, { Component } from 'react';
|
3
|
4
|
import {
|
4
|
5
|
SafeAreaView,
|
|
@@ -8,11 +9,10 @@ import {
|
8
|
9
|
View
|
9
|
10
|
} from 'react-native';
|
10
|
11
|
|
11
|
|
-import styles, { UNDERLAY_COLOR } from './styles';
|
12
|
|
-
|
|
12
|
+import { Icon } from '../../../font-icons';
|
13
|
13
|
import { translate } from '../../../i18n';
|
14
|
14
|
|
15
|
|
-import { Icon } from '../../../font-icons';
|
|
15
|
+import styles, { UNDERLAY_COLOR } from './styles';
|
16
|
16
|
|
17
|
17
|
type Props = {
|
18
|
18
|
|
|
@@ -60,14 +60,30 @@ type Props = {
|
60
|
60
|
* ]
|
61
|
61
|
*/
|
62
|
62
|
sections: Array<Object>
|
63
|
|
-}
|
|
63
|
+};
|
64
|
64
|
|
65
|
65
|
/**
|
66
|
|
- * Implements a general section list to display items that have a URL
|
67
|
|
- * property and navigates to (probably) meetings, such as the recent list
|
68
|
|
- * or the meeting list components.
|
|
66
|
+ * Implements a general section list to display items that have a URL property
|
|
67
|
+ * and navigates to (probably) meetings, such as the recent list or the meeting
|
|
68
|
+ * list components.
|
69
|
69
|
*/
|
70
|
70
|
class NavigateSectionList extends Component<Props> {
|
|
71
|
+ /**
|
|
72
|
+ * Creates an empty section object.
|
|
73
|
+ *
|
|
74
|
+ * @param {string} title - The title of the section.
|
|
75
|
+ * @param {string} key - The key of the section. It must be unique.
|
|
76
|
+ * @private
|
|
77
|
+ * @returns {Object}
|
|
78
|
+ */
|
|
79
|
+ static createSection(title, key) {
|
|
80
|
+ return {
|
|
81
|
+ data: [],
|
|
82
|
+ key,
|
|
83
|
+ title
|
|
84
|
+ };
|
|
85
|
+ }
|
|
86
|
+
|
71
|
87
|
/**
|
72
|
88
|
* Constructor of the NavigateSectionList component.
|
73
|
89
|
*
|
|
@@ -89,23 +105,23 @@ class NavigateSectionList extends Component<Props> {
|
89
|
105
|
}
|
90
|
106
|
|
91
|
107
|
/**
|
92
|
|
- * Implements React's Component.render function.
|
|
108
|
+ * Implements React's Component.render.
|
93
|
109
|
* Note: we don't use the refreshing value yet, because refreshing of these
|
94
|
110
|
* lists is super quick, no need to complicate the code - yet.
|
95
|
111
|
*
|
96
|
112
|
* @inheritdoc
|
97
|
113
|
*/
|
98
|
114
|
render() {
|
99
|
|
- const { renderListEmptyComponent, sections } = this.props;
|
|
115
|
+ const {
|
|
116
|
+ renderListEmptyComponent = this._renderListEmptyComponent,
|
|
117
|
+ sections
|
|
118
|
+ } = this.props;
|
100
|
119
|
|
101
|
120
|
return (
|
102
|
121
|
<SafeAreaView
|
103
|
122
|
style = { styles.container } >
|
104
|
123
|
<SectionList
|
105
|
|
- ListEmptyComponent = {
|
106
|
|
- renderListEmptyComponent
|
107
|
|
- || this._renderListEmptyComponent
|
108
|
|
- }
|
|
124
|
+ ListEmptyComponent = { renderListEmptyComponent }
|
109
|
125
|
keyExtractor = { this._getItemKey }
|
110
|
126
|
onRefresh = { this._onRefresh }
|
111
|
127
|
refreshing = { false }
|
|
@@ -117,27 +133,11 @@ class NavigateSectionList extends Component<Props> {
|
117
|
133
|
);
|
118
|
134
|
}
|
119
|
135
|
|
120
|
|
- /**
|
121
|
|
- * Creates an empty section object.
|
122
|
|
- *
|
123
|
|
- * @private
|
124
|
|
- * @param {string} title - The title of the section.
|
125
|
|
- * @param {string} key - The key of the section. It must be unique.
|
126
|
|
- * @returns {Object}
|
127
|
|
- */
|
128
|
|
- static createSection(title, key) {
|
129
|
|
- return {
|
130
|
|
- data: [],
|
131
|
|
- key,
|
132
|
|
- title
|
133
|
|
- };
|
134
|
|
- }
|
135
|
|
-
|
136
|
|
- _getAvatarColor: string => Object
|
|
136
|
+ _getAvatarColor: string => Object;
|
137
|
137
|
|
138
|
138
|
/**
|
139
|
|
- * Returns a style (color) based on the string that determines the
|
140
|
|
- * color of the avatar.
|
|
139
|
+ * Returns a style (color) based on the string that determines the color of
|
|
140
|
+ * the avatar.
|
141
|
141
|
*
|
142
|
142
|
* @param {string} colorBase - The string that is the base of the color.
|
143
|
143
|
* @private
|
|
@@ -162,22 +162,22 @@ class NavigateSectionList extends Component<Props> {
|
162
|
162
|
/**
|
163
|
163
|
* Generates a unique id to every item.
|
164
|
164
|
*
|
165
|
|
- * @private
|
166
|
165
|
* @param {Object} item - The item.
|
167
|
166
|
* @param {number} index - The item index.
|
|
167
|
+ * @private
|
168
|
168
|
* @returns {string}
|
169
|
169
|
*/
|
170
|
170
|
_getItemKey(item, index) {
|
171
|
171
|
return `${index}-${item.key}`;
|
172
|
172
|
}
|
173
|
173
|
|
174
|
|
- _onPress: string => Function
|
|
174
|
+ _onPress: string => Function;
|
175
|
175
|
|
176
|
176
|
/**
|
177
|
177
|
* Returns a function that is used in the onPress callback of the items.
|
178
|
178
|
*
|
179
|
|
- * @private
|
180
|
179
|
* @param {string} url - The URL of the item to navigate to.
|
|
180
|
+ * @private
|
181
|
181
|
* @returns {Function}
|
182
|
182
|
*/
|
183
|
183
|
_onPress(url) {
|
|
@@ -188,7 +188,7 @@ class NavigateSectionList extends Component<Props> {
|
188
|
188
|
};
|
189
|
189
|
}
|
190
|
190
|
|
191
|
|
- _onRefresh: () => void
|
|
191
|
+ _onRefresh: () => void;
|
192
|
192
|
|
193
|
193
|
/**
|
194
|
194
|
* Invokes the onRefresh callback if present.
|
|
@@ -209,26 +209,35 @@ class NavigateSectionList extends Component<Props> {
|
209
|
209
|
/**
|
210
|
210
|
* Renders a single item in the list.
|
211
|
211
|
*
|
212
|
|
- * @private
|
213
|
212
|
* @param {Object} listItem - The item to render.
|
|
213
|
+ * @private
|
214
|
214
|
* @returns {Component}
|
215
|
215
|
*/
|
216
|
216
|
_renderItem(listItem) {
|
217
|
|
- const { item } = listItem;
|
|
217
|
+ const { item: { colorBase, lines, title, url } } = listItem;
|
|
218
|
+
|
|
219
|
+ // XXX The value of title cannot be undefined; otherwise, react-native
|
|
220
|
+ // will throw a TypeError: Cannot read property of undefined. While it's
|
|
221
|
+ // difficult to get an undefined title and very likely requires the
|
|
222
|
+ // execution of incorrect source code, it is undesirable to break the
|
|
223
|
+ // whole app because of an undefined string.
|
|
224
|
+ if (typeof title === 'undefined') {
|
|
225
|
+ return null;
|
|
226
|
+ }
|
218
|
227
|
|
219
|
228
|
return (
|
220
|
229
|
<TouchableHighlight
|
221
|
|
- onPress = { this._onPress(item.url) }
|
|
230
|
+ onPress = { this._onPress(url) }
|
222
|
231
|
underlayColor = { UNDERLAY_COLOR }>
|
223
|
232
|
<View style = { styles.listItem }>
|
224
|
233
|
<View style = { styles.avatarContainer } >
|
225
|
234
|
<View
|
226
|
235
|
style = { [
|
227
|
236
|
styles.avatar,
|
228
|
|
- this._getAvatarColor(item.colorBase)
|
|
237
|
+ this._getAvatarColor(colorBase)
|
229
|
238
|
] } >
|
230
|
239
|
<Text style = { styles.avatarContent }>
|
231
|
|
- { item.title.substr(0, 1).toUpperCase() }
|
|
240
|
+ { title.substr(0, 1).toUpperCase() }
|
232
|
241
|
</Text>
|
233
|
242
|
</View>
|
234
|
243
|
</View>
|
|
@@ -239,11 +248,9 @@ class NavigateSectionList extends Component<Props> {
|
239
|
248
|
styles.listItemText,
|
240
|
249
|
styles.listItemTitle
|
241
|
250
|
] }>
|
242
|
|
- { item.title }
|
|
251
|
+ { title }
|
243
|
252
|
</Text>
|
244
|
|
- {
|
245
|
|
- this._renderItemLines(item.lines)
|
246
|
|
- }
|
|
253
|
+ { this._renderItemLines(lines) }
|
247
|
254
|
</View>
|
248
|
255
|
</View>
|
249
|
256
|
</TouchableHighlight>
|
|
@@ -255,9 +262,9 @@ class NavigateSectionList extends Component<Props> {
|
255
|
262
|
/**
|
256
|
263
|
* Renders a single line from the additional lines.
|
257
|
264
|
*
|
258
|
|
- * @private
|
259
|
265
|
* @param {string} line - The line text.
|
260
|
266
|
* @param {number} index - The index of the line.
|
|
267
|
+ * @private
|
261
|
268
|
* @returns {React$Node}
|
262
|
269
|
*/
|
263
|
270
|
_renderItemLine(line, index) {
|
|
@@ -275,32 +282,26 @@ class NavigateSectionList extends Component<Props> {
|
275
|
282
|
);
|
276
|
283
|
}
|
277
|
284
|
|
278
|
|
- _renderItemLines: (Array<string>) => Array<React$Node>;
|
|
285
|
+ _renderItemLines: Array<string> => Array<React$Node>;
|
279
|
286
|
|
280
|
287
|
/**
|
281
|
288
|
* Renders the additional item lines, if any.
|
282
|
289
|
*
|
283
|
|
- * @private
|
284
|
290
|
* @param {Array<string>} lines - The lines to render.
|
|
291
|
+ * @private
|
285
|
292
|
* @returns {Array<React$Node>}
|
286
|
293
|
*/
|
287
|
294
|
_renderItemLines(lines) {
|
288
|
|
- if (lines && lines.length) {
|
289
|
|
- return lines.map((line, index) =>
|
290
|
|
- this._renderItemLine(line, index)
|
291
|
|
- );
|
292
|
|
- }
|
293
|
|
-
|
294
|
|
- return null;
|
|
295
|
+ return lines && lines.length ? lines.map(this._renderItemLine) : null;
|
295
|
296
|
}
|
296
|
297
|
|
297
|
|
- _renderListEmptyComponent: () => Object
|
|
298
|
+ _renderListEmptyComponent: () => Object;
|
298
|
299
|
|
299
|
300
|
/**
|
300
|
301
|
* Renders a component to display when the list is empty.
|
301
|
302
|
*
|
302
|
|
- * @private
|
303
|
303
|
* @param {Object} section - The section being rendered.
|
|
304
|
+ * @private
|
304
|
305
|
* @returns {React$Node}
|
305
|
306
|
*/
|
306
|
307
|
_renderListEmptyComponent() {
|
|
@@ -322,13 +323,13 @@ class NavigateSectionList extends Component<Props> {
|
322
|
323
|
return null;
|
323
|
324
|
}
|
324
|
325
|
|
325
|
|
- _renderSection: Object => Object
|
|
326
|
+ _renderSection: Object => Object;
|
326
|
327
|
|
327
|
328
|
/**
|
328
|
329
|
* Renders a section title.
|
329
|
330
|
*
|
330
|
|
- * @private
|
331
|
331
|
* @param {Object} section - The section being rendered.
|
|
332
|
+ * @private
|
332
|
333
|
* @returns {React$Node}
|
333
|
334
|
*/
|
334
|
335
|
_renderSection(section) {
|