Skip to content

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

@FelixZY

Description

@FelixZY

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

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

Metadata

Metadata

Assignees

Labels

staleStale issues which are marked for closure

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions