Are there any examples on how to call a Composable...
# compose-ios
c
Are there any examples on how to call a Composable that accepts slots (i.e., Composable lambdas) from SwiftUI?
I'm guessing it has something to do with the example shown here but I don't understand completely what's involved.
Given a Composable like this
Copy code
@Composable fun MyComposable(
    mainContent: @Composable () -> Unit,
    bottomStickyContent: @Composable () -> Unit
) {
    // My Implementation
}
I think I need to wrap it (still in Kotlin land, in
iosMain
) like this:
Copy code
// Wrapper for use from SwiftUI
fun MyComposableEntryPoint(
    createMainContent: () -> UIView,
    createBottomStickyContent: () -> UIView
): UIViewController {
    ComposeUIViewController {
        MyComposable(
            mainContent = {
                UIKitView(
                    factory = createMainContent()
                )
            },
            bottomStickyContent = {
                UIKitView(
                    factory = createBottomStickyContent()
                )
            }
        )
    }
}
And finally use it from Swift like this:
Copy code
// Usage from SwiftUI
Main_iosKt.MyComposableEntryPoint(
    createMainContent: { () -> UIView in
        // SwiftUI implementation of mainContent
    },
    createBottomStickyContent: { () -> UIView in
    // SwiftUI implementation of bottomStickyContent
    }
)
Still figuring out if I need the
UIViewControllerRepresentable
step. All of this is just theory. Will have to try it out tomorrow.
I tried a bunch of stuff with this and still could not get it to work as I wanted. • My biggest issue is that using
SwiftUIInUIView
as shown here results in every "slot" taking up the entire screen. • I tried to make some changes like not setting the autolayout constraints to take up the full space. This solves one problem but still another remains: My slots are not sized correctly. So my question is: Is it at all possible for a Composable to impose sizing constraints on a SwiftUI view embedded inside it?