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