Как интегрировать собственные представления SwiftUI в Compose Multiplatform с помощью UIKitView?Android

Форум для тех, кто программирует под Android
Ответить
Anonymous
 Как интегрировать собственные представления SwiftUI в Compose Multiplatform с помощью UIKitView?

Сообщение Anonymous »

I am building a Compose Multiplatform (CMP) application and need to leverage some iOS-specific native components (like MapKit or a custom SwiftUI chart) that are already built in SwiftUI.
While CMP provides excellent UI sharing, I need to ensure these specific components maintain their native performance and look-and-feel. I understand that I need to use UIKitView to bridge native iOS views, but I'm struggling with the boilerplate required to wrap a SwiftUI View into something Compose can render in iosMain.
The Goal:
I want to pass a title string from my shared Compose code and have it rendered inside a native SwiftUI VStack.
My Current Setup:
In my commonMain, I have an expect function:
Kotlin

Код: Выделить всё

@Composable
expect fun NativeButton(title: String, onAction: () -> Void)
Задача:
Как реализовать фактическую часть в iosMain? Specifically:
  • How do I use UIHostingController to convert the SwiftUI view into a UIViewController?
  • How do I extract the UIView from that controller for use inside the UIKitView factory?
  • How do I handle updates if the title state changes in Compose?
Any guidance on the standard 2026 patterns for this interop would be greatly appreciated!

Подробнее здесь: https://stackoverflow.com/questions/798 ... -uikitview
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Android»