feat(Avatar): simplified code
This commit is contained in:
parent
2b9ce40533
commit
f5a667ad9e
|
@ -186,17 +186,11 @@ export default class Avatar extends Component<Props, State> {
|
||||||
*/
|
*/
|
||||||
_getBackgroundColor({ uri }) {
|
_getBackgroundColor({ uri }) {
|
||||||
if (!uri) {
|
if (!uri) {
|
||||||
// @lyubomir: I'm leaving @saghul's implementation which picks up a
|
|
||||||
// random color bellow so that we have it in the source code in
|
|
||||||
// case we decide to use it in the future. However, I think at the
|
|
||||||
// time of this writing that the randomness reduces the
|
|
||||||
// predictability which React is supposed to bring to our app.
|
|
||||||
return ColorPalette.white;
|
return ColorPalette.white;
|
||||||
}
|
}
|
||||||
|
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
|
|
||||||
if (typeof uri === 'string') {
|
|
||||||
/* eslint-disable no-bitwise */
|
/* eslint-disable no-bitwise */
|
||||||
|
|
||||||
for (let i = 0; i < uri.length; i++) {
|
for (let i = 0; i < uri.length; i++) {
|
||||||
|
@ -205,11 +199,6 @@ export default class Avatar extends Component<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* eslint-enable no-bitwise */
|
/* eslint-enable no-bitwise */
|
||||||
} else {
|
|
||||||
// @saghul: If we have no URI yet, we have no data to hash from. So
|
|
||||||
// use a random value.
|
|
||||||
hash = Math.floor(Math.random() * 360);
|
|
||||||
}
|
|
||||||
|
|
||||||
return `hsl(${hash % 360}, 100%, 75%)`;
|
return `hsl(${hash % 360}, 100%, 75%)`;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue