@momo-kits/avatar 0.0.74-beta → 0.72.1
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/Avatar.js +359 -505
- package/Avatar.web.js +355 -502
- package/package.json +14 -14
- package/publish.sh +2 -2
package/Avatar.js
CHANGED
|
@@ -1,554 +1,408 @@
|
|
|
1
1
|
/* eslint-disable indent */
|
|
2
|
-
import PropTypes from 'prop-types';
|
|
3
|
-
import React, { Component } from 'react';
|
|
4
|
-
import {
|
|
5
|
-
View, StyleSheet, TouchableOpacity, Dimensions
|
|
6
|
-
} from 'react-native';
|
|
7
|
-
import { get, isEqual } from 'lodash';
|
|
8
2
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
tiny: 'tiny',
|
|
20
|
-
small: 'small',
|
|
21
|
-
medium: 'medium',
|
|
22
|
-
large: 'large',
|
|
23
|
-
giant: 'giant',
|
|
24
|
-
size8: 'size8',
|
|
25
|
-
size24: 'size24',
|
|
26
|
-
size36: 'size36',
|
|
27
|
-
size44: 'size44',
|
|
28
|
-
size48: 'size48',
|
|
29
|
-
size52: 'size52',
|
|
30
|
-
size56: 'size56',
|
|
31
|
-
size64: 'size64',
|
|
32
|
-
size72: 'size72',
|
|
33
|
-
size80: 'size80',
|
|
34
|
-
size88: 'size88',
|
|
35
|
-
size96: 'size96'
|
|
36
|
-
};
|
|
3
|
+
Colors,
|
|
4
|
+
Image,
|
|
5
|
+
Radius,
|
|
6
|
+
ScaleSize,
|
|
7
|
+
Text,
|
|
8
|
+
ValueUtil,
|
|
9
|
+
} from '@momo-kits/core-v2';
|
|
10
|
+
import PropTypes from 'prop-types';
|
|
11
|
+
import React, {useState} from 'react';
|
|
12
|
+
import {StyleSheet, TouchableOpacity, View} from 'react-native';
|
|
37
13
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
none: 'none'
|
|
14
|
+
const AvatarQuality = {
|
|
15
|
+
low: 'low',
|
|
16
|
+
medium: 'medium',
|
|
17
|
+
high: 'high',
|
|
43
18
|
};
|
|
44
19
|
|
|
45
20
|
const styles = StyleSheet.create({
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
21
|
+
container: {
|
|
22
|
+
justifyContent: 'center',
|
|
23
|
+
alignItems: 'center',
|
|
24
|
+
},
|
|
25
|
+
shortNameView: {
|
|
26
|
+
backgroundColor: Colors.pink_09,
|
|
27
|
+
justifyContent: 'center',
|
|
28
|
+
alignItems: 'center',
|
|
29
|
+
borderWidth: 1,
|
|
30
|
+
borderColor: Colors.black_04,
|
|
31
|
+
},
|
|
32
|
+
shortNameText: {
|
|
33
|
+
// fontSize: 17,
|
|
34
|
+
color: Colors.pink_03,
|
|
35
|
+
},
|
|
36
|
+
shortNameTextCustom: {
|
|
37
|
+
color: '#f6f6f6',
|
|
38
|
+
},
|
|
39
|
+
absolute: {
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: 0,
|
|
42
|
+
left: 0,
|
|
43
|
+
right: 0,
|
|
44
|
+
bottom: 0,
|
|
45
|
+
},
|
|
46
|
+
subIcon: {
|
|
47
|
+
position: 'absolute',
|
|
48
|
+
bottom: 0,
|
|
49
|
+
right: 0,
|
|
50
|
+
},
|
|
51
|
+
topIcon: {
|
|
52
|
+
position: 'absolute',
|
|
53
|
+
top: 0,
|
|
54
|
+
right: 0,
|
|
55
|
+
},
|
|
56
|
+
subIconImage: {
|
|
57
|
+
width: 22,
|
|
58
|
+
height: 22,
|
|
59
|
+
},
|
|
60
|
+
subIconImageOnline: {
|
|
61
|
+
backgroundColor: Colors.kiwi_green,
|
|
62
|
+
borderColor: 'white',
|
|
63
|
+
borderWidth: 1,
|
|
64
|
+
},
|
|
83
65
|
});
|
|
84
66
|
|
|
85
|
-
const subIconSize =
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
borderRadius: 4
|
|
90
|
-
},
|
|
91
|
-
small: {
|
|
92
|
-
width: 10,
|
|
93
|
-
height: 10,
|
|
94
|
-
borderRadius: 5
|
|
95
|
-
},
|
|
96
|
-
medium: {
|
|
67
|
+
const subIconSize = size => {
|
|
68
|
+
switch (size) {
|
|
69
|
+
case 'giant':
|
|
70
|
+
return {
|
|
97
71
|
width: 12,
|
|
98
72
|
height: 12,
|
|
99
|
-
borderRadius: 6
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
height: 16,
|
|
104
|
-
borderRadius: 8
|
|
105
|
-
},
|
|
106
|
-
size8: {
|
|
73
|
+
borderRadius: 6,
|
|
74
|
+
};
|
|
75
|
+
case 'small':
|
|
76
|
+
return {
|
|
107
77
|
width: 8,
|
|
108
78
|
height: 8,
|
|
109
|
-
borderRadius: 4
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
size56: {
|
|
137
|
-
width: 16,
|
|
138
|
-
height: 16,
|
|
139
|
-
borderRadius: 8
|
|
140
|
-
},
|
|
141
|
-
size64: {
|
|
142
|
-
width: 16,
|
|
143
|
-
height: 16,
|
|
144
|
-
borderRadius: 8,
|
|
145
|
-
top: -2,
|
|
146
|
-
left: -2,
|
|
147
|
-
},
|
|
148
|
-
size72: {
|
|
149
|
-
width: 18,
|
|
150
|
-
height: 18,
|
|
151
|
-
borderRadius: 9,
|
|
152
|
-
top: -3,
|
|
153
|
-
left: -3,
|
|
154
|
-
},
|
|
155
|
-
size80: {
|
|
156
|
-
width: 18,
|
|
157
|
-
height: 18,
|
|
158
|
-
borderRadius: 9,
|
|
159
|
-
top: -3,
|
|
160
|
-
left: -3,
|
|
161
|
-
},
|
|
162
|
-
size88: {
|
|
163
|
-
width: 18,
|
|
164
|
-
height: 18,
|
|
165
|
-
borderRadius: 9,
|
|
166
|
-
top: -4,
|
|
167
|
-
left: -4,
|
|
168
|
-
},
|
|
169
|
-
size96: {
|
|
170
|
-
width: 20,
|
|
171
|
-
height: 20,
|
|
172
|
-
borderRadius: 10,
|
|
173
|
-
top: -4,
|
|
174
|
-
left: -4,
|
|
175
|
-
},
|
|
176
|
-
giant: {
|
|
177
|
-
top: -5,
|
|
178
|
-
left: -5,
|
|
79
|
+
borderRadius: 4,
|
|
80
|
+
};
|
|
81
|
+
case 'medium':
|
|
82
|
+
return {
|
|
83
|
+
width: 12,
|
|
84
|
+
height: 12,
|
|
85
|
+
borderRadius: 6,
|
|
86
|
+
};
|
|
87
|
+
case 'large':
|
|
88
|
+
return {
|
|
89
|
+
width: 12,
|
|
90
|
+
height: 12,
|
|
91
|
+
borderRadius: 6,
|
|
92
|
+
};
|
|
93
|
+
default:
|
|
94
|
+
return {
|
|
95
|
+
width: 12,
|
|
96
|
+
height: 12,
|
|
97
|
+
borderRadius: 6,
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const avatarSize = size => {
|
|
103
|
+
switch (size) {
|
|
104
|
+
case 'tiny':
|
|
105
|
+
return {
|
|
179
106
|
width: 24,
|
|
180
107
|
height: 24,
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const avatarSize = (width) => ({
|
|
186
|
-
tiny: {
|
|
187
|
-
width: 16,
|
|
188
|
-
height: 16,
|
|
189
|
-
borderRadius: 8
|
|
190
|
-
},
|
|
191
|
-
small: {
|
|
108
|
+
};
|
|
109
|
+
case 'small': {
|
|
110
|
+
return {
|
|
192
111
|
width: 32,
|
|
193
112
|
height: 32,
|
|
194
|
-
|
|
195
|
-
}
|
|
196
|
-
medium:
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
case 'medium':
|
|
116
|
+
return {
|
|
197
117
|
width: 40,
|
|
198
118
|
height: 40,
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
width: 60,
|
|
203
|
-
height: 60,
|
|
204
|
-
borderRadius: 30
|
|
205
|
-
},
|
|
206
|
-
giant: {
|
|
207
|
-
width: 120,
|
|
208
|
-
height: 120,
|
|
209
|
-
borderRadius: 60
|
|
210
|
-
},
|
|
211
|
-
size8: {
|
|
212
|
-
width: 8,
|
|
213
|
-
height: 8,
|
|
214
|
-
borderRadius: 4
|
|
215
|
-
},
|
|
216
|
-
size24: {
|
|
217
|
-
width: 24,
|
|
218
|
-
height: 24,
|
|
219
|
-
borderRadius: 12
|
|
220
|
-
},
|
|
221
|
-
size36: {
|
|
222
|
-
width: 36,
|
|
223
|
-
height: 36,
|
|
224
|
-
borderRadius: 18
|
|
225
|
-
},
|
|
226
|
-
size44: {
|
|
227
|
-
width: 44,
|
|
228
|
-
height: 44,
|
|
229
|
-
borderRadius: 22
|
|
230
|
-
},
|
|
231
|
-
size48: {
|
|
232
|
-
width: 48,
|
|
233
|
-
height: 48,
|
|
234
|
-
borderRadius: 24
|
|
235
|
-
},
|
|
236
|
-
size52: {
|
|
237
|
-
width: 52,
|
|
238
|
-
height: 52,
|
|
239
|
-
borderRadius: 26
|
|
240
|
-
},
|
|
241
|
-
size56: {
|
|
119
|
+
};
|
|
120
|
+
case 'large':
|
|
121
|
+
return {
|
|
242
122
|
width: 56,
|
|
243
123
|
height: 56,
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
width: 64,
|
|
248
|
-
height: 64,
|
|
249
|
-
borderRadius: 32
|
|
250
|
-
},
|
|
251
|
-
size72: {
|
|
124
|
+
};
|
|
125
|
+
case 'giant':
|
|
126
|
+
return {
|
|
252
127
|
width: 72,
|
|
253
128
|
height: 72,
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
width:
|
|
258
|
-
height:
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
width: 88,
|
|
263
|
-
height: 88,
|
|
264
|
-
borderRadius: 44
|
|
265
|
-
},
|
|
266
|
-
size96: {
|
|
267
|
-
width: 96,
|
|
268
|
-
height: 96,
|
|
269
|
-
borderRadius: 48
|
|
270
|
-
}
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
const shortName = (width) => ({
|
|
274
|
-
tiny: {
|
|
275
|
-
fontSize: ScaleSize(5, width)
|
|
276
|
-
},
|
|
277
|
-
small: {
|
|
278
|
-
fontSize: ScaleSize(11, width)
|
|
279
|
-
},
|
|
280
|
-
medium: {
|
|
281
|
-
fontSize: ScaleSize(15, width)
|
|
282
|
-
},
|
|
283
|
-
large: {
|
|
284
|
-
fontSize: ScaleSize(20, width)
|
|
285
|
-
},
|
|
286
|
-
giant: {
|
|
287
|
-
fontSize: ScaleSize(25, width)
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
export default class Avatar extends Component {
|
|
292
|
-
constructor(props) {
|
|
293
|
-
super(props);
|
|
294
|
-
this.state = {
|
|
295
|
-
hideSource: false,
|
|
296
|
-
ownUpdate: false,
|
|
297
|
-
source: props.source,
|
|
298
|
-
dimensions: {}
|
|
299
|
-
};
|
|
300
|
-
this.imageSource = '';
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
componentDidMount() {
|
|
304
|
-
const { scaleSize } = this.props;
|
|
305
|
-
if (scaleSize) {
|
|
306
|
-
this.subscription = Dimensions.addEventListener(
|
|
307
|
-
'change',
|
|
308
|
-
({ window }) => {
|
|
309
|
-
this.setState({ dimensions: window });
|
|
310
|
-
}
|
|
311
|
-
);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
componentWillUnmount() {
|
|
316
|
-
const { scaleSize } = this.props;
|
|
317
|
-
if (scaleSize) {
|
|
318
|
-
this.subscription?.remove?.();
|
|
319
|
-
}
|
|
320
|
-
}
|
|
129
|
+
};
|
|
130
|
+
default:
|
|
131
|
+
return {
|
|
132
|
+
width: 40,
|
|
133
|
+
height: 40,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
};
|
|
321
137
|
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
138
|
+
const shortName = size => {
|
|
139
|
+
switch (size) {
|
|
140
|
+
case 'tiny':
|
|
141
|
+
return {
|
|
142
|
+
fontSize: ScaleSize(10),
|
|
143
|
+
lineHeight: 16,
|
|
144
|
+
};
|
|
145
|
+
case 'small':
|
|
146
|
+
return {
|
|
147
|
+
fontSize: ScaleSize(15),
|
|
148
|
+
lineHeight: 22,
|
|
149
|
+
};
|
|
150
|
+
case 'medium':
|
|
151
|
+
return {
|
|
152
|
+
fontSize: ScaleSize(15),
|
|
153
|
+
lineHeight: 22,
|
|
154
|
+
};
|
|
155
|
+
case 'large':
|
|
156
|
+
return {
|
|
157
|
+
fontSize: ScaleSize(15),
|
|
158
|
+
lineHeight: 22,
|
|
159
|
+
};
|
|
160
|
+
case 'giant':
|
|
161
|
+
return {
|
|
162
|
+
fontSize: ScaleSize(15),
|
|
163
|
+
lineHeight: 22,
|
|
164
|
+
};
|
|
165
|
+
default:
|
|
166
|
+
return {
|
|
167
|
+
fontSize: ScaleSize(15),
|
|
168
|
+
lineHeight: 22,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
};
|
|
332
172
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
173
|
+
const Avatar = ({
|
|
174
|
+
resizeMode,
|
|
175
|
+
cached,
|
|
176
|
+
quality,
|
|
177
|
+
size,
|
|
178
|
+
shape,
|
|
179
|
+
name,
|
|
180
|
+
source,
|
|
181
|
+
onPress,
|
|
182
|
+
style,
|
|
183
|
+
subIcon,
|
|
184
|
+
topIcon,
|
|
185
|
+
loading,
|
|
186
|
+
}) => {
|
|
187
|
+
const {width, height} = avatarSize(size);
|
|
188
|
+
const {fontSize, lineHeight} = shortName(size);
|
|
189
|
+
const {
|
|
190
|
+
width: iconWidth,
|
|
191
|
+
height: iconHeight,
|
|
192
|
+
borderRadius: iconRadius,
|
|
193
|
+
} = subIconSize(size);
|
|
344
194
|
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
195
|
+
const [imageSource, setImageSource] = useState(
|
|
196
|
+
ValueUtil.getImageSource(source),
|
|
197
|
+
);
|
|
198
|
+
const getContactShortName = name => {
|
|
199
|
+
if (!name) return '';
|
|
200
|
+
const shortNameList = name.split(' ', 2);
|
|
201
|
+
const alphabet = [];
|
|
202
|
+
shortNameList.forEach(n => {
|
|
203
|
+
if (n && n.length > 0) {
|
|
204
|
+
alphabet.push(n[0].toString().toUpperCase());
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return alphabet.join('');
|
|
208
|
+
};
|
|
209
|
+
const isUrl = url => {
|
|
210
|
+
const expression =
|
|
211
|
+
/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/gi;
|
|
212
|
+
return expression.test(url);
|
|
213
|
+
};
|
|
357
214
|
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
}
|
|
215
|
+
const isValidImageUrl = source => {
|
|
216
|
+
return source && source.uri && isUrl(source.uri);
|
|
217
|
+
};
|
|
362
218
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
219
|
+
const mapAvatarQuality = (url, quality) => {
|
|
220
|
+
if (!quality || quality === AvatarQuality.medium) {
|
|
221
|
+
return url;
|
|
366
222
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
if (!quality || quality === AvatarQuality.medium) {
|
|
370
|
-
return url;
|
|
371
|
-
}
|
|
372
|
-
if (quality === AvatarQuality.low) {
|
|
373
|
-
return url.replace('.png', '_s64.png');
|
|
374
|
-
}
|
|
375
|
-
if (quality === AvatarQuality.high) {
|
|
376
|
-
return url.replace('.png', '_s512.png');
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return url;
|
|
223
|
+
if (quality === AvatarQuality.low) {
|
|
224
|
+
return url.replace('.png', '_s64.png');
|
|
380
225
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
const { dimensions } = this.state;
|
|
384
|
-
const avatarStyle = avatarSize(dimensions?.width || null).small;
|
|
385
|
-
if (typeof size === 'object') return size;
|
|
386
|
-
if (avatarSize(dimensions?.width || null)[size]) return avatarSize(dimensions?.width || null)[size];
|
|
387
|
-
return avatarStyle;
|
|
226
|
+
if (quality === AvatarQuality.high) {
|
|
227
|
+
return url.replace('.png', '_s512.png');
|
|
388
228
|
}
|
|
389
229
|
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
const { dimensions } = this.state;
|
|
393
|
-
switch (size) {
|
|
394
|
-
case AvatarSize.tiny: {
|
|
395
|
-
shortNameStyle = shortName(dimensions?.width || null).tiny;
|
|
396
|
-
break;
|
|
397
|
-
}
|
|
398
|
-
case AvatarSize.small: {
|
|
399
|
-
shortNameStyle = shortName(dimensions?.width || null).small;
|
|
400
|
-
break;
|
|
401
|
-
}
|
|
402
|
-
case AvatarSize.medium: {
|
|
403
|
-
shortNameStyle = shortName(dimensions?.width || null).medium;
|
|
404
|
-
break;
|
|
405
|
-
}
|
|
406
|
-
case AvatarSize.large: {
|
|
407
|
-
shortNameStyle = shortName(dimensions?.width || null).large;
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
case AvatarSize.giant: {
|
|
411
|
-
shortNameStyle = shortName(dimensions?.width || null).giant;
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
default:
|
|
415
|
-
shortNameStyle = shortName(dimensions?.width || null).small;
|
|
416
|
-
}
|
|
417
|
-
return shortNameStyle;
|
|
418
|
-
}
|
|
230
|
+
return url;
|
|
231
|
+
};
|
|
419
232
|
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
if (subIconSize(dimensions?.width || null)[size]) return subIconSize(dimensions?.width || null)[size];
|
|
424
|
-
return subIconStyle;
|
|
425
|
-
}
|
|
233
|
+
const onLoadSourceError = source => {
|
|
234
|
+
setImageSource(source);
|
|
235
|
+
};
|
|
426
236
|
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
237
|
+
const renderSubIcon = () => {
|
|
238
|
+
// const subIconSizeStyle = this.mapSubIconSize(size);
|
|
239
|
+
if (subIcon && shape === 'circle' && size !== 'tiny') {
|
|
240
|
+
return (
|
|
241
|
+
<View
|
|
242
|
+
style={[
|
|
243
|
+
styles.subIcon,
|
|
244
|
+
size === 'large' && {
|
|
245
|
+
bottom: 2,
|
|
246
|
+
right: 2,
|
|
247
|
+
},
|
|
248
|
+
size === 'giant' && {
|
|
249
|
+
bottom: 4,
|
|
250
|
+
right: 4,
|
|
251
|
+
},
|
|
252
|
+
]}>
|
|
253
|
+
{typeof subIcon === 'string' ? (
|
|
254
|
+
<Image
|
|
255
|
+
source={subIcon}
|
|
256
|
+
style={[
|
|
257
|
+
{
|
|
258
|
+
width: iconWidth,
|
|
259
|
+
height: iconHeight,
|
|
260
|
+
borderRadius: iconRadius,
|
|
261
|
+
},
|
|
262
|
+
]}
|
|
263
|
+
/>
|
|
264
|
+
) : (
|
|
265
|
+
subIcon()
|
|
266
|
+
)}
|
|
267
|
+
</View>
|
|
268
|
+
);
|
|
438
269
|
}
|
|
270
|
+
};
|
|
439
271
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
272
|
+
const renderTopIcon = () => {
|
|
273
|
+
if (topIcon && shape === 'circle' && size !== 'tiny') {
|
|
274
|
+
return (
|
|
275
|
+
<View
|
|
276
|
+
style={[
|
|
277
|
+
styles.topIcon,
|
|
278
|
+
size === 'large' && {
|
|
279
|
+
top: 2,
|
|
280
|
+
right: 2,
|
|
281
|
+
},
|
|
282
|
+
size === 'giant' && {
|
|
283
|
+
top: 4,
|
|
284
|
+
right: 4,
|
|
285
|
+
},
|
|
286
|
+
]}>
|
|
287
|
+
<Image
|
|
288
|
+
source={topIcon}
|
|
289
|
+
style={[
|
|
290
|
+
{
|
|
291
|
+
width: iconWidth,
|
|
292
|
+
height: iconHeight,
|
|
293
|
+
borderRadius: iconRadius,
|
|
294
|
+
},
|
|
295
|
+
]}
|
|
296
|
+
/>
|
|
297
|
+
</View>
|
|
298
|
+
);
|
|
445
299
|
}
|
|
300
|
+
};
|
|
446
301
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const subIconSizeStyle = this.mapSubIconSize(size);
|
|
451
|
-
const iconSource = ValueUtil.getImageSource(subIconSource);
|
|
452
|
-
return (
|
|
453
|
-
<View style={styles.subIcon}>
|
|
454
|
-
{subIcon === SubIconType.momo
|
|
455
|
-
? (
|
|
456
|
-
<Image
|
|
457
|
-
style={[styles.subIconImage, subIconSizeStyle]}
|
|
458
|
-
source={IconSource.ic_round_momo_tiny}
|
|
459
|
-
/>
|
|
460
|
-
)
|
|
461
|
-
: <View />}
|
|
462
|
-
{subIcon === SubIconType.online
|
|
463
|
-
? <View style={[styles.subIconImageOnline, subIconSizeStyle]} /> : <View />}
|
|
302
|
+
const onPressIcon = () => {
|
|
303
|
+
if (onPress && typeof onPress === 'function') onPress();
|
|
304
|
+
};
|
|
464
305
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
306
|
+
const renderShortName = () => {
|
|
307
|
+
if (name) {
|
|
308
|
+
const shortedName = getContactShortName(name);
|
|
309
|
+
// const shortNameStyle = mapShortNameStyle(size);
|
|
310
|
+
return (
|
|
311
|
+
<View
|
|
312
|
+
style={[
|
|
313
|
+
{
|
|
314
|
+
width,
|
|
315
|
+
height,
|
|
316
|
+
borderRadius: shape === 'circle' ? width / 2 : Radius.XS,
|
|
317
|
+
},
|
|
318
|
+
styles.shortNameView,
|
|
319
|
+
]}>
|
|
320
|
+
<Text
|
|
321
|
+
weight="regular"
|
|
322
|
+
style={{
|
|
323
|
+
fontSize,
|
|
324
|
+
lineHeight,
|
|
325
|
+
color: Colors.pink_03,
|
|
326
|
+
}}>
|
|
327
|
+
{shortedName}
|
|
328
|
+
</Text>
|
|
329
|
+
</View>
|
|
330
|
+
);
|
|
474
331
|
}
|
|
332
|
+
return <View />;
|
|
333
|
+
};
|
|
475
334
|
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
335
|
+
if (imageSource?.uri) {
|
|
336
|
+
imageSource.priority = 'high';
|
|
337
|
+
imageSource.uri = mapAvatarQuality(imageSource.uri, quality);
|
|
338
|
+
// if doest not have time query, set default cache time to 1 day
|
|
339
|
+
if (!imageSource.uri?.includes('?') && cached) {
|
|
340
|
+
const midnight = new Date().setHours(0, 0, 0, 0);
|
|
341
|
+
imageSource.uri = `${imageSource.uri}?time=${midnight}`;
|
|
479
342
|
}
|
|
343
|
+
}
|
|
480
344
|
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
345
|
+
const renderImage = () => {
|
|
346
|
+
return (
|
|
347
|
+
<Image
|
|
348
|
+
cached={cached}
|
|
349
|
+
resizeMode={resizeMode}
|
|
350
|
+
onLoadSourceError={() => onLoadSourceError(source)}
|
|
351
|
+
source={source}
|
|
352
|
+
loading={loading}
|
|
353
|
+
style={[
|
|
354
|
+
{
|
|
355
|
+
width,
|
|
356
|
+
height,
|
|
357
|
+
borderRadius: shape === 'circle' ? width / 2 : Radius.XS,
|
|
358
|
+
},
|
|
359
|
+
]}
|
|
360
|
+
/>
|
|
361
|
+
);
|
|
362
|
+
};
|
|
500
363
|
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
if (onPress) {
|
|
520
|
-
return (
|
|
521
|
-
<TouchableOpacity activeOpacity={onPress ? 0.5 : 1} onPress={this.onPress}>
|
|
522
|
-
{inner}
|
|
523
|
-
</TouchableOpacity>
|
|
524
|
-
);
|
|
525
|
-
}
|
|
526
|
-
return inner;
|
|
527
|
-
}
|
|
528
|
-
}
|
|
364
|
+
return (
|
|
365
|
+
<TouchableOpacity
|
|
366
|
+
activeOpacity={onPress ? 0.5 : 1}
|
|
367
|
+
style={style}
|
|
368
|
+
onPress={onPressIcon}>
|
|
369
|
+
<View
|
|
370
|
+
style={{
|
|
371
|
+
alignSelf: 'baseline',
|
|
372
|
+
}}>
|
|
373
|
+
{!!imageSource && isValidImageUrl(imageSource)
|
|
374
|
+
? renderImage()
|
|
375
|
+
: renderShortName()}
|
|
376
|
+
{renderTopIcon()}
|
|
377
|
+
{renderSubIcon()}
|
|
378
|
+
</View>
|
|
379
|
+
</TouchableOpacity>
|
|
380
|
+
);
|
|
381
|
+
};
|
|
529
382
|
|
|
530
383
|
Avatar.propTypes = {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
extraPropsImage: PropTypes.object
|
|
384
|
+
name: PropTypes.string,
|
|
385
|
+
quality: PropTypes.oneOf(['low', 'medium', 'high']),
|
|
386
|
+
size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant']),
|
|
387
|
+
source: PropTypes.oneOfType([
|
|
388
|
+
PropTypes.shape({uri: PropTypes.string}),
|
|
389
|
+
PropTypes.number,
|
|
390
|
+
PropTypes.string,
|
|
391
|
+
]),
|
|
392
|
+
subIcon: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
|
|
393
|
+
topIcon: PropTypes.string,
|
|
394
|
+
|
|
395
|
+
style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
|
|
396
|
+
onPress: PropTypes.func,
|
|
397
|
+
loading: PropTypes.bool,
|
|
398
|
+
shape: PropTypes.oneOf(['circle', 'square']),
|
|
547
399
|
};
|
|
548
400
|
|
|
549
401
|
Avatar.defaultProps = {
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
402
|
+
quality: 'medium',
|
|
403
|
+
size: 'small',
|
|
404
|
+
shape: 'circle',
|
|
405
|
+
name: '',
|
|
554
406
|
};
|
|
407
|
+
|
|
408
|
+
export default Avatar;
|