mirror of
https://github.com/billsonnn/nitro-react.git
synced 2024-11-23 14:40:50 +01:00
Update RoomView
This commit is contained in:
parent
3b5974a67b
commit
63f41afe58
@ -1,6 +1,5 @@
|
|||||||
import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
import { EventDispatcher, NitroRectangle, RoomGeometry, RoomVariableEnum, Vector3d } from '@nitrots/nitro-renderer';
|
||||||
import { FC, useEffect, useState } from 'react';
|
import { FC, useEffect, useRef, useState } from 'react';
|
||||||
import { createPortal } from 'react-dom';
|
|
||||||
import { GetNitroInstance, InitializeRoomInstanceRenderingCanvas } from '../../api';
|
import { GetNitroInstance, InitializeRoomInstanceRenderingCanvas } from '../../api';
|
||||||
import { DispatchMouseEvent } from '../../api/nitro/room/DispatchMouseEvent';
|
import { DispatchMouseEvent } from '../../api/nitro/room/DispatchMouseEvent';
|
||||||
import { DispatchTouchEvent } from '../../api/nitro/room/DispatchTouchEvent';
|
import { DispatchTouchEvent } from '../../api/nitro/room/DispatchTouchEvent';
|
||||||
@ -21,6 +20,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
|||||||
const [ roomCanvas, setRoomCanvas ] = useState<HTMLCanvasElement>(null);
|
const [ roomCanvas, setRoomCanvas ] = useState<HTMLCanvasElement>(null);
|
||||||
const [ canvasId, setCanvasId ] = useState(-1);
|
const [ canvasId, setCanvasId ] = useState(-1);
|
||||||
const [ widgetHandler, setWidgetHandler ] = useState<IRoomWidgetHandlerManager>(null);
|
const [ widgetHandler, setWidgetHandler ] = useState<IRoomWidgetHandlerManager>(null);
|
||||||
|
const elementRef = useRef<HTMLDivElement>();
|
||||||
|
|
||||||
useEffect(() =>
|
useEffect(() =>
|
||||||
{
|
{
|
||||||
@ -111,6 +111,8 @@ export const RoomView: FC<RoomViewProps> = props =>
|
|||||||
GetNitroInstance().render();
|
GetNitroInstance().render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(elementRef && elementRef.current) elementRef.current.appendChild(canvas);
|
||||||
|
|
||||||
setRoomCanvas(canvas);
|
setRoomCanvas(canvas);
|
||||||
setCanvasId(canvasId);
|
setCanvasId(canvasId);
|
||||||
}, [ roomSession ]);
|
}, [ roomSession ]);
|
||||||
@ -119,15 +121,12 @@ export const RoomView: FC<RoomViewProps> = props =>
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<RoomContextProvider value={ { roomSession, canvasId, eventDispatcher: (widgetHandler && widgetHandler.eventDispatcher), widgetHandler } }>
|
<RoomContextProvider value={ { roomSession, canvasId, eventDispatcher: (widgetHandler && widgetHandler.eventDispatcher), widgetHandler } }>
|
||||||
<div className="nitro-room w-100 h-100">
|
<div ref={ elementRef } id="room-view" className="nitro-room-container" />
|
||||||
<div id="room-view" className="nitro-room-container"></div>
|
{ widgetHandler &&
|
||||||
{ roomCanvas && createPortal(null, document.getElementById('room-view').appendChild(roomCanvas)) }
|
<>
|
||||||
{ widgetHandler &&
|
<RoomColorView />
|
||||||
<>
|
<RoomWidgetsView />
|
||||||
<RoomColorView />
|
</> }
|
||||||
<RoomWidgetsView />
|
|
||||||
</> }
|
|
||||||
</div>
|
|
||||||
</RoomContextProvider>
|
</RoomContextProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user