0Pricing
Kotlin Multiplatform Academy · درس

استضافة الواجهة المشتركة على iOS وDesktop

تضمين composables نفسها في كل هدف

استضافة الواجهة المشتركة على iOS وDesktop درس مجاني في Kotlin Multiplatform Academy على CoddyKit. هذا هو الدرس 4 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Kotlin Multiplatform Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Same App, New Hosts

Your shared App composable is ready. Now each platform needs a small entry point that mounts it. The UI code itself never changes.

iOS Wraps Compose in a Controller

On iOS you expose your composable through a UIViewController. The function ComposeUIViewController hands SwiftUI a controller it can present.

fun MainViewController() =
    ComposeUIViewController { App() }

Call It from SwiftUI

From SwiftUI you wrap that controller in a UIViewControllerRepresentable, so your Kotlin screen becomes an ordinary SwiftUI view.

struct ComposeView: UIViewControllerRepresentable {
    func makeUIViewController(context: Context) -> UIViewController {
        MainViewControllerKt.MainViewController()
    }
}

iOS Renders Natively

Under the hood Compose draws using Skia onto an iOS surface, so your shared screen feels native and shares logic with Android seamlessly.

Desktop Uses a Window

On desktop you launch the same App inside an application window. A few lines of Kotlin give you a real desktop program.

fun main() = application {
    Window(onCloseRequest = ::exitApplication) {
        App()
    }
}

Desktop Runs on the JVM

The desktop target compiles to the JVM and renders with Skia too, so the same composables you wrote for phones run on macOS, Windows and Linux.

One Composable, Three Hosts

Android uses setContent, iOS uses a view controller, desktop uses a window. All three call the very same shared App function.

Share Even More by Default

Because hosting is the only platform-specific part, almost everything you build lives in commonMain. The shared surface grows large.

Tweak Per-Platform When Needed

You can still branch on platform inside shared code for things like window size or safe areas, keeping a single codebase that adapts nicely.

Test the UI Once

Shared UI means shared UI tests in commonTest, so you verify behavior a single time and trust it on every host you ship to.

Ship Three Apps from One

With hosts wired up, a single Compose codebase powers your Android, iOS and desktop releases, cutting duplicated UI work dramatically. 🚢

Quick Check

How does iOS host a shared composable?

Recap: Host It Everywhere

You mounted the same shared App on iOS through a view controller and on desktop through a window. One Compose codebase, three platforms shipped. 🎯

الأسئلة الشائعة

هل درس «استضافة الواجهة المشتركة على iOS وDesktop» مجاني؟

نعم — نص درس «استضافة الواجهة المشتركة على iOS وDesktop» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Kotlin Multiplatform Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Kotlin Multiplatform Academy 4 دروس في المجموع.

ماذا ستتعلم في «استضافة الواجهة المشتركة على iOS وDesktop»؟

تضمين composables نفسها في كل هدف تتمرن على Kotlin Multiplatform Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Kotlin Multiplatform Academy؟

لا تُشترط خبرة سابقة. Kotlin Multiplatform Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 4 من أصل 4.

كم من الوقت يستغرق درس «استضافة الواجهة المشتركة على iOS وDesktop»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Kotlin Multiplatform Academy هذا؟

نعم. كل درس في Kotlin Multiplatform Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. تمكين Compose Multiplatform
  2. التخطيطات وModifiers وتنسيق الواجهة
  3. الحالة وإعادة التركيب في الواجهة المشتركة
  4. استضافة الواجهة المشتركة على iOS وDesktop
← العودة إلى Kotlin Multiplatform Academy