mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-27 08:00:51 +01:00
Update BadgeImageView
This commit is contained in:
parent
9ed49c902c
commit
263212f650
@ -8,6 +8,11 @@
|
||||
&.group-badge {
|
||||
width: 39px;
|
||||
height: 39px;
|
||||
|
||||
&.scale-2 {
|
||||
width: 80px;
|
||||
height: 80px;
|
||||
}
|
||||
}
|
||||
|
||||
.badge-information {
|
||||
|
@ -18,7 +18,6 @@ export const BadgeImageView: FC<BadgeImageViewProps> = props =>
|
||||
{
|
||||
const { badgeCode = null, isGroup = false, showInfo = false, customTitle = null, isGrayscale = false, scale = 1, classNames = [], style = {}, children = null, ...rest } = props;
|
||||
const [ badgeUrl, setBadgeUrl ] = useState<string>('');
|
||||
const [ isListening, setIsListening ] = useState<boolean>(true);
|
||||
|
||||
const getScaleClass = useMemo(() =>
|
||||
{
|
||||
@ -65,41 +64,27 @@ export const BadgeImageView: FC<BadgeImageViewProps> = props =>
|
||||
{
|
||||
if(!badgeCode || !badgeCode.length) return;
|
||||
|
||||
const existing = (isGroup) ? GetSessionDataManager().loadGroupBadgeImage(badgeCode) : GetSessionDataManager().loadBadgeImage(badgeCode);
|
||||
let didSetBadge = false;
|
||||
|
||||
const onBadgeImageReadyEvent = (event: BadgeImageReadyEvent) =>
|
||||
{
|
||||
if(event.badgeId !== badgeCode) return;
|
||||
|
||||
const nitroSprite = new NitroSprite(event.image);
|
||||
setBadgeUrl(TextureUtils.generateImageUrl(nitroSprite));
|
||||
setBadgeUrl(TextureUtils.generateImageUrl(new NitroSprite(event.image)));
|
||||
|
||||
didSetBadge = true;
|
||||
|
||||
if(isListening)
|
||||
{
|
||||
GetSessionDataManager().events.removeEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent);
|
||||
setIsListening(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(!existing)
|
||||
{
|
||||
GetSessionDataManager().events.addEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent);
|
||||
}
|
||||
else
|
||||
{
|
||||
const image = (isGroup) ? GetSessionDataManager().getGroupBadgeImage(badgeCode) : GetSessionDataManager().getBadgeImage(badgeCode);
|
||||
const nitroSprite = new NitroSprite(image);
|
||||
setBadgeUrl(TextureUtils.generateImageUrl(nitroSprite));
|
||||
}
|
||||
|
||||
return (() =>
|
||||
{
|
||||
if(isListening)
|
||||
{
|
||||
GetSessionDataManager().events.removeEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent);
|
||||
}
|
||||
});
|
||||
}, [ badgeCode, isGroup, isListening ]);
|
||||
const texture = isGroup ? GetSessionDataManager().getGroupBadgeImage(badgeCode) : GetSessionDataManager().getBadgeImage(badgeCode);
|
||||
|
||||
if(texture && !didSetBadge) setBadgeUrl(TextureUtils.generateImageUrl(new NitroSprite(texture)));
|
||||
|
||||
return () => GetSessionDataManager().events.removeEventListener(BadgeImageReadyEvent.IMAGE_READY, onBadgeImageReadyEvent);
|
||||
}, [ badgeCode, isGroup ]);
|
||||
|
||||
return (
|
||||
<Base classNames={ getClassNames } style={ getStyle } { ...rest }>
|
||||
|
Loading…
Reference in New Issue
Block a user