mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Update location widget
This commit is contained in:
parent
c55c0c1ee2
commit
535c9560df
@ -5,7 +5,7 @@ import { ObjectLocationViewProps } from './ObjectLocationView.types';
|
|||||||
|
|
||||||
export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
|
export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
|
||||||
{
|
{
|
||||||
const { objectId = -1, objectType = -1, children = null } = props;
|
const { objectId = -1, category = -1, children = null } = props;
|
||||||
const [ posX, setPosX ] = useState(0);
|
const [ posX, setPosX ] = useState(0);
|
||||||
const [ posY, setPosY ] = useState(0);
|
const [ posY, setPosY ] = useState(0);
|
||||||
const elementRef = useRef<HTMLDivElement>();
|
const elementRef = useRef<HTMLDivElement>();
|
||||||
@ -13,13 +13,13 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
|
|||||||
const updatePosition = useCallback(() =>
|
const updatePosition = useCallback(() =>
|
||||||
{
|
{
|
||||||
const roomSession = GetRoomSession();
|
const roomSession = GetRoomSession();
|
||||||
const objectBounds = GetRoomEngine().getRoomObjectBoundingRectangle(roomSession.roomId, objectId, objectType, 1);
|
const objectBounds = GetRoomEngine().getRoomObjectBoundingRectangle(roomSession.roomId, objectId, category, 1);
|
||||||
|
|
||||||
if(!objectBounds) return;
|
if(!objectBounds || !elementRef.current) return;
|
||||||
|
|
||||||
setPosX(Math.round(((objectBounds.left + (objectBounds.width / 2)) - (elementRef.current.offsetWidth / 2))));
|
setPosX(Math.round(((objectBounds.left + (objectBounds.width / 2)) - (elementRef.current.offsetWidth / 2))));
|
||||||
setPosY(Math.round((objectBounds.top - elementRef.current.offsetHeight) + 10));
|
setPosY(Math.round((objectBounds.top - elementRef.current.offsetHeight) + 10));
|
||||||
}, [ objectId, objectType ]);
|
}, [ objectId, category ]);
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
@ -32,7 +32,7 @@ export const ObjectLocationView: FC<ObjectLocationViewProps> = props =>
|
|||||||
}, [ updatePosition ]);
|
}, [ updatePosition ]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div ref={ elementRef } className="position-absolute w-100" style={ { left: posX, top: posY } }>
|
<div ref={ elementRef } className="position-absolute" style={ { left: posX, top: posY } }>
|
||||||
{ children }
|
{ children }
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
export interface ObjectLocationViewProps
|
export interface ObjectLocationViewProps
|
||||||
{
|
{
|
||||||
objectId: number;
|
objectId: number;
|
||||||
objectType: number;
|
category: number;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user