Update AvatarImageView

This commit is contained in:
Bill 2021-06-29 15:20:12 -04:00
parent b7e822678f
commit 7bce02f637

View File

@ -1,5 +1,5 @@
import { AvatarScaleType, AvatarSetType } from 'nitro-renderer';
import { FC, useCallback, useEffect, useState } from 'react';
import { FC, useEffect, useState } from 'react';
import { GetAvatarRenderManager } from '../../../api';
import { AvatarImageViewProps } from './AvatarImageView.types';
@ -8,19 +8,20 @@ export const AvatarImageView: FC<AvatarImageViewProps> = props =>
const { figure = '', gender = 'M', headOnly = false, direction = 0, scale = 1 } = props;
const [ avatarUrl, setAvatarUrl ] = useState<string>(null);
const [ randomValue, setRandomValue ] = useState(-1);
const getUserImageUrl = useCallback(() =>
useEffect(() =>
{
let url = null;
if(randomValue) {}
const avatarImage = GetAvatarRenderManager().createAvatarImage(figure, AvatarScaleType.LARGE, gender, {
resetFigure: (figure) => setAvatarUrl(getUserImageUrl()),
resetFigure: figure => setRandomValue(Math.random()),
dispose: () => {},
disposed: false
}, null);
if(avatarImage)
{
if(!avatarImage) return;
let setType = AvatarSetType.FULL;
if(headOnly) setType = AvatarSetType.HEAD;
@ -29,18 +30,10 @@ export const AvatarImageView: FC<AvatarImageViewProps> = props =>
const image = avatarImage.getCroppedImage(setType);
if(image) url = image.src;
if(image) setAvatarUrl(image.src);
avatarImage.dispose();
}
return url;
}, [ figure, gender, direction, headOnly ]);
useEffect(() =>
{
setAvatarUrl(getUserImageUrl());
}, [ getUserImageUrl ]);
}, [ figure, gender, direction, headOnly, randomValue ]);
const url = `url('${ avatarUrl }')`;