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

[ktx] onNeverAskAgain not called #767

Open
SammyOdenhoven opened this issue Mar 15, 2022 · 4 comments · May be fixed by #772
Open

[ktx] onNeverAskAgain not called #767

SammyOdenhoven opened this issue Mar 15, 2022 · 4 comments · May be fixed by #772

Comments

@SammyOdenhoven
Copy link

SammyOdenhoven commented Mar 15, 2022

Overview

onNeverAskAgain callback is not called when "Don't ask again" is selected.

Expected

onNeverAskAgain callback is called, so I can show the appropriate UI.

Actual

onNeverAskAgain callback is not called.

Environment

  • Running ktx-sample on API 29 and API 30, using ktx v1.1.3

Investigation

After debugging it, I can see that onNeverAskAgain: WeakReference<Fun>? is null in PermissionRequestViewModel.invoke().
After reading through the closed issues, I came across #735. Wondering if the weakreference could be the issue? If I downgrade the ktx library to 1.0.4, onNeverAskAgain is successfully called.

Reproducible steps

screen-20220315-112550.mp4
@OKatrych
Copy link

OKatrych commented Apr 21, 2022

Agree, I have the same issue WeakReference is null. It is null for all three arguments:

requiresPermission: WeakReference<Fun>,
onPermissionDenied: WeakReference<Fun>?,
onNeverAskAgain: WeakReference<Fun>?

@OKatrych
Copy link

It can be reproduced on Android < 10. For example, in my case, I have used an Android 7.1.1 build on Emulator.

@dpatel-mercari
Copy link

I can also reproduce it on Android > 10. The references are null and so going back and forth the callbacks are not invoked.

@francescopedronomnys
Copy link

I'm able to reproduce the problem using ktx:1.1.4, I've found a workaround keeping a reference to the onNeverAskAgain lambda from the Fragment that is constructing the permission request using constructPermissionsRequest; see sample code:

class MyFragment : Fragment() {
    private val locationPermissionNeverAskAgain : () -> Unit = { /* never ask again code here */ }
    private val locationPermissionRequest = constructPermissionsRequest(
        /* other settings here */
        onNeverAskAgain = locationPermissionNeverAskAgain
    ) { /* permission granted code here */ }
}

Probably library should declare onNeverAskAgain as a val on PermissionsRequesterImpl.

@francescopedronomnys francescopedronomnys linked a pull request Jun 16, 2022 that will close this issue
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 a pull request may close this issue.

4 participants