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

Compose Multiplatform 101

Compose Multiplatform 101

Compose Multiplatform 101: A declarative framework for sharing UIs across Multiplatform with Kotlin.

Leonardo YongUk Kim

September 12, 2023
Tweet

More Decks by Leonardo YongUk Kim

Other Decks in Programming

Transcript

  1. Dalinaum (Leonaro YongUk Kim) @ Coupang Pay Compose Multiplatform 101

    A declarative framework for sharing UIs across Multiplatform with Kotlin.
  2. Copyright © 2022 Coupang, Inc. All right reserved. ࢎਊػ ݽٚ

    ௢౿ ࢚಴৬ ௢౿ ۽Ҋ ߂ ࢲ࠺झ ݃௼ח ޷Ҵ ߂ ӝఋ Ҵоী ١۾غ য ੓ח Coupang, inc. ߂/ژח Ӓ ҅ৌࢎ(ాடೞৈ “௢౿”੉ۄ ೣ)੄ ੤࢑ੑפ׮. Ӓ ৻ ৈӝࢲ ঱әػ ഥࢎח ध߹ ݾ੸ਵ۽݅ ঱әػ Ѫ ਵ۽, ௢౿਷ ࢎਊػ ӝসݺ੉ ز ഥࢎ੄ ١۾ ࢚಴ੌ ࣻ ੓ਵݴ ೧׼ ഥࢎо ױةਵ۽ ز ࢚಴ী ؀ೠ ة੼੸ ࣗਬӂਸ о૓׮ח Ѫਸ ੋ੿ ೤פ׮. ৈӝী ನೣػ ੿ࠁח ੐૒ਗਵ۽ࢲ ੷੗ ࠄੋ੄ ѐੋ੸ ҃೷ਸ ߄ఔਵ۽ ೠ Ѫਵ۽ ௢౿੄ Ѽ೧ա ੄Ѽਸ աఋղח Ѫ੉ ইשਸ ߋഃ نפ ׮. ௢౿਷ ৈӝী ನೣػ ੿ࠁ੄ ੸੺ࢿ੉ա ҕ੿ࢿ, ੿ഛࢿ, উ੿ࢿী ؀೧ ഛੋೞ૑ ঋওਵݴ, Ӓী ؀ೠ যځೠ ૓ࣿب ೞ૑ ঋणפ׮.
  3. Compose Multiplatform੉ۆ? • Google੄ Jetpack Composeী ӝ߈ೠ JetBrains੄ য়೑ࣗझ ೐۽ં౟

    • Kotlin Multiplatformী ੄ઓ. • Androidח Kotlin/JVM, ART (Android Runtime)ী ӝ߈ೞৈ ز੘ೣ. • iOSח Kotlin/Native ӝࣿী ӝ߈ೞৈ ֎੉౭࠳ ௏٘۽ ࠽٘. • Desktop਷ JVM (Java virtual machine)ী ӝ߈ೞৈ ز੘. (ઑӘ पݎ. ֎੉౭࠳ ইש) • Web਷ Kotlin/WASM ী ӝ߈ೞৈ ز੘. • SKIKOܳ Ӓې೗ ۨ੉য۽ ࢎਊ.
  4. ݣ౭ ߔূ٘੄ Kotlin • ׮নೠ ߔূ٘ܳ ૑ਗ • JVM ߔূ٘

    • Java bytecodeо ఋѶ • JavaScript ߔূ٘ • Native ߔূ٘ • LLVM ӝ߈ (LLVM bitcode)
  5. Web Assembly • അ؀੸ੋ ਢ ࠳ۄ਋੷о ଻ఖೞҊ ੓ח झ ఖ

    ӝ߈੄ о࢚ ݠन. • JVM਷ झఖ ӝ߈, উ٘۽੉٘ Dalvik਷ ۨ ૑झఠ ӝ߈੄ о࢚ݠन. • WAPM ࢎ੉౟ ١ীࢲ рױೠ ౵੉ॆ ௏٘, C ঱য ௏٘١ਸ ਢ ࠳ۄ਋੷ী प೯೧ࠅ ࣻ ੓਺. • https://wapm.io/python/python (module (func (export "addTwo") (param i32 i32) (result i32) local.get 0 local.get 1 i32.add))
  6. 15 Kotlin Multiplatformਸ ਤ೧ ೙ਃೠ Ѫ Xcode Xcodeח ߔӒۄ਍٘ীࢲ ࣻ೯

    ؽ. Kotlin/Nativeо ੄ઓೞח ߡ੹ਸ ࢸ஖೧ঠ ೣ.
  7. 16 Kotlin Multiplatformਸ ਤ೧ ೙ਃೠ Ѫ Kotlin Multiplatform Mobile উ٘۽੉٘

    झౚ٣য়ীࢲ Kotlin Multiplatform Mobile ೒۞Ӓੋ ࢸ஖.
  8. 17 Kotlin Multiplatformਸ ਤ೧ ೙ਃೠ Ѫ JDK Android Studioী ੄೧

    ࢸ஖. Kotlin Plugin Android Studioী ࢸ஖. সؘ੉౟ܳ ೧ࢲ ߡ੹ਸ ୭नച ೧ঠ.
  9. 19

  10. 23 জ ֎੐ ӝࠄਵ۽ androidApp, iosApp, shared۽ জ ֎੐੉ ੿೧૗.

    iOS framework distribution਷ Regular۽ Cocoapods -_-ਸ ࢶఖೡ ࣻ ੓਺.
  11. 28

  12. 29 ߡ੹ ୊ܻח যڌѱ ೮ਸөਃ? expect৬ actual shared/src/ commonMain iOS৬

    Androidীࢲ ݽف ࢎਊೡ ੋఠಕ੉झܳ expect ఃਕ٘۽ ݅ٞ.
  13. 32 KMP for iOSীࢲ ݅աѱ غח ࢚ടٜ ObjC അ੤ Kotlin਷

    ObjC݅ ૑ਗ೧ࢲ ઁցܼ ௿ېझ݅ ૑ਗೞҊ ੋఠಕ੉झܳ ૑ਗೞ૑ ޅೣ. Abstract class ܳ ؀न ࢎਊ೧ঠ ೣ. (ઁցܼ੄ ؀࢚ਵ۽ ௿ېझ݅ оמೠ Ѫب ױ੼) 
 @HinddenFromObjC, @ObjcName ఃਕ٘ܳ ੸ӓ੸ਵ۽ ഝਊೞ੗. @ObjcName(swiftName=“_”) APIܳ झਤ೐౟ ׹ѱ ೞӝ ਤ೧ ੗઱ ࢎਊೡ Ѫ੐. plane.fuel(volume: .Gallons(gallons: 12.5)) ؀न plane.fuel(.Gallons(12.5)) 
 ੢ӝ੸ਵ۽ח ௏౟ܽ੉ Swiftܳ ߄۽ ఋѱ౴ೡ Ѫ੐. Swiftܳ ObjeCܳ ઁ৻ೞҊ ߄ੋ٘ೡ ࣻ হ঻ӝী ߊ ࢤೠ ޙઁ. SourceKitten৬ э਷ بҳٜ۽ ઺р ௏٘ܳ ࢤࢿೞ੗. ۄੋ ؘ݃ী஢੉ ѻ਷ য۰਑ Suspend suspendח ௒ߔ(completion handler)੉ غҊ ௒ߔ਷ Swiftীࢲ async۽ ഐ୹ оמೞ૑݅ ஂࣗо ࠛ оמೣ. 
 Flowب ੜ ૑ਗغ૑ ঋ਺. Flowо ੋఠಕ੉झ੉Ҋ KMPਸ ੜ૑ਗೞ૑ ޅೣ. (ৈ۞ߣ੄ நझ౟о ೙ਃ) 
 KMP-NativeCoroutines ۄ੉࠳۞ܻܳ ഝਊ೧ঠ ೣ. https://github.com/rickclephas/KMP-NativeCoroutines 
 ௏ౣܽ ৘৻о झਤ೐౟ ೩ٜ۞ ੹׳ غ૑ ঋਸ ࣻ ੓য @Throws ఃਕ٘۽ Errorܳ ૑੿೧ঠ ೣ.
  14. 33 KMP for iOSীࢲ ݅աѱ غח ࢚ടٜ CocoaPods ই૒ ҕध੸ਵ۽

    SPM(Swift Package Manager)ܳ ૑ਗೞ૑ ঋ਺. Gradle API ࣻળীࢲ ੿ܻػ ੉റ ী ૑ਗೠ׮Ҋ ೣ. (঱ઁ?) CocoaPodsח ੄ઓࢿਸ ࣗझ۽ оઉ৬ э੉ ࠽٘ী ࢎਊೞӝী ݒ਋ ࠺ബਯ੸. TouchLab੄ ۄ੉࠳۞ܻ KMMBridgeܳ ࢎਊ೤द׮. https://github.com/touchlab/KMMBridge 
 
 SPMਸ ؀਽ೞӝ ਤ೧ࢲח Git ܻನ૑షܻ৬ झక౮ ౵ੌ ੷੢ࣗо ೙ਃೞ׮. (AWS?) Frozen Global Objectח ӝࠄਵ۽ frozen. ੽Ӕೡ ࣻ ੓૑݅ ߸҃ೡ ࣻ হ਺. @ThreadLocalਸ ࠢ੉ݶ freeze ഐ୹ উೣ. Atomicೠ ੗ܐҳઑ੄ ࢎਊ੉ ೙ਃೡ ࣻ ੓׮. 
 freeze() ഛ੢ ೣࣻܳ ੉ਊ೧ ؘ੉ఠܳ ঴ܾ ࣻ ੓Ҋ ಽ ࣻח হ਺. Global ೐۽ಌ౭ח ݫੋझۨ٘ীࢲ݅ ࠅ ࣻ ੓਺.
  15. 34 KMP for iOSীࢲ ݅աѱ غח ࢚ടٜ Memory Management झఖ

    ౟ۨ੉झ ٣ߡӦ য۵Ҋ, ݫݽܻ ݒפ૑ݢ౟о ই૒ উ੿੸੉૑ח ঋ਺. 
 https://youtrack.jetbrains.com/issue/KT-55512 ଵҊ Kotlin Multiplatform Mobileਸ ഝਊೠ ؘ݃ী஢ ٘ۄ੉ߡজ ѐߊ ੉ঠӝ Kotlin/Multiplatform for iOS developers : state & future by Salomon Brys
  16. 36 Compose Multiplatform iOS Android Application మ೒݁ਸ ੉ਊ೧ࢲ द੘೧ঠ మ೒݁

    https://github.com/JetBrains/compose-multiplatform-ios-android-template
  17. 37 Compose for iOSܳ ਤ೧ ೙ਃೠ Ѫ Android Studio Android

    জҗ iOS জܳ प೯ೡ ࣻ ੓ח ѐߊ ജ҃. Xcode Xcodeח ߔӒۄ਍٘ীࢲ ࣻ೯ ؽ. Kotlin/Nativeо ੄ઓೞח ߡ੹ਸ ࢸ஖೧ঠ ೣ. Kotlin Multiplatform Mobile উ٘۽੉٘ झౚ٣য়ীࢲ Kotlin Multiplatform Mobile ೒۞Ӓੋ ࢸ஖. CocoaPods Compose for iOSب SPM(SwiftPackageManager)ܳ ૑ਗೞ૑ ঋ਺.
  18. 47 Compose for Desktop੄ ౠ૚ Cross- Platform ݣ౭೒ۖಬ੉ ইצ ௼۽झ೒ۖಬਵ۽

    ࠙ܨ. 
 JVM੉ ఋѶ੉Ҋ JVM ؋ী ৈ۞ ೒ۖಬীࢲ بח Ѫਸ ௼۽झ೒ۖಬਵ۽ ࢸݺ. SKIKO SKIA੄ ௏ౣܽ ߄ੋ٬ SKIKOী ੄೧ ۪؊݂. https://github.com/JetBrains/skiko SKIA੄ ಪ౟ ۪؊݂੉ ਍৔୓ઁ ݃׮ ׳ۄ झ௼ܽ ࢫ పझ౟ܳ ೞ૑ ݈੗. Compose Multiplatform IDE support ੋభܻઁ੉ ই੉٣যա উ٘۽੉٘ झౚ٣য়ী ࢸ஖. https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support IntelliJ IDEA ੋభܻઁ੉ ই੉٣য 2020.3 ੉࢚ীࢲ ࢎਊоמ.
  19. 48 Compose for Desktop੄ ౠ૚ ଵҊ৔࢚ You can do desktop

    too! By Victor Kropp https://www.youtube.com/watch?v=Mgf_9kxM1BA JDK 15 JDK11ਵ۽ ೐۽ં౟ ࢤࢿ оמ. ֎੉౭࠳ ߓನ ಁః૚ਸ ਤ೧ࢲח 15 ੉࢚.
  20. 50

  21. 51

  22. 53 Compose for Web੄ ౠ૚ WebAssembly JavaScriptܳ ॳ૑ ঋҊ WebAssembly۽

    प೯. Kotlin/WASM੉ ఋѶ. Compose HTML HTMLਸ ࢤࢿೞח Kotlin/JS੄ ۄ੉࠳۞ܻب ੓਺. Compose for Webҗ ޖҙ. Compose Multiplatform IDE support ੋభܻઁ੉ ই੉٣যա উ٘۽੉٘ झౚ٣য়ী ࢸ஖. https://plugins.jetbrains.com/plugin/16541-compose-multiplatform-ide-support IntelliJ IDEA ੋభܻઁ੉ ই੉٣য 2020.3 ੉࢚ীࢲ ࢎਊоמ.
  23. 55

  24. 56

  25. 58