@momo-kits/avatar 0.0.62-beta → 0.0.66-beta
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 +43 -6
- package/Avatar.web.js +36 -3
- package/package.json +1 -1
- package/publish.sh +1 -1
package/Avatar.js
CHANGED
|
@@ -9,6 +9,12 @@ import {
|
|
|
9
9
|
ValueUtil, Colors, Text, IconSource, Image, ScaleSize
|
|
10
10
|
} from '@momo-kits/core';
|
|
11
11
|
|
|
12
|
+
export const AvatarQuality = {
|
|
13
|
+
low: 'low',
|
|
14
|
+
medium: 'medium',
|
|
15
|
+
high: 'high',
|
|
16
|
+
};
|
|
17
|
+
|
|
12
18
|
export const AvatarSize = {
|
|
13
19
|
tiny: 'tiny',
|
|
14
20
|
small: 'small',
|
|
@@ -291,6 +297,7 @@ export default class Avatar extends Component {
|
|
|
291
297
|
source: props.source,
|
|
292
298
|
dimensions: {}
|
|
293
299
|
};
|
|
300
|
+
this.imageSource = '';
|
|
294
301
|
}
|
|
295
302
|
|
|
296
303
|
componentDidMount() {
|
|
@@ -354,10 +361,24 @@ export default class Avatar extends Component {
|
|
|
354
361
|
}
|
|
355
362
|
|
|
356
363
|
isValidImageUrl = (source) => {
|
|
357
|
-
const validSource = source &&
|
|
364
|
+
const validSource = source && source.uri && this.isUrl(source.uri);
|
|
358
365
|
return validSource;
|
|
359
366
|
}
|
|
360
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;
|
|
380
|
+
}
|
|
381
|
+
|
|
361
382
|
mapStyleFromSize = (size) => {
|
|
362
383
|
const { dimensions } = this.state;
|
|
363
384
|
const avatarStyle = avatarSize(dimensions?.width || null).small;
|
|
@@ -416,8 +437,11 @@ export default class Avatar extends Component {
|
|
|
416
437
|
};
|
|
417
438
|
}
|
|
418
439
|
|
|
419
|
-
onLoadSourceError = () => {
|
|
420
|
-
this.
|
|
440
|
+
onLoadSourceError = (imageSource) => {
|
|
441
|
+
if(this.imageSource?.uri !== imageSource?.uri){
|
|
442
|
+
this.imageSource = imageSource;
|
|
443
|
+
this.setState({ hideSource: true, ownUpdate: true });
|
|
444
|
+
}
|
|
421
445
|
}
|
|
422
446
|
|
|
423
447
|
renderSubIcon = () => {
|
|
@@ -456,13 +480,24 @@ export default class Avatar extends Component {
|
|
|
456
480
|
|
|
457
481
|
render() {
|
|
458
482
|
const {
|
|
459
|
-
size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage
|
|
483
|
+
size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage, quality
|
|
460
484
|
} = this.props;
|
|
461
485
|
const { hideSource } = this.state;
|
|
462
486
|
const avatarStyle = this.mapStyleFromSize(size);
|
|
463
487
|
const containerSize = this.extractSize(avatarStyle);
|
|
464
488
|
const imageSource = ValueUtil.getImageSource(source);
|
|
465
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
|
+
}
|
|
500
|
+
|
|
466
501
|
const inner = (
|
|
467
502
|
<View style={[styles.container, containerSize, style]}>
|
|
468
503
|
{(showName || hideSource) ? this.renderShortName(name, avatarStyle, size) : <View />}
|
|
@@ -472,7 +507,7 @@ export default class Avatar extends Component {
|
|
|
472
507
|
cached={cached}
|
|
473
508
|
loading={loading || isShowLoading}
|
|
474
509
|
source={imageSource}
|
|
475
|
-
onError={this.onLoadSourceError}
|
|
510
|
+
onError={() => this.onLoadSourceError(imageSource)}
|
|
476
511
|
style={avatarStyle}
|
|
477
512
|
resizeMode={resizeMode}
|
|
478
513
|
{...extraPropsImage}
|
|
@@ -495,6 +530,7 @@ export default class Avatar extends Component {
|
|
|
495
530
|
Avatar.propTypes = {
|
|
496
531
|
name: PropTypes.string,
|
|
497
532
|
resizeMode: PropTypes.string,
|
|
533
|
+
quality: PropTypes.oneOf(['low', 'medium', 'high']),
|
|
498
534
|
size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant', 'size8', 'size24', 'size36', 'size44', 'size48', 'size52', 'size56', 'size64', 'size72', 'size80', 'size88', 'size96',
|
|
499
535
|
PropTypes.shape({
|
|
500
536
|
width: PropTypes.number, height: PropTypes.number, borderRadius: PropTypes.number
|
|
@@ -513,5 +549,6 @@ Avatar.propTypes = {
|
|
|
513
549
|
Avatar.defaultProps = {
|
|
514
550
|
resizeMode: 'cover',
|
|
515
551
|
cached: true,
|
|
516
|
-
scaleSize: false
|
|
552
|
+
scaleSize: false,
|
|
553
|
+
quality: 'medium',
|
|
517
554
|
};
|
package/Avatar.web.js
CHANGED
|
@@ -11,6 +11,12 @@ import { Icons as IconSource } from '../../core/icons';
|
|
|
11
11
|
import Text from '../../core/components/typography';
|
|
12
12
|
import { RFValueHorizontal as ScaleSize } from '../../core/components/typography/reponsiveSize';
|
|
13
13
|
|
|
14
|
+
export const AvatarQuality = {
|
|
15
|
+
low: 'low',
|
|
16
|
+
medium: 'medium',
|
|
17
|
+
high: 'high',
|
|
18
|
+
};
|
|
19
|
+
|
|
14
20
|
export const AvatarSize = {
|
|
15
21
|
tiny: 'tiny',
|
|
16
22
|
small: 'small',
|
|
@@ -356,10 +362,24 @@ export default class Avatar extends Component {
|
|
|
356
362
|
}
|
|
357
363
|
|
|
358
364
|
isValidImageUrl = (source) => {
|
|
359
|
-
const validSource = source &&
|
|
365
|
+
const validSource = source && source.uri && this.isUrl(source.uri);
|
|
360
366
|
return validSource;
|
|
361
367
|
}
|
|
362
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;
|
|
381
|
+
}
|
|
382
|
+
|
|
363
383
|
mapStyleFromSize = (size) => {
|
|
364
384
|
const { dimensions } = this.state;
|
|
365
385
|
const avatarStyle = avatarSize(dimensions?.width || null).small;
|
|
@@ -458,13 +478,24 @@ export default class Avatar extends Component {
|
|
|
458
478
|
|
|
459
479
|
render() {
|
|
460
480
|
const {
|
|
461
|
-
size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage
|
|
481
|
+
size, source, name, resizeMode, style, onPress, isShowLoading, loading, cached, extraPropsImage, quality
|
|
462
482
|
} = this.props;
|
|
463
483
|
const { hideSource } = this.state;
|
|
464
484
|
const avatarStyle = this.mapStyleFromSize(size);
|
|
465
485
|
const containerSize = this.extractSize(avatarStyle);
|
|
466
486
|
const imageSource = ValueUtil.getImageSource(source);
|
|
467
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
|
+
}
|
|
498
|
+
|
|
468
499
|
const inner = (
|
|
469
500
|
<View style={[styles.container, containerSize, style]}>
|
|
470
501
|
{(showName || hideSource) ? this.renderShortName(name, avatarStyle, size) : <View />}
|
|
@@ -497,6 +528,7 @@ export default class Avatar extends Component {
|
|
|
497
528
|
Avatar.propTypes = {
|
|
498
529
|
name: PropTypes.string,
|
|
499
530
|
resizeMode: PropTypes.string,
|
|
531
|
+
quality: PropTypes.oneOf(['low', 'medium', 'high']),
|
|
500
532
|
size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large', 'giant', 'size8', 'size24', 'size36', 'size44', 'size48', 'size52', 'size56', 'size64', 'size72', 'size80', 'size88', 'size96',
|
|
501
533
|
PropTypes.shape({
|
|
502
534
|
width: PropTypes.number, height: PropTypes.number, borderRadius: PropTypes.number
|
|
@@ -515,5 +547,6 @@ Avatar.propTypes = {
|
|
|
515
547
|
Avatar.defaultProps = {
|
|
516
548
|
resizeMode: 'cover',
|
|
517
549
|
cached: true,
|
|
518
|
-
scaleSize: false
|
|
550
|
+
scaleSize: false,
|
|
551
|
+
quality: 'medium',
|
|
519
552
|
};
|
package/package.json
CHANGED
package/publish.sh
CHANGED
|
@@ -26,4 +26,4 @@ cd ..
|
|
|
26
26
|
rm -rf dist
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
curl -X POST -H 'Content-Type: application/json' 'https://chat.googleapis.com/v1/spaces/AAAAbP8987c/messages?key=AIzaSyDdI0hCZtE6vySjMm-WEfRq3CPzqKqqsHI&token=UGSFRvk_oYb9uGsAgs31bVvMm6jDkmD8zihGm3eyaQA%3D&threadKey=JoaXTEYaNNkl' -d '{"text": "@momo-kits/avatar new version release: '*"$VERSION"*' https://www.npmjs.com/package/@momo-kits/avatar"}'
|