简体   繁体   English

在 Android 和 iOS 之间可以通过 Kotlin Multiplatform 共享什么?

[英]What can be shared through Kotlin Multiplatform between Android and iOS?

Would someone describe explicitly what exactly can be shared through Kotlin Multiplatform between Android and iOS?有人会明确描述通过 Android 和 iOS 之间的 Kotlin Multiplatform 究竟可以共享什么? For example, we have in Android: UI (xml) <---binding (Kotlin) ---> business logic (Kotlin).例如,我们在 Android 中有:UI (xml) <---binding (Kotlin) ---> 业务逻辑 (Kotlin)。 As per JetBrains, everything below UI (xml) can be shared.根据 JetBrains,UI (xml) 以下的所有内容都可以共享。 Does that mean also binding?这是否意味着也具有约束力? I also heared 100% can be shared.我也听说100%可以共享。 How is it than done with UI?与 UI 相比,它是如何完成的?

Thanks and best regards谢谢和最好的问候

The main idea behind Kotlin Multiplatform is that you share what´s under the hood. Kotlin Multiplatform 背后的主要思想是您共享引擎盖下的内容。 This means that you can share basically business logic while your UI remains native (note: in Android, the UI is not only the XML but also the Fragment/Activity with his bindings).这意味着您可以在 UI 保持原生状态的同时共享基本的业务逻辑(注意:在 Android 中,UI 不仅是 XML,而且是带有其绑定的 Fragment/Activity)。 One common approach for example is having an architecture pattern (like MVVM/MVP), you expose your presenters/viewmodels and interact with the native UI using interfaces (aka protocols in Swift).例如,一种常见的方法是使用架构模式(如 MVVM/MVP),公开您的演示者/视图模型并使用接口(在 Swift 中也称为协议)与本机 UI 交互。 The presenters, use-cases, repositories, and API calls are shared with kotlin and the UI is implemented in each platform.演示者、用例、存储库和 API 调用与 kotlin 共享,并且 UI 在每个平台中实现。

For code that needs to be implemented using platform-specific code, (like SharedPreferences in Android and NSUserDefaults for iOS), check the expect-actual mechanism in the Kotlin documentation)对于需要使用特定于平台的代码来实现的代码(如 Android 中的 SharedPreferences 和 iOS 的 NSUserDefaults),请查看 Kotlin 文档中的预期实际机制)

Moreover, you can also share abstractions for platform-specific libraries.此外,您还可以共享特定于平台的库的抽象。 For example, you can define an interface to interact with any platform library, provide the implementation on the iOS/Android side, and interact with it from the shared module.例如,您可以定义一个与任何平台库交互的接口,在 iOS/Android 端提供实现,并从共享模块与其交互。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Kotlin Multiplatform - iOS + Android 之间的策略共享 - Kotlin Multiplatform - Strategy sharing between iOS + Android 如何在 Android/IOS Kotlin 多平台项目中设置 protobuf - How to setup protobuf in Android/IOS Kotlin Multiplatform project 无法在 Kotlin 多平台项目中调试 iOS 应用程序 - Can't debug iOS application in Kotlin multiplatform project 在 Kotlin 多平台项目中与 Compose 共享活动 - Shared Activity with Compose in Kotlin Multiplatform project Android Studio:如何在 Kotlin 多平台共享模块 build.gradle.kts 中访问项目级 compileSdkVersion 和 targetSdkVersion? - Android Studio: How to access project level compileSdkVersion and targetSdkVersion in Kotlin Multiplatform shared module build.gradle.kts? Kotlin 多平台保留可选项 iOS 框架 - Kotlin Multiplatform keep optionals iOS framework iOS 依赖项在 Kotlin 多平台项目中未解决 - iOS dependences not resolving in Kotlin MultiPlatform Project iOS cocoaods 框架未在 Kotlin 多平台项目中生成 - iOS cocoaods framework not generating in Kotlin Multiplatform project Kotlin 多平台移动 (KMM)。我想让我的 Android 应用程序使用 KMM 在 iOS 上运行吗? - Kotlin Multiplatform Mobile(KMM) .I want to make my Android application work on iOS using KMM? 是否可以在多平台 Z1B4419ABC43A758B418ZA0CA50 应用程序中使用用 Kotlin 编写的 Android 和 iOS 的业务代码? - Is it possible to use business code for Android and iOS written in Kotlin in a multiplatform Xamarin application?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM