Chore: Upgraded example-dom to use the new API

This commit is contained in:
Aria Minaei 2021-06-27 13:41:17 +02:00
parent ff582697c8
commit 6e19c51998

View file

@ -46,7 +46,7 @@ const Box: React.FC<{
}, },
onDrag(x, y) { onDrag(x, y) {
if (!firstOnDragCalled) { if (!firstOnDragCalled) {
studio.__experimental_setSelectedObject(obj) studio.__experimental_setSelection([obj])
firstOnDragCalled = true firstOnDragCalled = true
} }
scrub!.capture(({set}) => { scrub!.capture(({set}) => {
@ -69,7 +69,7 @@ const Box: React.FC<{
return ( return (
<div <div
onClick={() => { onClick={() => {
studio.__experimental_setSelectedObject(obj) studio.__experimental_setSelection([obj])
}} }}
ref={setDivRef} ref={setDivRef}
style={{ style={{
@ -93,11 +93,11 @@ export const Scene: React.FC<{project: IProject}> = ({project}) => {
// This is cheap to call and always returns the same value, so no need for useMemo() // This is cheap to call and always returns the same value, so no need for useMemo()
const sheet = project.sheet('Scene', 'default') const sheet = project.sheet('Scene', 'default')
const [studioState, setStudioState] = useState<IStudio['state']>() const [selection, _setSelection] = useState<IStudio['selection']>([])
useLayoutEffect(() => { useLayoutEffect(() => {
return studio.__experimental_onStateChange((newState) => { return studio.__experimental_onSelectionChange((newSelection) => {
setStudioState(newState) _setSelection(newSelection)
}) })
}) })
@ -124,7 +124,7 @@ export const Scene: React.FC<{project: IProject}> = ({project}) => {
key={'box' + id} key={'box' + id}
id={id} id={id}
sheet={sheet} sheet={sheet}
selectedObject={studioState?.selectedObject} selectedObject={selection[0]}
/> />
))} ))}
</div> </div>