Slide 1

Slide 1 text

Model ૚Λ iOS/Android Ͱ ·ͱΊ͍ͨ LT Session 4 ๨೥.swift laprasDrum

Slide 2

Slide 2 text

laprasDrum Mobile Lead, freee Β΀Β΀ͱΑ͹Εͯ·͢ iOS/Android Engineer

Slide 3

Slide 3 text

iOS/Android ྆ରԠͷΞϓϦ࣮૷Λଓ͚ͯ Model ͷ࣮૷Λ֤ॴʹ΍͍ͬͯ͘ͷͭΒ͘ͳ͍Ͱ͔͢ Models ViewModel View Web Resources

Slide 4

Slide 4 text

iOS/Android ྆ରԠͷΞϓϦ࣮૷Λଓ͚ͯ ͜͜͸ OS ґଘͷٕज़Λ۷ΓԼ͛Δͱͯ͠ʢUIViewController ͱ͔ Activity ͱ͔ʣ Models ViewModel View Web Resources

Slide 5

Slide 5 text

iOS/Android ྆ରԠͷΞϓϦ࣮૷Λଓ͚ͯ Binding ख๏͸ϓϥοτϑΥʔϜͱ͍͏͔ RxSwift/RxJava Ͱఆணͭͭ͋͠Δ ʢϓϥοτϑΥʔϜԣஅͰιʔείʔυڞ௨Խͱ·Ͱ͸͍͔ͳ͍͕ʣ Models ViewModel View Web Resources

Slide 6

Slide 6 text

iOS/Android ྆ରԠͷΞϓϦ࣮૷Λଓ͚ͯ ͬͯ͜͜ϓϥοτϑΥʔϜ͝ͱʹಉ࣮͡૷܁Γฦͯ͠ΔͷͰ͸ Models ViewModel View Web Resources

Slide 7

Slide 7 text

iOS/Android ྆ରԠͷΞϓϦ࣮૷Λଓ͚ͯ ͲͪΒ͔ʹ Property ੜ͑๨Ε·ͨ͠ͱ͔ NonNull / Nullable ఆ͕ٛͿΕͨΓͱ͔΋͏͍΍ͩ Models ViewModel View Web Resources

Slide 8

Slide 8 text

Model ૚Λ iOS/Android Ͱ ·ͱΊ͍ͨ

Slide 9

Slide 9 text

ԿΛ࢖͏͔ ͜͜ͷఆ͚ٛͩʹہॴతʹ࢖͑ͦ͏ͳΫϩεϓϥοτϑΥʔϜ͕΄͍͠ C/C++ ͳΓ Xamarin ͳΓ͍Ζ͍Ζ͋Γ·͕͢ ࠓճ͸ React Native Ͱ࣮ݧ Models ViewModel View Web Resources

Slide 10

Slide 10 text

React Native ͩͱʁ جຊ View पΓͷίʔυͷ౷ҰԽͷͨΊʹ࢖͏͜ͱ͕ଟ͍͔ͱ Models ViewModel View Web Resources

Slide 11

Slide 11 text

ϞόΠϧΤϯδχΞͱͯ͠͸ View / Animation ·ΘΓ͸ OS ඪ४ͷ࠷৽ API ͷಈ޲΋ݟͭͭ ͍Ζ͍Ζ΍Γ͍ͨ΋ͷʢݸਓతͳݟղʣ Models ViewModel View Web Resources

Slide 12

Slide 12 text

ΞϓϦέʔγϣϯͱͯ͠͸ڞ௨Խ͞ΕΔ΂͖ྖҬ ͸ɺϓϥοτϑΥʔϜͷٕज़ʹ߆ΔΑΓ࣮૷ࠩҟʹΑΔόάʹ ؾ͖ͮ΍͍͢࢓૊ΈΛೖΕָͯʹӡ༻͍ͨ͠ Models ViewModel View Web Resources

Slide 13

Slide 13 text

Web ΞϓϦέʔγϣϯΤϯδχΞͱͷձ࿩ ࣮ࡍͷͱ͜Ζ Model ͷఆٛͬͯ Server ্ͷఆ͕ٛਖ਼ʹͳΔͷͰ αʔόʔαΠυɾWeb ϑϩϯτͷਓͱ΋ Model ఆٛΛڠٞ͠қ͍ IF ͕͋Δͱ͍͍ΑͶ Models ViewModel View Web Resources

Slide 14

Slide 14 text

΍ͬͯΈΔ

Slide 15

Slide 15 text

laprasdrum/ReactLayeredDomain

Slide 16

Slide 16 text

ViewController React Native ͷ View Λ Model ௨৴ʹઐ༻ར༻ʢԿ΋දࣔ͠ͳ͍ʣ

Slide 17

Slide 17 text

ViewController React Native ଆ͔Β Model ͕ૹΒΕ͖ͯͨΒ View ʹ൓өͤ͞Δ

Slide 18

Slide 18 text

Model iOS ଆͰ property ͷܕɾNonNull / Nullable ఆٛ

Slide 19

Slide 19 text

Model Ϛοϐϯά༻ͷΫϥεͱϝιουΛఆٛʢmacro only ʣ

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

NonNull / Nullable Property

Slide 22

Slide 22 text

Nullable Property ͳΒ໰୊ͳ͠ export default class App extends Component<{}> { componentDidMount() { let adapter = NativeModules.RLDRootAdapter; let languages = [ { type: "Swift", stars: 41872 }, { type: "Kotlin" }, <————— ] adapter.emitChange(languages); } render() { return ; } } import Foundation struct Language: Codable { var type: String = "" var stars: Int? = 0 <————— }

Slide 23

Slide 23 text

NonNull Property ͳΒ Runtime Ͱؾ෇͚ΔΑ͏ʹ export default class App extends Component<{}> { componentDidMount() { let adapter = NativeModules.RLDRootAdapter; let languages = [ { type: "Swift", stars: 41872 }, { type: "Kotlin" }, <————— ] adapter.emitChange(languages); } render() { return ; } } import Foundation struct Language: Codable { var type: String = "" var stars: Int = 0 <————— }

Slide 24

Slide 24 text

Android ͩͱʁ Codable Ͱอূ͔ͨͬͨ͜͠ͱ͸ square/moshi Ͱ୲อͰ͖ͦ͏ data class Language( val type: String, val stars: Int ) val json = """ {"type": “swift"} """ val moshi = Moshi.Builder() .add(KotlinJsonAdapterFactory()) .build() // throw JsonDataException val lang = moshi.adapter(Language::class.java).fromJson(json)

Slide 25

Slide 25 text

ࠓޙͷݕূ࣮ݧ Android ઈࢍରԠத ͋ΘΑ͘͹ API ୟ͘ͱ͜΋ React Native ଆʹدͤΔͷ΋͋Γ͔΋ͱࢥͬͯΔ → Data Layer ͱͯ͠·ͱΊΔͱΑ͔͛͞ݕূ Models ViewModel View Web Resources ਖ਼௚ React Native ͡Όͳͯ͘Α͘Ͷʁ ͱ͍͏ؾ࣋ͪ͸͋Δ ʢ͋·Γָʹͳͬͨײ͕ͳ͍͠ɺRepo ෼ׂͲ͏͢ΔΑʣ