Abdullah
01/09/2024, 10:09 PMAndrei Salavei
01/10/2024, 9:37 AM@Composable UIKitViewController()
.
Could you please elaborate a bit regarding your problem?Abdullah
01/10/2024, 12:38 PMfun ComposeEntryPointWithUIView(createUIView: () -> UIView): UIViewController =
ComposeUIViewController {
Column(horizontalAlignment = Alignment.CenterHorizontally) {
UIKitView(
factory = createUIView,
modifier = Modifier
.size(300.dp)
.border(2.dp, Color.Blue),
)
}
}
but I couldn't call it from kotlin because it has lambda.Abdullah
01/10/2024, 12:44 PMAndrei Salavei
01/10/2024, 1:11 PMUIHostingController
with SwiftUI you needed, and pass this object to Kotlin Code in any way you want (Like factory interface, or just as a reference).
Then you need to use UIKitViewController()
instead of UIKitView()
to place this controller on the compose scene.Abdullah
01/10/2024, 3:11 PMAndrei Salavei
01/10/2024, 3:52 PMAbdullah
01/11/2024, 12:04 AMAndrei Salavei
01/11/2024, 9:13 AM// Kotlin:
interface Factory {
companion object {
var shared: Factory? = null
}
fun makeController(): UIViewController
}
@Composable
fun MyView() {
UIKitViewController(
Factory.shared!!.makeController(),
...
)
}
// Swift:
class TheFactory: Factory {
func makeController() -> UIViewController {
MySwiftUIViewController()
}
}
class MySwiftUIViewController: UIHostingController { ... }
class AppDelegate: UIApplicationDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
FactoryCompanion().shared = TheFactory()
...
return true
}
}
Abdullah
01/12/2024, 9:01 PM