This commit is contained in:
@@ -8,8 +8,4 @@ export default class TestUi1 extends Control {
|
|||||||
_ready(): void {
|
_ready(): void {
|
||||||
Renderer.renderComponent(this, TestUi1Component)
|
Renderer.renderComponent(this, TestUi1Component)
|
||||||
}
|
}
|
||||||
|
|
||||||
_exit_tree(): void {
|
|
||||||
console.log("exit tree")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the "empty props" type in React */
|
/** biome-ignore-all lint/complexity/noBannedTypes: {} is the "empty props" type in React */
|
||||||
import type { Node, NodePathMap } from "godot"
|
import { Callable, type Node, type NodePathMap } from "godot"
|
||||||
import * as React from "react"
|
import * as React from "react"
|
||||||
import * as Reconciler from "./Reconciler.js"
|
import * as Reconciler from "./Reconciler.js"
|
||||||
|
|
||||||
@@ -21,10 +21,11 @@ export const renderComponent: {
|
|||||||
component: React.FC<{}>,
|
component: React.FC<{}>,
|
||||||
props?: Record<string, unknown>,
|
props?: Record<string, unknown>,
|
||||||
): void => {
|
): void => {
|
||||||
const reconciler = Reconciler.make()
|
if (!(container as any)._reactReconciler)
|
||||||
|
(container as any)._reactReconciler = Reconciler.make()
|
||||||
|
|
||||||
if (!(container as any)._rootContainer)
|
if (!(container as any)._reactContainer) {
|
||||||
(container as any)._rootContainer = (reconciler as any).createContainer(
|
(container as any)._reactContainer = (container as any)._reactReconciler.createContainer(
|
||||||
container,
|
container,
|
||||||
ConcurrentRoot,
|
ConcurrentRoot,
|
||||||
null,
|
null,
|
||||||
@@ -34,9 +35,23 @@ export const renderComponent: {
|
|||||||
console.error,
|
console.error,
|
||||||
)
|
)
|
||||||
|
|
||||||
reconciler.updateContainer(
|
const cleanup = Callable.create(container, function(this) {
|
||||||
|
(container as any)._reactReconciler.updateContainer(
|
||||||
|
null,
|
||||||
|
(container as any)._reactContainer,
|
||||||
|
null,
|
||||||
|
)
|
||||||
|
delete (container as any)._reactReconciler
|
||||||
|
delete (container as any)._reactContainer
|
||||||
|
|
||||||
|
container.tree_exiting.disconnect(cleanup)
|
||||||
|
})
|
||||||
|
container.tree_exiting.connect(cleanup)
|
||||||
|
}
|
||||||
|
|
||||||
|
(container as any)._reactReconciler.updateContainer(
|
||||||
React.createElement(component, props),
|
React.createElement(component, props),
|
||||||
(container as any)._rootContainer,
|
(container as any)._reactContainer,
|
||||||
null,
|
null,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user