Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
adelsaramii opened this issue Oct 7, 2023 · 7 comments
Closed
Labels
documentation Improvements or additions to documentation

Comments

@adelsaramii
Copy link

adelsaramii commented Oct 7, 2023

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()
	    }
     }
 }
@adelsaramii adelsaramii changed the title how to provide RouterContext for ios side correctly how to provide RouterContext for ios side correctly 0.5.0 in update Oct 7, 2023
@xxfast
Copy link
Owner

xxfast commented Oct 11, 2023

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

@adelsaramii
Copy link
Author

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
Copy link
Owner

xxfast commented Oct 19, 2023

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
Copy link

Same problem for me

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

Unresolved reference for iOS target

@xxfast
Copy link
Owner

xxfast commented Oct 22, 2023

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 xxfast added the documentation Improvements or additions to documentation label Nov 1, 2023
@xxfast
Copy link
Owner

xxfast commented Nov 1, 2023

Addressed in 0.5.1 🎉

@xxfast xxfast closed this as completed Nov 1, 2023
@adelsaramii
Copy link
Author

Thanks for fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

3 participants