Thread
#compose
    Philip S

    Philip S

    1 year ago
    How do you mock
    rememberLauncherForActivityResult
    in Compose? With
    registerForActivityResult
    you could send in a
    registry
    parameter to prevent the real implementation from being called in UI-tests. However this is missing for the Compose equivalent.
    n

    nitrog42

    1 year ago
    Compose
    @Preview
    now provides a
    LocalActivityResultRegistryOwner
    that allows you to preview Composables that use APIs like
    rememberLauncherForActivityResult()
    that depend on that owner existing. (Ib13d1, b/185693006)
    oh sorry I thought it was for the Preview
    i

    Ian Lake

    1 year ago
    Just provide your own registry via
    LocalActivittResultRegistryOwner
    Philip S

    Philip S

    1 year ago
    How? I tried:
    val registry = registryWrapper.activityResultRegistry
    
    if (registry != null) {
        LocalActivityResultRegistryOwner.provides {
            registry
        }
    }
    val current = LocalActivityResultRegistryOwner.current?.activityResultRegistry
    
    require(registry == current)
    where registry is my mocked registry (i debugged to check that it is not null).
    rememberLauncherForActivityResult
    Will still not take my mocked registry and calling
    .current
    does not return my mocked registry
    i

    Ian Lake

    1 year ago
    That's what makes that value you provide available to everything under that hierarchy
    Philip S

    Philip S

    1 year ago
    It works now thanks for the help