iOS and Android Application with React-Native-Layered Domain Model

26173c2f52b5aa5d06e6806c7a9478d3?s=47 laprasDrum
December 07, 2017

iOS and Android Application with React-Native-Layered Domain Model

26173c2f52b5aa5d06e6806c7a9478d3?s=128

laprasDrum

December 07, 2017
Tweet

Transcript

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

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

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

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

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

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

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

    ViewModel View Web Resources
  8. Model ૚Λ iOS/Android Ͱ ·ͱΊ͍ͨ

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

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

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

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

  13. Web ΞϓϦέʔγϣϯΤϯδχΞͱͷձ࿩ ࣮ࡍͷͱ͜Ζ Model ͷఆٛͬͯ Server ্ͷఆ͕ٛਖ਼ʹͳΔͷͰ αʔόʔαΠυɾWeb ϑϩϯτͷਓͱ΋ Model

    ఆٛΛڠٞ͠қ͍ IF ͕͋Δͱ͍͍ΑͶ Models ViewModel View Web Resources
  14. ΍ͬͯΈΔ

  15. laprasdrum/ReactLayeredDomain

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

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

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

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

  20. None
  21. NonNull / Nullable Property

  22. 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 <View />; } } import Foundation struct Language: Codable { var type: String = "" var stars: Int? = 0 <————— }
  23. 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 <View />; } } import Foundation struct Language: Codable { var type: String = "" var stars: Int = 0 <————— }
  24. 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)
  25. ࠓޙͷݕূ࣮ݧ Android ઈࢍରԠத ͋ΘΑ͘͹ API ୟ͘ͱ͜΋ React Native ଆʹدͤΔͷ΋͋Γ͔΋ͱࢥͬͯΔ →

    Data Layer ͱͯ͠·ͱΊΔͱΑ͔͛͞ݕূ Models ViewModel View Web Resources ਖ਼௚ React Native ͡Όͳͯ͘Α͘Ͷʁ ͱ͍͏ؾ࣋ͪ͸͋Δ ʢ͋·Γָʹͳͬͨײ͕ͳ͍͠ɺRepo ෼ׂͲ͏͢ΔΑʣ