New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Permissions] Clean up the APIs to guarantee a better UX #990
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description is 💯 🤩
Looks good to me, just a couple of nits!
permissions/src/main/java/com/google/accompanist/permissions/MutablePermissionState.kt
Outdated
Show resolved
Hide resolved
permissions/src/main/java/com/google/accompanist/permissions/PermissionsUtil.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is really great work. Well done @manuelvicnt
@manuelvicnt Hey, I am wondering if the sample could be improved. Currently, if I deny all permissions the app tells me In my opinion it is much better to open the settings that doing nothing. As a user I would wonder why nothing happens. Maybe the user denies the permissions and later, when the app is used again, wonders why it's not working. I know that anyone can implement it in a different way, but I als think it's especially important to consider this case as your sample might be the starting point for many developers. WDYT? |
Hi @ln-12, thanks for your feedback. We're working closely with UX and PM teams to see what's the best recommendation we can give here. Unfortunately, this is what we can show so far. If you think your app could benefit from a different UX, go ahead and implement that logic. That's fine too! Thanks! |
But doesn't this take away the possibility to directly ask the user when entering a composable? |
@PaulWoitaschek Can't you just do it like this? // define permission state
val locationPermissionsState = rememberMultiplePermissionsState(
listOf(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION
)
)
// call launch permission request on first composition
LaunchedEffect(Unit) {
locationPermissionsState.launchMultiplePermissionRequest()
} |
But that would also show the permission when the user is in a showRationale state right? |
Both So if I understand you correctly, you can launch the request when you enter your barcode screen and simply check |
Yes but that does not handle the case where the user denies the permission permanently. To handle the permission, I would need to do sth like this: val permissions = rememberPermissions()
when {
permissions.granted -> {
doSomethingWithpermission()
}
permissions.deniedAndShowRationale -> {
Dialog("we need permissions.") {
permissions.request()
}
}
permissions.deniedAndNotAsked -> {
permissions.request()
}
permissions.deniedButAsked -> {
Dialog("Enable the permissions in the settings") {
goToSystemSettings()
}
}
}
If I were to do it like that, the code in the the second {} would lead the user to the system settings. And that would immediately happen before the user answered the initial permission request. I don't see how this is possible without adding to the state if the user was actually asked for the permissions. |
I can see your problem now. In my project, I don't call If you directly want to open the settings, you would have to save the state somewhere which might lead to problems after the permissions are manually changed in the settings. |
Yes, that's how we do it too, though through a dialog. I updated my sample to match that request. That doesn't solve the problem though. So the only way I can think if to solve it with accompanist is to show a dialog before requesting the permission in the first place. It would be super helpful to add that flow to the samples. |
Right, that's unfortunately not something accompanist can solve. As Manuel mentioned in the PR description, the route the new APIs encourage is always having a button that would request the permission since we can't in general distinguish the "permanently denied" case. There's a possibility that you can still directly request the permission. You can use the callback in the |
Check out https://github.com/akardas16/Compose-Permissions for better implementation |
API breaking changes
The
isPermissionRequested
flag from thePermissionState
andMultiplePermissionsState
APIs is removed.true
the first time the permission result launcher returns with the user's choice, not uponlaunchPermissionRequest
being called.The
PermissionRequired
andPermissionsRequired
slot APIs have been removed.permissionsNotAvailableContent
slot misbehaved in different Android API versions, and just having two slots available doesn't add that much value.Model the permission result as
PermissionStatus
to avoid state inconsistencies.[New API] New callback in the
rememberPermissionState
andrememberMultiplePermissionsState
for when theactivityResultLauncher
returns.Changes in samples
Misc
This PR fixes: #549 and #819