Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix err of textNode attach to WidgetElement. #1336

Merged
merged 22 commits into from
Apr 26, 2022

Conversation

answershuto
Copy link
Member

@answershuto answershuto commented Apr 18, 2022

close #1292

close #1175

报错的原因是 TextNode 在 append 到 WidgetElement 时,TextNode 的 RO 会 insert 到 WidgetElement 的 Kraken RO 上,_parent 指向该 RO。实际上需要的结果是 TextNode 的 RO 的 parent 是 Flutter WIdget 的 RO,该 RO 的 parent 才是 Kraken RO。Flutter Widget 的 RO 创建以及 insert 依赖 mount,也就是 Flutter framework,不需要在这里 insert,否则会多次 insert 报错。

此外,在两(多)层 WidgetElement 下子节点为 Kraken element 的 case, 从第一层开始需要走 Flutter framework 的逻辑来执行 mount,这里 didAttachRenderer 来触发 _attachWidget,此时会将该节点的 RO 通过 insert 插入到父节点中,Flutter element 也会被 mount,后续的 WidgetElement 子节点通过 Flutter framework 触发 mount,而不是通过 didAttachRenderer 中的 ensureChildAttached 来执行子节点逻辑,所以需要 override 掉 didAttachRenderer 防止执行 element 中 didAttachRenderer 的逻辑。否则会多次 mount,导致断言出错,或者由于多次 mount 影响性能。

综上,核心思想是当遇到了 WidgetElement,把 mount element 以及 insert RO 的执行权交给 Flutter framework,Kraken 不需要侵入后续的插入以及遍历子节点流程,只需要在对应的生命周期中处理自己的 style 的 push 等流程即可。

temper357
temper357 previously approved these changes Apr 18, 2022
@@ -80,12 +81,14 @@ class TextNode extends Node {

createRenderer();

if (parent.renderBoxModel is RenderLayoutBox) {
// If element attach WidgetElement, render object should be attach to render tree when mount.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里可以用 ascii image 注释描述下关系

wssgcg1213
wssgcg1213 previously approved these changes Apr 24, 2022
temper357
temper357 previously approved these changes Apr 25, 2022
@answershuto answershuto merged commit 94c404a into main Apr 26, 2022
@answershuto answershuto deleted the fix/err_of_textNode_attachTo_WidgetElement branch April 26, 2022 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants