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୯ମͰѻ͍͖ͬͯ·͢ɻ Yoga͸Flexbox࣮૷ͷΫϩεϓϥοτϑΥʔϜϨΠΞ΢τΤϯδϯ

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.getComputedLayout΍Node.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

• JSX΍YAML΍JSONΛಥͬࠐΜͰYogaͰLayoutΛܭࢉ • YogaͰܭࢉͨ͠΋ͷΛSketch΍PowerPointʹग़ྗ͢Δ • ༻్ʹϋϚΕ͹௒ศརϥΠϒϥϦͱͯ͠࢖͑Δ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

͋Γ͕ͱ͏͍͟͝·ͨ͠