React Nativeのレイアウトエンジン YogaでFlexible box layoutレイアウトを作る / yoga-with-sketch
by
mottox2
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
React NativeͷϨΠΞτΤϯδϯ YogaͰFlexboxϨΠΞτΛ࡞Δ 2018.06.26 Roppongi.js #4 - @mottox2
Slide 2
Slide 2 text
@mottox2 • React, Ruby on RailsΛத৺ʹWebαʔϏε։ൃ͍ͯ͠·͢ • ReactNative৭ʑݴΘΕ͍ͯΔ͚Ͳ͖Ͱ͢ • UI EngineeringʹڵຯΞϦ • ϒϩάͬͯ·͢(esa.io + note.mu + GatsbyJS) => mottox2.com Freelance web engineer Yuki Takemoto
Slide 3
Slide 3 text
ࠓͷ • Yogaͷ • YogaͷNodeͱLayoutʹ͍ͭͯ • ࣮ફ: JSON to Sketch.app
Slide 4
Slide 4 text
Yoga ͱʁ Yoga is a cross platform layout engine implementing Flexbox • https://yogalayout.com/͋ • Facebook • FlexboxϥΠΫͳAPIΛ࣋ͬͨϨΠΞτΤϯδϯ • React NativeɺComponent Kit (iOS)ɺLitho (Android)ͳͲͷϥΠϒϥϦͷ෦Ͱ ΘΕ͍ͯΔɻa͋ • ୯ମͰ͏͜ͱ͕Ͱ͖ΔɻࠓճJS୯ମͰѻ͍͖ͬͯ·͢ɻ YogaFlexbox࣮ͷΫϩεϓϥοτϑΥʔϜϨΠΞτΤϯδϯ
Slide 5
Slide 5 text
Yoga Playground Playground - https://yogalayout.com/playground
Slide 6
Slide 6 text
Usage Docs Standalone example - https://yogalayout.com/getting-started/standalone
Slide 7
Slide 7 text
Yogaͷ֓೦ ~Node~ • ෯ߴ͞ɺFlexboxͷଐੑΛ࣋ͬͨΦϒδΣΫτ • `insertChild(childNode)`ͰࢠؔΛ࣋ͯΔɻ`getChild(index)` ͰࢠΛऔಘग़དྷ Δɻ • Nodeʹରͯ͠ `calculateLayout()` Λ࣮ߦ͢ΔͱࢠϊʔυΛؚΊͨϨΠΞτΛܭ ࢉͯ͘͠ΕΔɻ
Slide 8
Slide 8 text
Yogaͷ֓೦ ~Layout~ • left, right, top, bottom, width, heightΛ࣋ͭΦϒδΣΫτ • Node.getComputedLayoutNode.getComputedXXX(ex. Left, Width)ؔͰऔಘ Ͱ͖Δɻ • calculateLayoutΛ࣮ߦ͢Δ·ͰLayoutऔಘͰ͖ͳ͍ɻ(JSͷ߹NaN͕ฦΔ)
Slide 9
Slide 9 text
࣮ફ: JSON to Sketch.app
Slide 10
Slide 10 text
YogaͰܭࢉͨ͠ϨΠΞτΛݩʹSketchϑΝΠϧΛ࡞ͬͯΈΔɻ JSX to Sketchͷ࣮ͱͯ͠طʹReact Sketch.app͕͋ΔͷͰɺࠓճJSON to Sketchͷ࣮ΛਐΊ͍ͯ͘ɻͭ·ΓશྼԽ൛ͷ࠶ൃ໌Ͱ͢ɻ ࣮ફ: JSON to Sketch.app JSON file Yoga Node Tree Sketch file 1 2 3
Slide 11
Slide 11 text
airbnb/React Sketch.app ࢀߟ • JSX͔ΒSketchϑΝΠϧΛੜͰ͖ΔϥΠϒϥϦɻ෦ͰYogaΛ͍ͬͯΔɻ • http://airbnb.io/react-sketchapp/
Slide 12
Slide 12 text
STEP1: JSONܗࣜΛఆٛ STEP2: JSON͔ΒNode TreeΛ࡞ΔॲཧΛॻ͘ STEP3: Node TreeͱJSONΛͱʹSketchϑΝΠϧΛ࡞ΔॲཧΛॻ͘ ࣮ફ: JSON to Sketch.app
Slide 13
Slide 13 text
·ͣɺ࣍ͷΑ͏ͳJSONΛSketchϑΝΠϧʹஔ͖͑Δ͜ͱΛߟ͍͑ͯ͘ɻ දݱྗ͕͍ܗࣜͰ͋Δ͜ͱʹΛͭͿ͍ͬͯͩ͘͞ JSONΛఆٛ
Slide 14
Slide 14 text
JSONΛNode Treeʹͯ͠ɺ ϨΠΞτܭࢉΛߦ͏ɻ Node TreeΛ࡞Δ
Slide 15
Slide 15 text
SketchAPIͰΈཱͯ SketchAPIΛͬͯɺ ϨΠϠʔΛ࡞͍ͬͯ͘ɻ
Slide 16
Slide 16 text
DEMO https://github.com/mottox2/json-sketchapp
Slide 17
Slide 17 text
• ϨΠΞτܭࢉ͕ͳ͍ͷͰɺඇৗʹγϯϓϧʹίʔυ͕͔͚Δɻa • SketchAPIͷ༻ײΛѲ͢Δͷ͕Ұ൪͔͔࣌ؒͬͨɻ • JSXͷදݱྗͷߴ͞Λࢥ͍ͬͨ͠ɻjsonnetͷΑ͏ͳJSON֦ுه๏Λ͏͖ ͩͬͨɻ • ࠓճͷίʔυ: https://github.com/mottox2/json-sketchapp • ࠓճͷσϞͰ࡞ͬͨJSON to Sketch.app͍Έ͕ͪશ͘ͳ͍ɻࠔͬͨɻ σϞͷ·ͱΊ
Slide 18
Slide 18 text
• JSXYAMLJSONΛಥͬࠐΜͰYogaͰLayoutΛܭࢉ • YogaͰܭࢉͨ͠ͷΛSketchPowerPointʹग़ྗ͢Δ • ༻్ʹϋϚΕศརϥΠϒϥϦͱͯ͑͠Δa • ͨͩ͠׆͔ͤΔػձ͋·Γͳ͍ɻa YogaԿʹ͑Δͷ͔ʁ
Slide 19
Slide 19 text
• ࣗલͰϨΠΞτܭࢉ࣮ͨ͘͠ͳ͍ͷͰɺFacebookͷ͍͢͝ਓ͕ͨͪ࡞ͬͨ Έʹ͔ͬΔͱ͍͍ͱࢥ͏ɻa • JSXͷํ͕දݱྗ͕ߴ͍ϑΥʔϚοτͳͷͰɺJSX to XXXΈ͍ͨͳͷΛ࡞Δ࣌ ʹYogaΛ͑ʢͦΕͳΓʹʣ؆୯ʹͰ͖Δ͔͠Εͳ͍ɻa • ͱΓ͋͑ͣYoga Playground͞ΘͬͯΈͯཉ͍͠ɻΑ͘ग़དྷͯΔɻ • https://yogalayout.com/playground ͋ • cross-platform UIͱ͍͏จ຺Ͱairbnb/Lona͕ؾʹͳ͍ͬͯΔɻ ؾ͖ͮ
Slide 20
Slide 20 text
͋Γ͕ͱ͏͍͟͝·ͨ͠