-
Notifications
You must be signed in to change notification settings - Fork 304
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
answershuto
merged 22 commits into
main
from
fix/err_of_textNode_attachTo_WidgetElement
Apr 26, 2022
Merged
Fix err of textNode attach to WidgetElement. #1336
answershuto
merged 22 commits into
main
from
fix/err_of_textNode_attachTo_WidgetElement
Apr 26, 2022
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wssgcg1213
reviewed
Apr 18, 2022
temper357
previously approved these changes
Apr 18, 2022
yuanyan
reviewed
Apr 19, 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里可以用 ascii image 注释描述下关系
…sert render object by flutter framework..
…object by Flutter Framework..
…ementToFlutterElementAdaptor.
wssgcg1213
previously approved these changes
Apr 24, 2022
yuanyan
reviewed
Apr 24, 2022
temper357
reviewed
Apr 24, 2022
temper357
reviewed
Apr 25, 2022
temper357
previously approved these changes
Apr 25, 2022
wssgcg1213
approved these changes
Apr 26, 2022
temper357
approved these changes
Apr 26, 2022
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 等流程即可。