xxfast / Decompose-Router

A Compose-multiplatform navigation library that leverage Decompose to create an API inspired by Conductor
https://xxfast.github.io/Decompose-Router/
221 stars 9 forks source link

how to provide RouterContext for ios side correctly 0.5.0 in update #70

Closed adelsaramii closed 10 months ago

adelsaramii commented 11 months ago

i saw your example about platform-configurations Ios but there is no sample and im lost i give you better look from my code and please guide me how to implement ios part

Class main.ios.kt

fun MainViewController(routerContext : RouterContext) = ComposeUIViewController {

    CompositionLocalProvider(LocalRouterContext provides routerContext) {

        App()

    }

}

swift file ContentView.swift

import UIKit
import SwiftUI
import shared

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

   func updateUIViewController(_ uiViewController: UIViewController, context: Context) {}
}

struct ContentView: View {
   var body: some View {
       ComposeView()
               .ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler
   }
 }

swift file IOSApp

import SwiftUI

@main
struct iOSApp: App {
        var body: some Scene {
         WindowGroup {
             ContentView()
        }
     }
 }
xxfast commented 11 months ago

Hi @adelsaramii Thanks for opening the issue. You will need to have an AppDelegate defined like this. Let me know if that helps

adelsaramii commented 11 months ago

Hi @adelsaramii Thanks for opening the issue. You will need to have an AppDelegate defined like this. Let me know if that helps

i did but in AppDelegate.swift the RouterContextKt is Unresolved reference. i did every step from your code also i did import shared module is this problem from your library? and aslo defaultComponentContext is Unresolved reference in shared -> ios. Please guide me

xxfast commented 10 months ago

Hi @adelsaramii apologies for the late reply.

You'll need to add this file RouterContext.kt in your shared module, under the iosMain source set

fun defaultRouterContext(): RouterContext = defaultRouterContext()
val Lifecycle.registry get() = this as LifecycleRegistry
fun Lifecycle.destroy() = registry.destroy()
fun Lifecycle.resume() = registry.resume()
fun Lifecycle.stop() = registry.stop()

With that, RouterContextKt should no longer be an unresolved reference.

I think you raised a good issue here - it is not intuitive to set this up, and the documentation is unclear. I will use this issue to address this.

voitenkodev commented 10 months ago

Same problem for me

import io.github.xxfast.decompose.router.defaultRouterContext

Unresolved reference for iOS target

xxfast commented 10 months ago

Hi @adelsaramii & @voitenkodev

I've added this section in the readme, that covers how to setup decompose-router on ios - and added code-examples for kotlin app delegates, and both swift-ui app and swift uikit app delegate.

The defaultRouterContext() should now be available on the latest snapshot 0.5.1-SNAPSHOT. Make sure to include the snapshot repository on your build if you wish to try out the snapshot builds - otherwise I will release stable 0.5.1 later today

Let me know how it goes

xxfast commented 10 months ago

Addressed in 0.5.1 🎉

adelsaramii commented 10 months ago

Thanks for fix