Skip to content
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: If a permission has not been determined shouldShowRationale is now false, if it has been denied shouldShowRationale is now true. #244

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vanniktech
Copy link

Refs #229

Isn't this how it should be done @MohamedRejeb ?

I'd like to test this in my project and therefore publish Calf to my local maven repository but this does not work:

./gradlew publishToMavenLocal fails with: > Cannot perform signing task ':calf-core:signDesktopPublication' because it has no configured signatory, do you have a solution for this?


My use case is a map and a locate me button. In the beginning, nothing should happen. If the user clicks the locate me button, they should see the permission request. If they accept all fine. If they deny also fine, nothing should be shown. If they then however click again and the system does no longer display the dialog (because it has been denied), I want to show a dialog from which you can go to the settings.

This behavior that I'm describing works already as is on Android. This is my code:

val permissionState = rememberPermissionState(Permission.FineLocation)
var hasRequestedLocation by rememberSaveable { mutableStateOf(value = false) }


LaunchedEffect(permissionState.status, hasRequestedLocation) {
  if (permissionState.status is PermissionStatus.Granted && hasRequestedLocation) {
    requestCurrentLocation()
  }
}

Button(
  onClick = {
    when (permissionState.status) {
      PermissionStatus.Granted -> requestCurrentLocation()
      is PermissionStatus.Denied -> when (permissionStatus.shouldShowRationale) {
        true -> permissionRationalDialog = true
        false -> {
          hasRequestedLocation = true
          permissionState.launchPermissionRequest()
        }
      }
    }
  },
)

…ale is now false, if it has been denied shouldShowRationale is now true.
@vanniktech
Copy link
Author

I'm convinced that the behavior between Android & iOS isn't the same and this PR would fix it (still need to test this though), in the meantime I rolled my own wrapper that uses the Calf API and checks for the target platform. Weird, but at least it is working.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant