@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.
Files changed (4) hide show
  1. package/Avatar.js +359 -505
  2. package/Avatar.web.js +355 -502
  3. package/package.json +14 -14
  4. 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
- 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
- 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
- static getDerivedStateFromProps(nextProps, prevState) {
323
- if (prevState.ownUpdate) {
324
- return {
325
- ownUpdate: false,
326
- };
327
- } if (!isEqual(nextProps.source, prevState.source)) {
328
- return { source: nextProps.source, hideSource: false };
329
- }
330
- return null;
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
- getContactShortName = (name) => {
334
- if (!name) return '';
335
- const shortNameList = name.split(' ', 2);
336
- const alphabet = [];
337
- shortNameList.forEach((n) => {
338
- if (n && n.length > 0) {
339
- alphabet.push(n[0].toString().toUpperCase());
340
- }
341
- });
342
- return alphabet.join('');
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
- renderShortName = (name, avatarStyle, size) => {
346
- if (name) {
347
- const shortedName = this.getContactShortName(name);
348
- const shortNameStyle = this.mapShortNameStyle(size);
349
- return (
350
- <View style={[styles.shortNameView, avatarStyle]}>
351
- <Text.H4 style={[styles.shortNameText, shortNameStyle]}>{shortedName}</Text.H4>
352
- </View>
353
- );
354
- }
355
- return <View />;
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
- isUrl(url) {
359
- const expression = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/gi;
360
- return expression.test(url);
361
- }
215
+ const isValidImageUrl = source => {
216
+ return source && source.uri && isUrl(source.uri);
217
+ };
362
218
 
363
- isValidImageUrl = (source) => {
364
- const validSource = source && source.uri && this.isUrl(source.uri);
365
- return validSource;
219
+ const mapAvatarQuality = (url, quality) => {
220
+ if (!quality || quality === AvatarQuality.medium) {
221
+ return url;
366
222
  }
367
-
368
- mapAvatarQuality = (url, quality) => {
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
- mapStyleFromSize = (size) => {
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
- mapShortNameStyle = (size) => {
391
- let shortNameStyle = {};
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
- mapSubIconSize = (size) => {
421
- const { dimensions } = this.state;
422
- const subIconStyle = subIconSize(dimensions?.width || null).small;
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
- extractSize = (avatarStyle) => {
428
- const { style } = this.props;
429
- const borderWidth = get(style, 'borderWidth', 1);
430
- const containerWidth = Math.round(avatarStyle.width + 2 + borderWidth);
431
- return {
432
- width: containerWidth,
433
- height: containerWidth,
434
- borderRadius: containerWidth / 2,
435
- borderWidth,
436
- borderColor: Colors.black_01
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
- onLoadSourceError = (imageSource) => {
441
- if(this.imageSource?.uri !== imageSource?.uri){
442
- this.imageSource = imageSource;
443
- this.setState({ hideSource: true, ownUpdate: true });
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
- renderSubIcon = () => {
448
- const { subIcon, size, subIconSource } = this.props;
449
- if ((!subIcon || subIcon === SubIconType.none) && !subIconSource) return <View />;
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
- {iconSource && subIconSource && !subIcon ? (
466
- <Image
467
- style={[styles.subIconImage, subIconSizeStyle]}
468
- source={iconSource}
469
- />
470
- )
471
- : <View />}
472
- </View>
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
- onPress = () => {
477
- const { onPress } = this.props;
478
- 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}`;
479
342
  }
343
+ }
480
344
 
481
- render() {
482
- const {
483
- size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage, quality
484
- } = this.props;
485
- const { hideSource } = this.state;
486
- const avatarStyle = this.mapStyleFromSize(size);
487
- const containerSize = this.extractSize(avatarStyle);
488
- const imageSource = ValueUtil.getImageSource(source);
489
- const showName = typeof imageSource === 'object' && Object.keys(imageSource).length === 0 && typeof imageSource !== 'number';
490
- // add priority high for avatar
491
- if (imageSource?.uri) {
492
- imageSource.priority = 'high';
493
- imageSource.uri = this.mapAvatarQuality(imageSource.uri, quality);
494
- // if doest not have time query, set default cache time to 1 day
495
- if (!imageSource.uri?.includes('?') && cached) {
496
- const midnight = new Date().setHours(0, 0, 0, 0);
497
- imageSource.uri = `${imageSource.uri}?time=${midnight}`;
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
- const inner = (
502
- <View style={[styles.container, containerSize, style]}>
503
- {(showName || hideSource) ? this.renderShortName(name, avatarStyle, size) : <View />}
504
- {this.isValidImageUrl(imageSource) && !hideSource
505
- ? (
506
- <Image
507
- cached={cached}
508
- loading={loading || isShowLoading}
509
- source={imageSource}
510
- onError={() => this.onLoadSourceError(imageSource)}
511
- style={avatarStyle}
512
- resizeMode={resizeMode}
513
- {...extraPropsImage}
514
- />
515
- ) : <View />}
516
- {this.renderSubIcon()}
517
- </View>
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
- name: PropTypes.string,
532
- resizeMode: PropTypes.string,
533
- quality: PropTypes.oneOf(['low', 'medium', 'high']),
534
- size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant', 'size8', 'size24', 'size36', 'size44', 'size48', 'size52', 'size56', 'size64', 'size72', 'size80', 'size88', 'size96',
535
- PropTypes.shape({
536
- width: PropTypes.number, height: PropTypes.number, borderRadius: PropTypes.number
537
- })]),
538
- source: PropTypes.oneOfType([PropTypes.shape({ uri: PropTypes.string }), PropTypes.number, PropTypes.string]),
539
- subIcon: PropTypes.oneOf(['momo', 'online', 'key', 'none']),
540
- subIconSource: PropTypes.oneOfType([PropTypes.shape({ uri: PropTypes.string }), PropTypes.number, PropTypes.string]),
541
- style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
542
- onPress: PropTypes.func,
543
- loading: PropTypes.bool,
544
- cached: PropTypes.bool,
545
- scaleSize: PropTypes.bool,
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
- resizeMode: 'cover',
551
- cached: true,
552
- scaleSize: false,
553
- quality: 'medium',
402
+ quality: 'medium',
403
+ size: 'small',
404
+ shape: 'circle',
405
+ name: '',
554
406
  };
407
+
408
+ export default Avatar;