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

Avoid retaining outdated LocalKoinApplication/LocalKoinScope #1586

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on May 16, 2023

  1. Inject current Koin application from Android context

    The Koin application is looked up in the Context tree and the Koin CompositionLocals are provided with/from this value.
    This (still) requires this function to be called around the first time Koin is used from Compose.
    A practical place for this is the setContent function.
    This means that (boilerplate) code needs to be added to every Activity or Fragment using Compose, and every test case where a Composable is tested in isolation.
    
    Untested - will need verification with these test frameworks!
    
    Fixes InsertKoinIOgh-1557
    jjkester committed May 16, 2023
    Configuration menu
    Copy the full SHA
    7bf2a84 View commit details
    Browse the repository at this point in the history

Commits on May 17, 2023

  1. Look up LocalKoinApplication/LocalKoinScope if not explicitly provided

    By throwing an exception as default factory for the CompositionLocals we signal that there is no explicit value set. This will trigger the default lookup behavior that used to be the result of the factory function, as long as the appropriate functions getKoin() and getKoinScope() are used. By using the internal Compose API we are able to catch the exception to run the lookup code. We remember the result of the try/catch block to ensure we only incur the overhead of the exception once per `getKoin()` call per composition.
    
    Performance analysis and testing necessary!
    
    Fixes InsertKoinIOgh-1557
    jjkester committed May 17, 2023
    Configuration menu
    Copy the full SHA
    b784bf3 View commit details
    Browse the repository at this point in the history