@momo-kits/avatar 0.0.8 → 0.0.13
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 +8 -9
- package/Avatar.web.js +11 -0
- package/package.json +1 -1
package/Avatar.js
CHANGED
|
@@ -317,7 +317,7 @@ const shortName = (width) => ({
|
|
|
317
317
|
export default class Avatar extends Component {
|
|
318
318
|
constructor(props) {
|
|
319
319
|
super(props);
|
|
320
|
-
this.color = this.getAvatarColor();
|
|
320
|
+
this.color = this.getAvatarColor(props.name);
|
|
321
321
|
this.state = {
|
|
322
322
|
hideSource: false,
|
|
323
323
|
ownUpdate: false,
|
|
@@ -518,14 +518,13 @@ export default class Avatar extends Component {
|
|
|
518
518
|
);
|
|
519
519
|
}
|
|
520
520
|
|
|
521
|
-
getAvatarColor() {
|
|
522
|
-
const
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
return '#d5d6d6';
|
|
521
|
+
getAvatarColor(name) {
|
|
522
|
+
const shortName = this.getContactShortName(name)
|
|
523
|
+
if (!shortName) return "#d5d6d6"
|
|
524
|
+
const firstLetter = shortName[0].charCodeAt(0)
|
|
525
|
+
let colorIndex = Number(firstLetter) % 26
|
|
526
|
+
if (colorIndex > 19) colorIndex = 25 - colorIndex
|
|
527
|
+
return COLORS[colorIndex]
|
|
529
528
|
}
|
|
530
529
|
|
|
531
530
|
onPress = () => {
|
package/Avatar.web.js
CHANGED
|
@@ -293,6 +293,7 @@ const shortName = (width) => ({
|
|
|
293
293
|
export default class Avatar extends Component {
|
|
294
294
|
constructor(props) {
|
|
295
295
|
super(props);
|
|
296
|
+
this.color = this.getAvatarColor(props.name);
|
|
296
297
|
this.state = {
|
|
297
298
|
hideSource: false,
|
|
298
299
|
ownUpdate: false,
|
|
@@ -440,6 +441,16 @@ export default class Avatar extends Component {
|
|
|
440
441
|
};
|
|
441
442
|
}
|
|
442
443
|
|
|
444
|
+
getAvatarColor(name) {
|
|
445
|
+
const shortName = this.getContactShortName(name)
|
|
446
|
+
if (!shortName) return "#d5d6d6"
|
|
447
|
+
const firstLetter = shortName[0].charCodeAt(0)
|
|
448
|
+
let colorIndex = Number(firstLetter) % 26
|
|
449
|
+
if (colorIndex > 19) colorIndex = 25 - colorIndex
|
|
450
|
+
return COLORS[colorIndex]
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
|
|
443
454
|
onLoadSourceError = () => {
|
|
444
455
|
this.setState({ hideSource: true, ownUpdate: true });
|
|
445
456
|
}
|