@momo-kits/avatar 0.0.65-beta → 0.0.65-beta.2

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.
Files changed (4) hide show
  1. package/Avatar.js +359 -501
  2. package/Avatar.web.js +355 -502
  3. package/package.json +14 -14
  4. package/publish.sh +2 -2
package/Avatar.js CHANGED
@@ -1,550 +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
- ValueUtil, Colors, Text, IconSource, Image, ScaleSize
10
- } from '@momo-kits/core';
11
-
12
- export const AvatarQuality = {
13
- low: 'low',
14
- medium: 'medium',
15
- high: 'high',
16
- };
17
-
18
- export const AvatarSize = {
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
- export const SubIconType = {
39
- momo: 'momo',
40
- online: 'online',
41
- key: 'key',
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
- container: {
47
- justifyContent: 'center',
48
- alignItems: 'center'
49
- },
50
- shortNameView: {
51
- justifyContent: 'center',
52
- alignItems: 'center',
53
-
54
- backgroundColor: Colors.very_light_pink_four,
55
- width: '100%',
56
- height: '100%'
57
- },
58
- shortNameText: {
59
- // fontSize: 17,
60
- color: '#f6f6f6'
61
- },
62
- absolute: {
63
- position: 'absolute',
64
- top: 0,
65
- left: 0,
66
- right: 0,
67
- bottom: 0
68
- },
69
- subIcon: {
70
- position: 'absolute',
71
- bottom: 0,
72
- right: 0
73
- },
74
- subIconImage: {
75
- width: 22,
76
- height: 22
77
- },
78
- subIconImageOnline: {
79
- backgroundColor: Colors.kiwi_green,
80
- borderColor: 'white',
81
- borderWidth: 1
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 = (width) => ({
86
- tiny: {
87
- width: 8,
88
- height: 8,
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
- large: {
102
- width: 16,
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
- size24: {
112
- width: 10,
113
- height: 10,
114
- borderRadius: 5
115
- },
116
- size36: {
117
- width: 10,
118
- height: 10,
119
- borderRadius: 5
120
- },
121
- size44: {
122
- width: 14,
123
- height: 14,
124
- borderRadius: 7
125
- },
126
- size48: {
127
- width: 14,
128
- height: 14,
129
- borderRadius: 7
130
- },
131
- size52: {
132
- width: 16,
133
- height: 16,
134
- borderRadius: 8
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
- borderRadius: 12
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
- borderRadius: 16
195
- },
196
- medium: {
113
+ };
114
+ }
115
+ case 'medium':
116
+ return {
197
117
  width: 40,
198
118
  height: 40,
199
- borderRadius: 20
200
- },
201
- large: {
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
- borderRadius: 28
245
- },
246
- size64: {
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
- borderRadius: 36
255
- },
256
- size80: {
257
- width: 80,
258
- height: 80,
259
- borderRadius: 40
260
- },
261
- size88: {
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
- }
301
-
302
- componentDidMount() {
303
- const { scaleSize } = this.props;
304
- if (scaleSize) {
305
- this.subscription = Dimensions.addEventListener(
306
- 'change',
307
- ({ window }) => {
308
- this.setState({ dimensions: window });
309
- }
310
- );
311
- }
312
- }
313
-
314
- componentWillUnmount() {
315
- const { scaleSize } = this.props;
316
- if (scaleSize) {
317
- this.subscription?.remove?.();
318
- }
319
- }
129
+ };
130
+ default:
131
+ return {
132
+ width: 40,
133
+ height: 40,
134
+ };
135
+ }
136
+ };
320
137
 
321
- static getDerivedStateFromProps(nextProps, prevState) {
322
- if (prevState.ownUpdate) {
323
- return {
324
- ownUpdate: false,
325
- };
326
- } if (!isEqual(nextProps.source, prevState.source)) {
327
- return { source: nextProps.source, hideSource: false };
328
- }
329
- return null;
330
- }
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
+ };
331
172
 
332
- getContactShortName = (name) => {
333
- if (!name) return '';
334
- const shortNameList = name.split(' ', 2);
335
- const alphabet = [];
336
- shortNameList.forEach((n) => {
337
- if (n && n.length > 0) {
338
- alphabet.push(n[0].toString().toUpperCase());
339
- }
340
- });
341
- return alphabet.join('');
342
- }
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);
343
194
 
344
- renderShortName = (name, avatarStyle, size) => {
345
- if (name) {
346
- const shortedName = this.getContactShortName(name);
347
- const shortNameStyle = this.mapShortNameStyle(size);
348
- return (
349
- <View style={[styles.shortNameView, avatarStyle]}>
350
- <Text.H4 style={[styles.shortNameText, shortNameStyle]}>{shortedName}</Text.H4>
351
- </View>
352
- );
353
- }
354
- return <View />;
355
- }
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
+ };
356
214
 
357
- isUrl(url) {
358
- const expression = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/gi;
359
- return expression.test(url);
360
- }
215
+ const isValidImageUrl = source => {
216
+ return source && source.uri && isUrl(source.uri);
217
+ };
361
218
 
362
- isValidImageUrl = (source) => {
363
- const validSource = source && source.uri && this.isUrl(source.uri);
364
- return validSource;
219
+ const mapAvatarQuality = (url, quality) => {
220
+ if (!quality || quality === AvatarQuality.medium) {
221
+ return url;
365
222
  }
366
-
367
- mapAvatarQuality = (url, quality) => {
368
- if (!quality || quality === AvatarQuality.medium) {
369
- return url;
370
- }
371
- if (quality === AvatarQuality.low) {
372
- return url.replace('.png', '_s64.png');
373
- }
374
- if (quality === AvatarQuality.high) {
375
- return url.replace('.png', '_s512.png');
376
- }
377
-
378
- return url;
223
+ if (quality === AvatarQuality.low) {
224
+ return url.replace('.png', '_s64.png');
379
225
  }
380
-
381
- mapStyleFromSize = (size) => {
382
- const { dimensions } = this.state;
383
- const avatarStyle = avatarSize(dimensions?.width || null).small;
384
- if (typeof size === 'object') return size;
385
- if (avatarSize(dimensions?.width || null)[size]) return avatarSize(dimensions?.width || null)[size];
386
- return avatarStyle;
226
+ if (quality === AvatarQuality.high) {
227
+ return url.replace('.png', '_s512.png');
387
228
  }
388
229
 
389
- mapShortNameStyle = (size) => {
390
- let shortNameStyle = {};
391
- const { dimensions } = this.state;
392
- switch (size) {
393
- case AvatarSize.tiny: {
394
- shortNameStyle = shortName(dimensions?.width || null).tiny;
395
- break;
396
- }
397
- case AvatarSize.small: {
398
- shortNameStyle = shortName(dimensions?.width || null).small;
399
- break;
400
- }
401
- case AvatarSize.medium: {
402
- shortNameStyle = shortName(dimensions?.width || null).medium;
403
- break;
404
- }
405
- case AvatarSize.large: {
406
- shortNameStyle = shortName(dimensions?.width || null).large;
407
- break;
408
- }
409
- case AvatarSize.giant: {
410
- shortNameStyle = shortName(dimensions?.width || null).giant;
411
- break;
412
- }
413
- default:
414
- shortNameStyle = shortName(dimensions?.width || null).small;
415
- }
416
- return shortNameStyle;
417
- }
230
+ return url;
231
+ };
418
232
 
419
- mapSubIconSize = (size) => {
420
- const { dimensions } = this.state;
421
- const subIconStyle = subIconSize(dimensions?.width || null).small;
422
- if (subIconSize(dimensions?.width || null)[size]) return subIconSize(dimensions?.width || null)[size];
423
- return subIconStyle;
424
- }
233
+ const onLoadSourceError = source => {
234
+ setImageSource(source);
235
+ };
425
236
 
426
- extractSize = (avatarStyle) => {
427
- const { style } = this.props;
428
- const borderWidth = get(style, 'borderWidth', 1);
429
- const containerWidth = Math.round(avatarStyle.width + 2 + borderWidth);
430
- return {
431
- width: containerWidth,
432
- height: containerWidth,
433
- borderRadius: containerWidth / 2,
434
- borderWidth,
435
- borderColor: Colors.black_01
436
- };
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
+ );
437
269
  }
270
+ };
438
271
 
439
- onLoadSourceError = () => {
440
- this.setState({ hideSource: true, ownUpdate: true });
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
+ );
441
299
  }
300
+ };
442
301
 
443
- renderSubIcon = () => {
444
- const { subIcon, size, subIconSource } = this.props;
445
- if ((!subIcon || subIcon === SubIconType.none) && !subIconSource) return <View />;
446
- const subIconSizeStyle = this.mapSubIconSize(size);
447
- const iconSource = ValueUtil.getImageSource(subIconSource);
448
- return (
449
- <View style={styles.subIcon}>
450
- {subIcon === SubIconType.momo
451
- ? (
452
- <Image
453
- style={[styles.subIconImage, subIconSizeStyle]}
454
- source={IconSource.ic_round_momo_tiny}
455
- />
456
- )
457
- : <View />}
458
- {subIcon === SubIconType.online
459
- ? <View style={[styles.subIconImageOnline, subIconSizeStyle]} /> : <View />}
302
+ const onPressIcon = () => {
303
+ if (onPress && typeof onPress === 'function') onPress();
304
+ };
460
305
 
461
- {iconSource && subIconSource && !subIcon ? (
462
- <Image
463
- style={[styles.subIconImage, subIconSizeStyle]}
464
- source={iconSource}
465
- />
466
- )
467
- : <View />}
468
- </View>
469
- );
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
+ );
470
331
  }
332
+ return <View />;
333
+ };
471
334
 
472
- onPress = () => {
473
- const { onPress } = this.props;
474
- if (onPress && typeof onPress === 'function') onPress();
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}`;
475
342
  }
343
+ }
476
344
 
477
- render() {
478
- const {
479
- size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage, quality
480
- } = this.props;
481
- const { hideSource } = this.state;
482
- const avatarStyle = this.mapStyleFromSize(size);
483
- const containerSize = this.extractSize(avatarStyle);
484
- const imageSource = ValueUtil.getImageSource(source);
485
- const showName = typeof imageSource === 'object' && Object.keys(imageSource).length === 0 && typeof imageSource !== 'number';
486
- // add priority high for avatar
487
- if (imageSource?.uri) {
488
- imageSource.priority = 'high';
489
- imageSource.uri = this.mapAvatarQuality(imageSource.uri, quality);
490
- // if doest not have time query, set default cache time to 1 day
491
- if (!imageSource.uri?.includes('?') && cached) {
492
- const midnight = new Date().setHours(0, 0, 0, 0);
493
- imageSource.uri = `${imageSource.uri}?time=${midnight}`;
494
- }
495
- }
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
+ };
496
363
 
497
- const inner = (
498
- <View style={[styles.container, containerSize, style]}>
499
- {(showName || hideSource) ? this.renderShortName(name, avatarStyle, size) : <View />}
500
- {this.isValidImageUrl(imageSource) && !hideSource
501
- ? (
502
- <Image
503
- cached={cached}
504
- loading={loading || isShowLoading}
505
- source={imageSource}
506
- onError={this.onLoadSourceError}
507
- style={avatarStyle}
508
- resizeMode={resizeMode}
509
- {...extraPropsImage}
510
- />
511
- ) : <View />}
512
- {this.renderSubIcon()}
513
- </View>
514
- );
515
- if (onPress) {
516
- return (
517
- <TouchableOpacity activeOpacity={onPress ? 0.5 : 1} onPress={this.onPress}>
518
- {inner}
519
- </TouchableOpacity>
520
- );
521
- }
522
- return inner;
523
- }
524
- }
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
+ };
525
382
 
526
383
  Avatar.propTypes = {
527
- name: PropTypes.string,
528
- resizeMode: PropTypes.string,
529
- quality: PropTypes.oneOf(['low', 'medium', 'high']),
530
- size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant', 'size8', 'size24', 'size36', 'size44', 'size48', 'size52', 'size56', 'size64', 'size72', 'size80', 'size88', 'size96',
531
- PropTypes.shape({
532
- width: PropTypes.number, height: PropTypes.number, borderRadius: PropTypes.number
533
- })]),
534
- source: PropTypes.oneOfType([PropTypes.shape({ uri: PropTypes.string }), PropTypes.number, PropTypes.string]),
535
- subIcon: PropTypes.oneOf(['momo', 'online', 'key', 'none']),
536
- subIconSource: PropTypes.oneOfType([PropTypes.shape({ uri: PropTypes.string }), PropTypes.number, PropTypes.string]),
537
- style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
538
- onPress: PropTypes.func,
539
- loading: PropTypes.bool,
540
- cached: PropTypes.bool,
541
- scaleSize: PropTypes.bool,
542
- 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']),
543
399
  };
544
400
 
545
401
  Avatar.defaultProps = {
546
- resizeMode: 'cover',
547
- cached: true,
548
- scaleSize: false,
549
- quality: 'medium',
402
+ quality: 'medium',
403
+ size: 'small',
404
+ shape: 'circle',
405
+ name: '',
550
406
  };
407
+
408
+ export default Avatar;