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

KotlinでReact Native(expo) を使いたい

KotlinでReact Native(expo) を使いたい

Shinnosuke Kugimiya

June 06, 2019
Tweet

More Decks by Shinnosuke Kugimiya

Other Decks in Programming

Transcript

  1. X © DMM.com ͳͥϞϊϨϙΛࢼ͍ͨ͠ͷ͔ w ྫ͑͹αʔόʔΤϯδχΞਓɺJ04ΤϯδχΞਓɺ"OESPJEΤϯδχ Ξਓɺ8FCϑϩϯτਓͷਓͷνʔϜ͕͋Δͱ͢Δ w ྖҬ͝ͱʹϦϙδτϦΛ࡞ΔɻYYYTFSWFS YYYJPT

    YYYXFC YYY BOESPJEͳͲ w ͍ͭͷؒʹ͔ɺαʔόʔνʔϜɺJ04νʔϜͳͲͱݺ͹ΕΔʜʢ੹೚ൣ ғ͕໌֬ʹ෼͔Εͯ͠·͏ʣ w ଞྖҬͷ͜ͱ͸͔͋ͣΓ஌Β͵ʜ ͱ͍͏ঢ়گΛճආ͍ͨ͠ʂ
  2. X © DMM.com ͳͥ̍ݴޠͳͷ͔ w ֤ྖҬ͕͍ͭͷؒʹ͔෼அ͞ΕΔͷΛճආ͢ΔͨΊʹϞϊϨϙ΁ʂ w ϓϧϦΫ͕ͨ͘͞ΜདྷΔΑ͏ʹͳ͚ͬͨͲɺීஈ࢖Θͳ͍ݴޠʜίϯς ΩετεΠον͕େม w

    ͍ͭͷؒʹ͔ɺଞྖҬͷ13͸ݟͳ͘ͳΔ ͱ͍͏ঢ়گΛճආ͍ͨ͠ʂ w ʢίϯςΩετεΠονͩΔ͍ʜݩʹ໭͍ͨ͠ʜϞϊϨϙ΍Ί͍ͨʜʣ
  3. X © DMM.com ैདྷͷΫϩεϓϥοτϑΥʔϜؔ࿈ٕज़ͷಛ௃ "OESPJE J04 8FC 91MBUGPSN'SBNFXPSL :PVS$PEF w

    91MBUGPSN'SBNFXPSLͷ"1*Λ ࢖༻͢Δ w 91MBUGPSN'SBNFXPSLͷରԠ͢ ΔϓϥοτϑΥʔϜʹ͸੍ݶ͕ ͋Δ w ݴޠ͸റΒΕΔ
  4. X © DMM.com ,PUMJONQQͷಛ௃ w σεΫτοϓΞϓϦΛ֤04͝ͱʹ࣮૷͢Δͷ͸͠ΜͲ͍͔ΒFMFDUSPO࢖ ͍͍ͨ w 8FC͸3FBDUͰ΍Γ͍ͨ w

    "OESPJE͸ಘҙ͔ͩΒωΠςΟϒͷ·· w J04͸ͦΜͳʹಘҙ͡Όͳ͍ɻͲͪΒ͔ͱ͍͏ͱ3FBDU/BUJWFͰ΍Γͨ ͍ ,PUMJONQQͳΒ͜Ε͕Ͱ͖Δʂ
  5. X © DMM.com ϝϦοτɾσϝϦοτͷྫ 91MBUGPSN'SBNFXPSL ,PUMJONQQ ϝϦοτ w ֶशίετతʹ͸̍ͭͷ'SBNFXPSLͷ"1*Λ஌Δ ͚ͩͰྑ͍

    w ͳͲͳͲ w ֤ϓϥοτϑΥʔϜʹରͯ͠޷͖ͳ'SBNFXPSL Λ࢖༻Ͱ͖Δ w 'SBNFXPSL͕ഇΕͨ৔߹ͷμϝʔδ͸௿͍ʢ࡞ Γํʹ΋ΑΔ͕ʣ w ͳͲͳͲ σϝϦοτ w 'SBNFXPSL͕ഇΕͨ৔߹ͷμϝʔδ͕ਙେ w 'SBNFXPSLͷ࠾༻͢ΔݴޠʹϩοΫΠϯ͞ΕΔ ʢϝϦοτʹ΋ͳΓ͏Δʣ w ͳͲͳͲ w ֶशίετ͸બΜͩ'SBNFXPSLɺϓϥοτϑΥ ʔϜͷ਺͚ͩ͋Δ w ,PUJMOʹϩοΫΠϯ͞ΕΔʢϝϦοτͷਓ΋͍ Δʣ w ͳͲͳͲ
  6. X © DMM.com ͨͩʜ "OESPJE :PVS$PEF J04 8FC .BD 8JO

    -JOVY &MFDUSPO 3/ w ຊ౰ʹͰ͖Δͷʜʁʁ w ΍ͬͯΔͷݟͨ͜ͱͳ͍͚Ͳʁʁ
  7. X © DMM.com ͨͩʜ "OESPJE :PVS$PEF J04 8FC .BD 8JO

    -JOVY &MFDUSPO 3/ w ຊ౰ʹͰ͖Δͷʜʁʁ w ΍ͬͯΔͷݟͨ͜ͱͳ͍͚Ͳʁʁ ͱ͍͏͜ͱͰࢼͯ͠Έͨʂͱ͍͏ͷ͕ࠓճͷൃදͰ͢ʂ
  8. X © DMM.com ,PUMJOΛ࢖ͬͯ8FC։ൃΛ͢Δ࣌ plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend"

    } dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11' implementation 'org.jetbrains:kotlin-react:16.6.0-pre.70-kotlin-1.3.21' … } compileKotlin2Js { … } kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } CVJMEHSBEMF͸͜͏ͳΔ
  9. X © DMM.com ,PUMJOΛ࢖ͬͯ8FC։ൃΛ͢Δ࣌ plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend"

    } dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11' implementation 'org.jetbrains:kotlin-react:16.6.0-pre.70-kotlin-1.3.21' … } compileKotlin2Js { … } kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } CVJMEHSBEMF͸͜͏ͳΔ
  10. X © DMM.com ,PUMJOΛ࢖ͬͯ8FC։ൃΛ͢Δ࣌ plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend"

    } dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11' implementation 'org.jetbrains:kotlin-react:16.6.0-pre.70-kotlin-1.3.21' … } compileKotlin2Js { … } kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } CVJMEHSBEMF͸͜͏ͳΔ
  11. X © DMM.com ,PUMJOΛ࢖ͬͯ8FC։ൃΛ͢Δ࣌ plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend"

    } dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11' implementation 'org.jetbrains:kotlin-react:16.6.0-pre.70-kotlin-1.3.21' … } compileKotlin2Js { … } kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } CVJMEHSBEMF͸͜͏ͳΔ
  12. X © DMM.com ,PUMJOΛ࢖ͬͯ8FC։ൃΛ͢Δ࣌ plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend"

    } dependencies { implementation “org.jetbrains.kotlin:kotlin-stdlib-js:$kotlin_version" implementation 'org.jetbrains.kotlinx:kotlinx-html-js:0.6.11' implementation 'org.jetbrains:kotlin-react:16.6.0-pre.70-kotlin-1.3.21' … } compileKotlin2Js { … } kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } CVJMEHSBEMF͸͜͏ͳΔ
  13. X © DMM.com ࣮ࡍͷίʔυྫ ίʔυ͸͜͏ͳΔ fun main() { document.addEventListener("DOMContentLoaded", {

    render(document.getElementById("root")) { a { +"Hello" } } }) } NBJOLU
  14. X © DMM.com ࣮ࡍͷίʔυྫ ίʔυ͸͜͏ͳΔ fun main() { document.addEventListener("DOMContentLoaded", {

    render(document.getElementById("root")) { a { +"Hello" } } }) } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script type="text/javascript" language="JavaScript" src=“main.bundle.js"></script> … </head> <body> <div id="root"></div> </body> </html> NBJOLU JOEFYIUNM
  15. X © DMM.com ࣮ࡍͷίʔυྫ ίʔυ͸͜͏ͳΔ fun main() { document.addEventListener("DOMContentLoaded", {

    render(document.getElementById("root")) { a { +"Hello" } } }) } <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <script type="text/javascript" language="JavaScript" src=“main.bundle.js"></script> … </head> <body> <div id="root"></div> </body> </html> NBJOLU JOEFYIUNM ͜ΕͰ3VO͢Ε͹ɺϒϥ΢β͕։͍ͯ8FC͕ಈ͘
  16. X © DMM.com ,PUMJOKT ͜͏͍͏ؔ਺͕͋ͬͨΒ @file:JsModule("react") package react external fun

    isValidElement(element: Any): Boolean ͜͏ॻ͚ͩ͘ ͜Ε͚ͩͰɺ,PUMJOͰ࢖͑Δ
  17. X © DMM.com Ͳ͏͍͏࢓૊ΈͰಈ͍͍ͯΔͷ͔ʁ  τϥϯεύΠϧͯ͠,PUMJO͔ΒKT͕Ͱ͖Δ  QBDLBHFKTPO࡞੒  KBS͔ΒVOQBDL

     OQNJOTUBMM  EFWTFSWFSىಈ 3VO͢Δ·Ͱͷɺେ·͔ͳखॱ͸͜͏ͳͬͯΔ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ
  18. X © DMM.com plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend" }

    … kotlinFrontend { downloadNodeJsVersion = "latest" npm { dependency "kotlinx-html-js" dependency "react" dependency "react-dom" … } webpackBundle { bundleName = "main" … } } QBDLBHFKTPO࡞੒ QBDLBHFKTPO CVJME഑Լʹੜ੒͞ΕΔ
  19. X © DMM.com KBS͔ΒVOQBDLᶃ CVJMEOPEF@NPEVMFT@JNQPSUFE KT LKTN KBS KT LKTN

    KBS KT LKTN KBS KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KBS͔Βநग़
  20. X © DMM.com KBS͔ΒVOQBDLᶄ CVJMEOPEF@NPEVMFT KT LKTN QBDLBHFKTPO KT LKTN

    QBDLBHFKTPO KT LKTN QBDLBHFKTPO γϯϘϦοΫϦϯΫ࡞੒ CVJMEOPEF@NPEVMFT@JNQPSUFE KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO
  21. X © DMM.com OQNJOTUBMM CVJMEOPEF@NPEVMFT KT LKTN QBDLBHFKTPO OQNJOTUBMM KT

    LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT QBDLBHFKTPO KT QBDLBHFKTPO KT QBDLBHFKTPO ʜ
  22. X © DMM.com Ͳ͏͍͏࢓૊ΈͰಈ͍͍ͯΔͷ͔ʁ  τϥϯεύΠϧͯ͠,PUMJO͔ΒKT͕Ͱ͖Δ  QBDLBHFKTPO࡞੒  KBS͔ΒVOQBDL

     OQNJOTUBMM  EFWTFSWFSىಈ 3VO͢Δ·Ͱͷɺେ·͔ͳखॱ͸͜͏ͳͬͯΔ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ
  23. X © DMM.com Ͳ͏͍͏࢓૊ΈͰಈ͍͍ͯΔͷ͔ʁ  τϥϯεύΠϧͯ͠,PUMJO͔ΒKT͕Ͱ͖Δ  QBDLBHFKTPO࡞੒  KBS͔ΒVOQBDL

     OQNJOTUBMM  EFWTFSWFSىಈ 3VO͢Δ·Ͱͷɺେ·͔ͳखॱ͸͜͏ͳͬͯΔ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ LPUMJOKT LPUMJOGSPOUFOEQMVHJO
  24. X © DMM.com LPUMJOΛ࢖Θͳ͍৔߹ͷී௨ͷFYQP։ൃ  QBDLBHFKTPOΛੜ੒  OQNJOTUBMM  BQQKTPOͳͲॾʑඞཁͳϑΝΠϧੜ੒

     "QQKTͳͲΛमਖ਼  FYQPTUBSU 3VO͢Δ·Ͱͷɺେ·͔ͳखॱ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ
  25. X © DMM.com LPUMJOΛ࢖Θͳ͍৔߹ͷී௨ͷFYQP։ൃ  QBDLBHFKTPOΛੜ੒  OQNJOTUBMM  BQQKTPOͳͲॾʑඞཁͳϑΝΠϧੜ੒

     "QQKTͳͲΛमਖ਼  FYQPTUBSU 3VO͢Δ·Ͱͷɺେ·͔ͳखॱ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ LPUMJOKTͱ LPUMJOGSPOUFOEQMVHJO͕ ΍͍ͬͯΔ͜ͱͱࣅ͍ͯΔ
  26. X © DMM.com ·ͣ͸FYQPͷ"1*Λ࢖͑ΔΑ͏ʹXSBQQFSΛ࡞Δ @file:JsModule("expo") package expo import react.Component external

    fun <T : Component<*, *>> registerRootComponent(component: JsClass<T>) FYQPϞδϡʔϧΛ࡞੒
  27. X © DMM.com ,PUMJONQQ৔߹ͷී௨ͷFYQP։ൃ  τϥϯεύΠϧͯ͠,PUMJO͔ΒKT͕Ͱ͖Δ  QBDLBHFKTPOΛੜ੒  KBS͔ΒVOQBDL

     OQNJOTUBMM  BQQKTPOͳͲॾʑඞཁͳϑΝΠϧੜ੒  "QQKTʹSFOBNF  FYQPTUBSU ͜͏͍͏λεΫΛ࣮૷ͯ͠ߦ͘ ʢҰ෦୺ંͬͯΔͱ͜Ζ΋͋Γ·͢ʣ LPUMJOKT LPUMJOFYQPQMVHJO ‑
  28. X © DMM.com plugins { id "kotlin2js" id "org.jetbrains.kotlin.frontend" }

    … kotlinExpo { npm { dependency "kotlinx-html-js" dependency "kotlin-expo" dependency "kotlinx-html-js" dependency "react" dependency "react-dom" dependency "react-redux" dependency "react-router-dom" } } QBDLBHFKTPO࡞੒ QBDLBHFKTPO CVJMEFYQP഑Լʹੜ੒͞ΕΔ https://github.com/kgmyshin/kotlin-expo-sample/blob/master/kotlin-expo-gradle-plugin/src/main/kotlin/com/kgmyshin/kotlin/expo/tasks/GeneratePackageJsonTask.kt
  29. X © DMM.com KBS͔ΒVOQBDLᶃ CVJMEFYQPOPEF@NPEVMFT@JNQPSUFE KT LKTN KBS KT LKTN

    KBS KT LKTN KBS KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KBS͔Βநग़ https://github.com/kgmyshin/kotlin-expo-sample/blob/master/kotlin-expo-gradle-plugin/src/main/kotlin/com/kgmyshin/kotlin/expo/tasks/UnpackGradleDependenciesTask.kt
  30. X © DMM.com KBS͔ΒVOQBDLᶄ CVJMEFYQPOPEF@NPEVMFT KT LKTN QBDLBHFKTPO KT LKTN

    QBDLBHFKTPO KT LKTN QBDLBHFKTPO γϯϘϦοΫϦϯΫ࡞੒ CVJMEFYQPOPEF@NPEVMFT@JNQPSUFE KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO https://github.com/kgmyshin/kotlin-expo-sample/blob/master/kotlin-expo-gradle-plugin/src/main/kotlin/com/kgmyshin/kotlin/expo/tasks/UnpackGradleDependenciesTask.kt
  31. X © DMM.com OQNJOTUBMM CVJMEFYQPOPEF@NPEVMFT KT LKTN QBDLBHFKTPO OQNJOTUBMM KT

    LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO https://github.com/kgmyshin/kotlin-expo-sample/blob/master/kotlin-expo-gradle-plugin/src/main/kotlin/com/kgmyshin/kotlin/expo/tasks/NpmInstallTask.kt
  32. X © DMM.com OQNJOTUBMM CVJMEFYQPOPEF@NPEVMFT KT LKTN QBDLBHFKTPO OQNJOTUBMM KT

    LKTN QBDLBHFKTPO KT LKTN QBDLBHFKTPO KT QBDLBHFKTPO KT QBDLBHFKTPO KT QBDLBHFKTPO ʜ https://github.com/kgmyshin/kotlin-expo-sample/blob/master/kotlin-expo-gradle-plugin/src/main/kotlin/com/kgmyshin/kotlin/expo/tasks/NpmInstallTask.kt
  33. X © DMM.com ͨͩʜ "OESPJE :PVS$PEF J04 8FC .BD 8JO

    -JOVY &MFDUSPO 3/ w ຊ౰ʹͰ͖Δͷʜʁʁ w ΍ͬͯΔͷΈͨ͜ͱͳ͍͚Ͳʁʁ
  34. X © DMM.com ͨͩʜ "OESPJE :PVS$PEF J04 8FC .BD 8JO

    -JOVY &MFDUSPO 3/ w ຊ౰ʹͰ͖Δͷʜʁʁ w ΍ͬͯΔͷΈͨ͜ͱͳ͍͚Ͳʁʁ Ͱ͖ΔΑʂ