accompanist icon indicating copy to clipboard operation
accompanist copied to clipboard

[Permissions] `MutableMultiplePermissionsState.shouldShowRationale` returns true despite some permissions being `Denied(shouldShowRationale=false)`

Open FelixZY opened this issue 1 year ago • 4 comments

Description

The current implementation of MutableMultiplePermissionsState.shouldShowRationale does not consider cases where one or more permissions are Denied(shouldShowRationale=false). This causes issues in statements such as

val permissions = rememberMultiplePermissionsState(listOf(ACCESS_FINE_LOCATION, ACCESS_BACKGROUND_LOCATION))

when {
  // Granted
  permissions.allPermissionsGranted -> Unit,
  // Denied, but I can ask the user
  permissions.shouldShowRationale -> 
    // ERROR: Does not trigger!
    permissions.launchMultiplePermissionRequest()
  // Denied and I may not ask the user.
  else -> Unit
}

The issue is located at

https://github.com/google/accompanist/blob/57907e1c9aadef1f70e51889c04048693e983f21/permissions/src/main/java/com/google/accompanist/permissions/MutableMultiplePermissionsState.kt#L130

Suggested fix:

    override val shouldShowRationale: Boolean by derivedStateOf {
-       permissions.any { it.status.shouldShowRationale }
+       permissions.any { it.status.shouldShowRationale } && permissions.none { !it.status.isGranted && !it.status.shouldShowRationale }
    }

FelixZY avatar Jul 05 '24 16:07 FelixZY

That does make sense. PR's welcome!

bentrengrove avatar Jul 09 '24 20:07 bentrengrove

I'm also having this issue

BobbyESP avatar Jul 29 '24 10:07 BobbyESP

However I have issue with this in which shouldShowRationale is never being trigger even I already click don't allow. Check report bugs I have made.

hafiz013 avatar Aug 01 '24 03:08 hafiz013

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 Sep 16 '24 03:09 github-actions[bot]

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 Nov 04 '24 03:11 github-actions[bot]

@bentrengrove as far as I know this has not yet been resolved? Could you please reopen?

FelixZY avatar Nov 10 '24 12:11 FelixZY