Hello All , I want to create project with followin...
# multiplatform
g
Hello All , I want to create project with following scenarios: 1. I have four screen out of which 1st is in compose, 2nd is in SwiftUI Native , 3rd is in compose, 4th is in SwiftUI Native. 2. Want to understand how we can navigate from compose to SwiftUI and SwiftUI to compose . please help also if you have any examples please share .
j
There is a gazillion many ways solving this 😄 Do you want to use frameworks, mixing frameworks, doing it manually etc. What I would decide first, do you want to use native navigation or compose library navigation. That depends how you structure your app ui. If you go compose way of doing things I would check like Decompose, Voyager, Circuit or such library with a navigation host, and using compose interop with UiKitView wrappers to "embed" SwiftUI native sceens. You can do the other way around as well, and navigate native in Swift with lets say StackView or whatever and then using ComposeUiViewController from Swift to embed compose screens. Somewhere need to decide if the glue should be compose or Swift I think, to glue together all navigation. That including structure how to navigate to controllers, deep links and such.
g
I do not have clear knowledge about this as I am new to the technology. I gone through some of the examples but they give only have single screen application . But when it comes to multiple screen I don’t understand how will it flow. Please guide me with standard which is executed by developers. Thank you
j
There is no standard way, compose for iOS is still in alpha. I personally using Circuit, see https://slackhq.github.io/circuit/navigation/ The main concept if going that road, is having some kind of navigation host container in compose, acts as root level container to switch between screens. Do you have to mix SwiftUi and Compose or? If you can its easiest if not mix at all. I mean its possible but more complex. The concept of the navigation host, is having SwiftUi/UiViewcontroller only having ONE root composable and then navigating inside that. Meaning a screen will be hosted in that navigation host. And not same as in the native world of viewcontrollers, even if can mix that as well.
Also are you target only iOS or other platforms, such as Android, desktop or so?
g
Only Android and IOS
p
@Joel Denke I think you have tried the swift and compose interop , I have a doubt What is my usecase? I want to be able to pass different kinds of swifUI views and use them in my compose screens For eg.SignInWithApple button in swift UI, I m passing that to compose since I wasn’t able to implement the native sign in using kotlin/native currently from documentation what I am able to achieve is My pure swift code that connects ios application to
Copy code
struct ComposeView: UIViewControllerRepresentable {
   
    func makeUIViewController(context: Context) -> UIViewController {
        MainViewControllerKt.MainViewController(createUIView: { () -> UIView in
            SwiftUIInUIView(
                content: SignInWithAppleView()
            )
        }
        )
    }

    func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}
now this is the only function of this kind that is there by default and calls the entry point function from iosMain now whatever swfit ui views that I want to pass to my compose code, say a button , or some other swift ui view DO I NEED TO PASS THEM ALL AS DIFFERENT PARAMETERS IN THIS(MainViewController) FUNCTION ONLY? 2nd question This is the defination of MainViewController function in Kotlin
@OptIn(ExperimentalForeignApi::class)
fun MainViewController( createUIView: () -> UIView ):UIViewController =
_ComposeUIViewController_ *{*
_App_(swiftUIView = *{*
_UIKitView_(
factory = createUIView, modifier = Modifier.
_wrapContentWidth_()
)
*}*)
}
In above function I have createUIView as parameter which is the swift view that I am passing from swift code But the issue is I only have it available in the scope of this function Now I have passed it to my App() composable in common code and I can use it, but how do I use that createUiVIew paramter in some other function which I can call using expect actual in any part of my compose screen, Right now it seems like I will have to pass it from screen to screen for eg: App() -> SignInScreen()-> OnboardingScreens() (4-5)->HomeScreen() Now what If I want to use that createUIVIew in Homescreen? I dont want to pass it from App() composable all the way to Homescreen