accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Permissions] Pass PermissionStatus instead of boolean to onPermissionResult

Open Digipom opened this issue 2 years ago • 5 comments

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()
            }
        }
    }

Digipom avatar Oct 17 '23 18:10 Digipom

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.

github-actions[bot] avatar Dec 02 '23 03:12 github-actions[bot]

Bump to remove stale status

Digipom avatar Dec 02 '23 10:12 Digipom

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

bentrengrove avatar Dec 03 '23 22:12 bentrengrove

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.

github-actions[bot] avatar Jan 18 '24 03:01 github-actions[bot]

Bumping to remove stale status

Digipom avatar Jan 18 '24 13:01 Digipom

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

Digipom avatar Jan 24 '24 13:01 Digipom