Closed rzolin closed 7 months ago
Hmm.. by sample are you referring to this app?
Can you verify if you included router as an API dependency like this?
Yes, that app, which is included in the GitHub repo.
The line api(project(":decompose-router"))
was originally there (and it works on iOS that way), but since I am linking the project to the repo as this:
decompose-router = "0.6.0"
decompose-router = { module = "io.github.xxfast:decompose-router", version.ref = "decompose-router" }
sourceSets {
val commonMain by getting {
dependencies {
// Only need to add this as api if you wish to add your own AppDelegate in swift
implementation(libs.decompose.router)
the inclusion of the directories decompose-router
and decompose-router-wear
are no longer needed. And it is true for Android, though not for iOS.
Any updates? I would love to export to iOS without including the code in the directories decompose-router and decompose-router-wear
Hi. Sorry I'm struggling a little to understand a little context around your usage.
Is there a reason why you are including your dependency as implementation
instead of api
?
I would love to export to iOS without including the code in the directories decompose-router and decompose-router-wear
Exporting allows your iOS project to reference RouterContext
and its lifecycle triggeres (resume
, stop
and destroy
) from your AppDelegate (as outlined here).
However - alternatively, If you don't want to export decompose-router
for whatever reason, you can still export only the bare essentials by creating your own exports. To do that
export()
and api()
declarations from the build script// iosMain/MyCustomExport.kt
fun defaultRouterContext(): RouterContext = defaultRouterContext()
private val RouterContext.lifecycleRegistry: LifecycleRegistry get() = this.lifecycle as LifecycleRegistry
fun RouterContext.destroy() = lifecycleRegistry.destroy()
fun RouterContext.resume() = lifecycleRegistry.resume()
fun RouterContext.stop() = lifecycleRegistry.stop()
fun RouterContext.pause() = lifecycleRegistry.pause()
Update your delegate on swift
var defaultRouterContext: Decompose_routerRouterContext { delegate.holder.defaultRouterContext }
var body: some Scene {
WindowGroup {
HomeView(routerContext: defaultRouterContext)
}
.onChange(of: scenePhase) { newPhase in
switch newPhase {
case .background: defaultRouterContext.stop()
case .inactive: defaultRouterContext.pause()
case .active: defaultRouterContext.resume()
@unknown default: break
}
}
}
Arguably this is more setup, and it would be easier to export decompose-router
as an API dependency.
Thanks for clarification. I am new to Android/Gradle.
Is there a reason why you are including your dependency as implementation instead of api? I think it's just my lack of understanding Gradle. Does
implementation
mean that the code should be present, andapi
that the code is included in a library/module? I was following the pattern how other libs are linked, likeimplementation("libs.decompose")
.
The general idea is to use the AppDelegate in iOS, as your sample app does. I will probably expand it with other things like sessions and etc. But when I removed the included directories "decompose-router" and "decompose-router-wear" (and reference them it stopped building for iOS.
Anyway, it looks like if I replace implementation("decompose-router")
with api("decompose-router")
it builds. Just having some issues with launching the simulator. But it's another issue.
Does implementation mean that the code should be present, and api that the code is included in a library/module? I was following the pattern how other libs are linked, like implementation("libs.decompose").
Basically, api
will make my library be transitively exposed to your shared module. You can learn more about the api/implementation difference here
I'll update the docs here to include instructions on exporting for future reference
Thanks
I am coming from iOS side of things and a bit lost here. The documentation and the closed issue says that I need to export the RouterContext to use it in AppDelegate. At the moment I am trying to build your stripped sample app for iOS, it builds for Android, but iOS spits out the error:
I do export RouterContext as following:
Still not sure what I am missing or doing wrong. Please advise