mirror of
https://github.com/billsonnn/nitro-react.git
synced 2025-01-19 05:46:27 +01:00
Update AvatarImageView
This commit is contained in:
parent
b7e822678f
commit
7bce02f637
@ -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 }')`;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user