google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.42k stars 597 forks source link

[Permissions] Pass PermissionStatus instead of boolean to onPermissionResult #1721

Closed Digipom closed 8 months ago

Digipom commented 11 months ago

Description

Please pass in PermissionStatus to onPermissionResult instead of a boolean.

Steps to reproduce

Observe onPermissionResults signature.

Expected behavior

Receiving a PermissionStatus allows us to check the rationale.

Additional context

When the user says "Don't ask again", onPermissionResult is called with granted = false, and shouldShowRationale will also return false.

Example code:

var permissionDeniedFlag: Boolean by remember { mutableStateOf(false) }
    val state = rememberPermissionState(
        permission = MEDIA_STORAGE_PERMISSION,
        onPermissionResult = { granted ->
            if (granted) {
                // Handle permission granted...
                onPermissionGranted()
            } else {
                // Handle permission denied. Having the status in the callback would avoid having to use a launched effect here.
                permissionDeniedFlag = true
            }
        }
    )

    if (permissionDeniedFlag && !state.status.shouldShowRationale) {
        val context = LocalContext.current
        // Automatic denial without rationale means the user selected "don't ask again"
        LaunchedEffect(Unit) {
            try {
                context.openSystemSettingsScreenForApp()
                permissionDeniedFlag = false
            } catch (e: Exception) {
                // Handle exception
                onCouldNotOpenSystemSettings()
            }
        }
    }
github-actions[bot] commented 10 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Digipom commented 10 months ago

Bump to remove stale status

bentrengrove commented 10 months ago

We aren't making changes to the API right now, but I will keep this open for if we do consider making changes in the future because it is a good point

github-actions[bot] commented 8 months ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

Digipom commented 8 months ago

Bumping to remove stale status

Digipom commented 8 months ago

@bentrengrove the bot closed the issue. Is the team still not considering this or could the API be extended in the future? Thank you.