[英]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.