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