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 { FC, useEffect, useState } from 'react';
|
||||
import { createPortal } from 'react-dom';
|
||||
import { FC, useEffect, useRef, useState } from 'react';
|
||||
import { GetNitroInstance, InitializeRoomInstanceRenderingCanvas } from '../../api';
|
||||
import { DispatchMouseEvent } from '../../api/nitro/room/DispatchMouseEvent';
|
||||
import { DispatchTouchEvent } from '../../api/nitro/room/DispatchTouchEvent';
|
||||
@ -21,6 +20,7 @@ export const RoomView: FC<RoomViewProps> = props =>
|
||||
const [ roomCanvas, setRoomCanvas ] = useState<HTMLCanvasElement>(null);
|
||||
const [ canvasId, setCanvasId ] = useState(-1);
|
||||
const [ widgetHandler, setWidgetHandler ] = useState<IRoomWidgetHandlerManager>(null);
|
||||
const elementRef = useRef<HTMLDivElement>();
|
||||
|
||||
useEffect(() =>
|
||||
{
|
||||
@ -111,6 +111,8 @@ export const RoomView: FC<RoomViewProps> = props =>
|
||||
GetNitroInstance().render();
|
||||
}
|
||||
|
||||
if(elementRef && elementRef.current) elementRef.current.appendChild(canvas);
|
||||
|
||||
setRoomCanvas(canvas);
|
||||
setCanvasId(canvasId);
|
||||
}, [ roomSession ]);
|
||||
@ -119,15 +121,12 @@ export const RoomView: FC<RoomViewProps> = props =>
|
||||
|
||||
return (
|
||||
<RoomContextProvider value={ { roomSession, canvasId, eventDispatcher: (widgetHandler && widgetHandler.eventDispatcher), widgetHandler } }>
|
||||
<div className="nitro-room w-100 h-100">
|
||||
<div id="room-view" className="nitro-room-container"></div>
|
||||
{ roomCanvas && createPortal(null, document.getElementById('room-view').appendChild(roomCanvas)) }
|
||||
{ widgetHandler &&
|
||||
<>
|
||||
<RoomColorView />
|
||||
<RoomWidgetsView />
|
||||
</> }
|
||||
</div>
|
||||
<div ref={ elementRef } id="room-view" className="nitro-room-container" />
|
||||
{ widgetHandler &&
|
||||
<>
|
||||
<RoomColorView />
|
||||
<RoomWidgetsView />
|
||||
</> }
|
||||
</RoomContextProvider>
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user