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

Koin-Integration: getting scoped ScreenModel #406

Open
andretietz opened this issue May 2, 2024 · 0 comments
Open

Koin-Integration: getting scoped ScreenModel #406

andretietz opened this issue May 2, 2024 · 0 comments

Comments

@andretietz
Copy link

I am struggeling with following problem:

Having a KMP/compose multiplatform Project (mainly Android&Desktop) and need to scope(koin) my ScreenModel for Android-Lifecycle Reasons (in particular I am injecting a class that requires an activity to call and Android-API). In order to inject the screenmodel now, I have 2 different implementations of the screen, for Android & Desktop (no need for the scope on desktop).

Implementation on desktop:

class SignInScreen : Screen {
    @Composable
    override fun Content() {
        val viewmodel = getScreenModel<SignInViewModel>()
        AppTheme {
            Surface {
                ShowSignInScreen(
                    viewmodel = viewmodel
                )
            }
        }
    }
}

Implementation for Android:

class AndroidSignInScreen(private val scope: Scope) : Screen {
    @Composable
    override fun Content() {
        val viewmodel by scope.inject<SignInViewModel>()
        AppTheme {
            Surface {
                ShowSignInScreen(
                    viewmodel = viewmodel
                )
            }
        }
    }
}

My questions:

  1. Is there a way I can avoid the Android specific implementation? (prefered)
  2. Is there a way I can use getScreenModel on a scope? I read about navigation scoped screenmodels can this help somehow?

In ideal case the only difference between the platform implementations is the DI setup (sadly, I don't get rid of the scope on android => ideas are welcome, even though they don't belong here)

@andretietz andretietz changed the title KoinIntegration: getting scoped ScreenModel Koin-Integration: getting scoped ScreenModel May 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant