-
Notifications
You must be signed in to change notification settings - Fork 611
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] Preview breaks for composables using permissions: no activity context #1498
Comments
Yeah, this is a problem with |
@manuelvicnt Why do you close the issue if it is a known one? Will it be fixed? If one wants to preview the entire screen it is not possible to split further |
There's nothing we can fix on this library. Preview needs to support Lifecycle APIs like Activities or ViewModel. Without their support we cannot do anything. This would work out of the box when they fix it |
Ah ok. Are you aware of an open issue where I can participate? |
Tried searching in https://issuetracker.google.com/issues and asked internally but got no luck. Maybe you can file a new bug? |
@manuelvicnt Thanks for investigating. I have filed an issue, see https://issuetracker.google.com/issues/267227895 Could you please re-open the issue so other users can find this discussion. The chance might be higher that we get more users to subscribe to this issue at google so google is forced to increase the priority. You are also welcome to give it a +1 |
Issues in Accompanist get tagged as "stale" after 30 days if no one interacts with them. Then, they are automatically closed. Given this is a common problem not only for Permissions but also for Activity and ViewModels in Compose, I'll leave this closed because there isn't much we can do in Accompanist. Thanks for filing the bug! |
@manuelvicnt I understand your reasoning behind this, but in my particular case, and I think in many cases, the workaround will go against the principle of holding the state in the smallest scope as possible. I will need to lift my state unnecessarily just to fix this. |
Maybe such wrappers could help until root cause is solved: @OptIn(ExperimentalPermissionsApi::class)
@Composable
fun rRememberMultiplePermissionsState(
permissions: List<String>,
onPermissionsResult: (Map<String, Boolean>) -> Unit = {},
): MultiplePermissionsState {
val isInspection = LocalInspectionMode.current
return if (isInspection) {
object : MultiplePermissionsState {
override val allPermissionsGranted: Boolean = false
override val permissions: List<PermissionState> = emptyList()
override val revokedPermissions: List<PermissionState> = emptyList()
override val shouldShowRationale: Boolean = false
override fun launchMultiplePermissionRequest() {}
}
} else {
rememberMultiplePermissionsState(permissions, onPermissionsResult)
}
} We have a little bit more complex wrappers and only in debug BuildType, but the idea is to check |
@audkar thanks that works, I can preview my code now. I think you should create a PR. |
@manuelvicnt is the above workaround not something that can be put into accompanist so that preview doesn't break for anyone using this library? |
@Preview composables do not render composables using permissions which makes sense because they are not running in the context of an activity.
Rendering issue:
Stacktrace:
Did I miss something or is this a problem with the findActivity() function?
The text was updated successfully, but these errors were encountered: