Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Layered Architecture と Widget Tree (Google Exte...

Layered Architecture と Widget Tree (Google Extended Japan 2021 - Flutter)

I/O Extended Japan 2021 - Flutter に登壇したときのスライドです。

Session- Layered ArchitectureとWidget Tree
https://gdgkyoto.connpass.com/event/215611/

Flutter のLayered ArchitectureとWidget Tree (と並行するTreeの構造)に関して解説しています。

botamochi

June 23, 2021
Tweet

Other Decks in Programming

Transcript

  1. Layered Architecture ͱ Widget Tree ΅ͨ΋ͪ(Twitter: @bot6rice) I/O Extended Japan

    2021 - Flutter on Jun 22, 2021 Building a desktop design language with Flutter
  2. ࣗݾ঺հ • ΅ͨ΋ͪ • Twitter: @bot6rice • ຊۀ • αʔόʔαΠυΤϯδχΞ

    • Python / Go / AWS … • Flutter • ࡢ೥12݄͔ΒݸਓͰ • Flutter Osaka
  3. I/O Extended Japan 2021 - Flutter 1. Recapping Google I/O

    - ηογϣϯͷ֓ཁ 2. Layered Architecture 3. Widget Treeʢ3ͭͷTreeߏ଄ʣ 4. StatefulWidget ͷਖ਼ମ 5. ·ͱΊ
  4. Building a desktop design language with Flutter Todd Volkert (Engineering

    Manager) https://www.youtube.com/watch?v=z6PpxO7R0gM
  5. dart:ui Layer Rendering Widget Material Cupertino dart:ui • Flutter Framework͔ΒFlutterΤϯδϯ

    Λར༻͢ΔLayer • Canvas, RawϨϕϧͷςΩετϨϯμ ϦϯάͳͲΛѻ͏ • ͜ͷLayerͰΞϓϦΛ࣮૷͠Α͏ͱ͢Δ ͱɺεΫϦʔϯ৘ใͳͲ͔ΒϨΠΞ΢τ ͷ࠲ඪ΍഑ஔΛܭࢉ͠ͳ͍ͱ͍͚ͳ͍
  6. dart:ui Layer Rendering Widget Material Cupertino Foundation Animation Painting Gestures

    👈 ͷΑ͏ʹهࡌ͞ΕΔ͜ͱ΋ɻ ެࣜυΩϡϝϯτ https:// f lutter.dev/docs/resources/architectural-overview
  7. Rendering Layer Rendering Widget Material Cupertino dart:ui • Layout Abstraction:

    ϨΠΞ΢τΛந৅Խ͠ ͨLayer • dart:ui LayerͰ͸࠲ඪܭࢉͷͨΊͷίʔσΟ ϯά͕ඞཁ͕ͩͬͨɺ͜ͷLayerͰͦΕΛ ѻ͍ͬͯΔ • RenderObject TreeΛѻ͏Layer • RenderObjectͷcreateͱupdateͰ֤ʑϩ δοΫΛίʔσΟϯάΛ͠ͳ͍ͱ͍͚ͳ͍
  8. Widget Layer Rendering Widget Material Cupertino dart:ui • Composition Abstraction:

    Ϙλϯ΍ς ΩετͳͲͷߏ੒Λந৅Խͨ͠Layer • Widget TreeΛѻ͏Layer • ը໘Λߋ৽͍ͨ͠ͱ͖ʹ͸Widget Tree Λ৽ͨʹ࡞Ε͹͍͍ͷͰɺRendering LayerͷΑ͏ʹcreateͱupdateΛؾʹ͢ Δඞཁ͕ͳ͍
  9. Material / Cupertino Layer Rendering Widget Material Cupertino dart:ui •

    Design languageͷLayer • Material Design ΍ Cupertino DesignΛ Ϣʔβʔ͕؆୯ʹίϯτϩʔϧͰ͖ΔΑ ͏ʹͨ͠Layer • Widget LayerΛݩʹ͍ͯ͠Δ
  10. Rendering Widget • Widget TreeΛߏ੒͢ΔLayer • Rendering LayerΛݩʹߏ੒͞ΕΔ • Layer

    Abstraction: ϨΠΞ΢τͷѻ͍Λந৅Խ • RenderObject TreeΛߏ੒͢ΔLayer Treeʹؔ࿈ͯ͠ਂ۷Γ͠·͢💪 Layered Architecture
  11. ݁࿦ • Widgetʹฒߦ͢ΔܗͰ3ͭͷTree͕࡞ΒΕΔ • Widget Tree • Element Tree •

    RenderObject Tree • TreeͷΠϯελϯε͕࡞ΒΕΔॱ൪: Widget → Element → RenderObject • Widget͸ImmutableʢෆมʣͳͷͰ ը໘ͷߋ৽࣌ʹຖ౓ஔ͖׵ΘΔ • RenderObject͸MutableʢมߋՄʣͳͷͰՄೳͳݶΓ࠶ར༻͞ΕΔ
  12. Widget Tree Element Tree RenderObject Tree Property৘ใ ʢྫ: RichTextͷtextͳͲʣ Widget΍RenderObjectΛ

    ؅ཧ αΠζ΍ϨΠΞ΢τɺ ඳࣸʹؔͯ͠ͷ৘ใΛ࣋ͭ (ྫ: Paddingͷchildͱpaddingͷ αΠζͳͲ) PublicͷAPI
  13. Widget Tree Element Tree RenderObject Tree Center (Root widget) Widget

    Treeͷrootʹ Center WidgetͷΠϯελϯε͕ੜ੒͞ΕΔ
  14. Widget Tree Element Tree RenderObject Tree Center (Root widget) SingleChildRender

    ObjectElement WidgetͷcreateElementϝιουʹΑΓ Element͕ੜ੒͞ΕΔ
  15. Widget Tree Element Tree RenderObject Tree Center (Root widget) Render

    PositionedBox SingleChildRender ObjectElement Element͔Βwidget.createRenderObject͕ ݺ͹Εੜ੒͞ΕΔ
  16. Widget Tree Element Tree RenderObject Tree Center (Root widget) Render

    PositionedBox RichText MultiChild RenderObject Element RenderParagraph (Text: Hello World!) SingleChildRender ObjectElement ࢠʹରͯ͠΋ಉ༷ʹ Widget → Element → RenderObject͕ ࡞ΒΕͯ “Hello World!” ͕දࣔ✌
  17. Widget Tree Element Tree RenderObject Tree Center (Root widget) Render

    PositionedBox RichText MultiChild RenderObject Element RenderParagraph (Text: Hello World!) SingleChildRender ObjectElement Center (Root widget) RichText NEW Widget͸ImmutableͳͷͰ શऔͬସ͑͞ΕΔ
  18. Widget Tree Element Tree RenderObject Tree Center (Root widget) Render

    PositionedBox RichText MultiChild RenderObject Element RenderParagraph (Text: Hello World!) SingleChildRender ObjectElement canUpdate͸ trueͳͷͰ Elementͱ RenderObject͸ ࠶ར༻͞ΕΔ
  19. Widget Tree Element Tree RenderObject Tree Center (Root widget) Render

    PositionedBox RichText MultiChild RenderObject Element RenderParagraph (Text: Hello Flutter!) SingleChildRender ObjectElement updateRenderObject͕ݺ͹Εͯը໘͕ߋ৽͞ΕΔɻ RichTextͷtext͕RenderObjectʹ౉͞Εͯจࣈ͕มΘΔɻ
  20. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Foo) SingleChildRender ObjectElement Foo StatefulElement
  21. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Foo) SingleChildRender ObjectElement Foo StatefulElement StatefulBuilder ͸ ɾchildΛ࣋ͨͳ͍ʢ࣋ͭͷ͸builder callbackؔ਺ͷฦΓ஋ʹΑΓٙࣅతʹchildΛ࣋ͭʣ ɾRenderObjectΛ࣋ͨͳ͍
  22. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Foo) SingleChildRender ObjectElement Foo StatefulBuilder FooElement RenderFoo ඇಉظॲཧͰStatefulBuilder͔ΒFoo͕ฦ͞ΕΔͱ Widget → Element → RenderObject ͕ੜ੒͞ΕΔɻ ʢ࿷ۂͨ͠໼ҹ͸ݫີͳchildͰͳ͍͜ͱΛࣔ͢ʣ
  23. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Bar) SingleChildRender ObjectElement Foo StatefulElement FooElement RenderFoo Bar ஔ͖׵ΘΔWidget͸FooͱͦͷChild / ChildrenͷΈʂ
  24. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Bar) SingleChildRender ObjectElement Bar StatefulElement BarElement RenderBar
  25. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    (builder: return Foo) SingleChildRender ObjectElement Foo StatefulBuilder FooElement RenderFoo State ElementʹStateΛ࣋ͨͤͯ…
  26. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulBuilder

    SingleChildRender ObjectElement StatefulElement FooElement RenderFoo State builder callback ͞Βʹbuilder callback΋࣋ͨͤΔ Foo
  27. Widget Tree Element Tree RenderObject Tree Center Render PositionedBox StatefulWidget

    SingleChildRender ObjectElement StatefulElement FooElement RenderFoo State builder callback Foo StatefulWidget͸Treeͩͱ͜ͷ෦෼ʹ֘౰
  28. ·ͱΊ • FlutterͷLayered ArchitectureͱTreeߏ଄Λ஌ΔͱɺDesign LanguageΛࣗ ࡞Ͱ͖ΔΑ͏ʹͳΔ • Layerʹ͸ dart:ui, Rendering,

    Widget, Material / Cupertino ͕͋Δ • Treeʹ͸ Widget Tree, Element Tree, RenderObject Tree͕͋Δ • StatefulWidgetͷState͸Element͕؅ཧ͍ͯͨ͠
  29. ΋ͬͱৄ͘͠ How Flutter renders widgets When to Use Keys The

    Mahogany Staircase Flutter’s Layered Design ࠓ೔ͷ಺༰͕ΑΓৄ͘͠ղઆ͞Ε͍ͯΔɻdart:ui Layer͔Βͷ࣮૷ͷ࿩͸Ұڵɻ https://www.youtube.com/watch?v=dkyY9WCGMi0 StatefulWidgetͷElement Tree͕ཧղͰ͖͍ͯΕ͹ɺཧղ͠΍͍͢ɻ https://www.youtube.com/watch?v=kn0EOS-ZiIc Treeͷجຊతͳղઆɻ https://www.youtube.com/watch?v=996ZgFRENMs