Created
May 23, 2023 17:40
-
-
Save oussama-dz/c4a80b2005a54aa3ff2c886f81489cd2 to your computer and use it in GitHub Desktop.
An alert dialog composable to be shown when the user refuses to grant a permission.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun PermissionAlertDialog( | |
neededPermission: NeededPermission, | |
isPermissionDeclined: Boolean, | |
onDismiss: () -> Unit, | |
onOkClick: () -> Unit, | |
onGoToAppSettingsClick: () -> Unit, | |
) { | |
AlertDialog( | |
onDismissRequest = onDismiss, | |
buttons = { | |
Column( | |
modifier = Modifier | |
.fillMaxWidth() | |
) { | |
Divider(color = Color.LightGray) | |
Text( | |
text = if (isPermissionDeclined) "Go to app setting" else "OK", | |
textAlign = TextAlign.Center, | |
modifier = Modifier | |
.fillMaxWidth() | |
.clickable { | |
if (isPermissionDeclined) | |
onGoToAppSettingsClick() | |
else | |
onOkClick() | |
} | |
.padding(16.dp) | |
) | |
} | |
}, | |
title = { | |
Text( | |
text = neededPermission.title, | |
fontSize = 18.sp, | |
fontWeight = FontWeight.Bold, | |
) | |
}, | |
text = { | |
Text( | |
text = neededPermission.permissionTextProvider(isPermissionDeclined), | |
) | |
}, | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment