FullScreenNotification redone with Compose
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
package com.glovoapp.components | |
import androidx.compose.foundation.Image | |
import androidx.compose.foundation.background | |
import androidx.compose.foundation.clickable | |
import androidx.compose.foundation.layout.Arrangement | |
import androidx.compose.foundation.layout.Column | |
import androidx.compose.foundation.layout.Row | |
import androidx.compose.foundation.layout.Spacer | |
import androidx.compose.foundation.layout.defaultMinSize | |
import androidx.compose.foundation.layout.fillMaxHeight | |
import androidx.compose.foundation.layout.fillMaxWidth | |
import androidx.compose.foundation.layout.height | |
import androidx.compose.foundation.layout.padding | |
import androidx.compose.foundation.shape.RoundedCornerShape | |
import androidx.compose.material.Button | |
import androidx.compose.material.ButtonDefaults | |
import androidx.compose.material.Checkbox | |
import androidx.compose.material.CircularProgressIndicator | |
import androidx.compose.material.Icon | |
import androidx.compose.material.MaterialTheme | |
import androidx.compose.material.Surface | |
import androidx.compose.material.Text | |
import androidx.compose.runtime.Composable | |
import androidx.compose.ui.Alignment | |
import androidx.compose.ui.Modifier | |
import androidx.compose.ui.res.painterResource | |
import androidx.compose.ui.text.style.TextAlign | |
import androidx.compose.ui.unit.dp | |
import com.glovoapp.theme.GlovoTheme | |
import com.glovoapp.theme.Icons | |
import com.glovoapp.theme.Palette | |
import com.glovoapp.theme.Spacing | |
import com.glovoapp.theme.e2 | |
import com.glovoapp.theme.p1 | |
enum class IllustrationSize { | |
COMPACT, | |
EXTENDED | |
} | |
data class FullScreenNotificationButton(val text: String = "", val actionCallback: () -> Unit) | |
@Composable | |
fun FullScreenNotification( | |
header: String, | |
message: String, | |
chip: String? = null, | |
illustration: Int, | |
illustrationSize: IllustrationSize = IllustrationSize.EXTENDED, | |
primaryButton: FullScreenNotificationButton? = null, | |
secondaryButton: FullScreenNotificationButton? = null, | |
closeButton: FullScreenNotificationButton? = null, | |
checkBox: FullScreenNotificationButton? = null, | |
isLoading: Boolean = false | |
) { | |
GlovoTheme { | |
Surface { | |
Column( | |
modifier = Modifier | |
.fillMaxWidth() | |
.fillMaxHeight(), | |
horizontalAlignment = Alignment.End, | |
) { | |
closeButton?.let { | |
Icon( | |
modifier = Modifier | |
.padding(top = Spacing.S, end = Spacing.S) | |
.clickable { closeButton.actionCallback() }, | |
painter = painterResource(Icons.Close), | |
contentDescription = "", | |
) | |
} | |
Column( | |
modifier = Modifier.weight(1f), | |
verticalArrangement = Arrangement.Center, | |
horizontalAlignment = Alignment.CenterHorizontally, | |
) { | |
if (isLoading) { | |
CircularProgressIndicator() | |
} else { | |
Content(illustration, illustrationSize, header, message, chip, checkBox) | |
} | |
} | |
if (!isLoading) { | |
secondaryButton?.let { NotificationButton(it) } | |
primaryButton?.let { NotificationButton(it) } | |
} | |
} | |
} | |
} | |
} | |
@Composable | |
private fun Content( | |
illustration: Int, | |
illustrationSize: IllustrationSize, | |
header: String, | |
message: String, | |
chip: String?, | |
checkBox: FullScreenNotificationButton? | |
) { | |
Image( | |
modifier = Modifier | |
.fillMaxWidth() | |
.height(if (illustrationSize == IllustrationSize.EXTENDED) 200.dp else 56.dp), | |
painter = painterResource(illustration), | |
contentDescription = "", | |
) | |
Text( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(start = Spacing.XL, end = Spacing.XL), | |
style = MaterialTheme.typography.h2, | |
textAlign = TextAlign.Center, | |
text = header, | |
) | |
Text( | |
modifier = Modifier | |
.fillMaxWidth() | |
.padding(start = Spacing.XL, end = Spacing.XL, top = Spacing.S), | |
style = MaterialTheme.typography.p1, | |
textAlign = TextAlign.Center, | |
text = message, | |
) | |
chip?.let { | |
Spacer(modifier = Modifier.padding(top = Spacing.S)) | |
Surface(shape = RoundedCornerShape(10.dp)) { | |
Text( | |
modifier = Modifier | |
.background(Palette.Sunstone) | |
.padding(horizontal = Spacing.XXS), | |
style = MaterialTheme.typography.e2, | |
text = it, | |
) | |
} | |
} | |
checkBox?.let { | |
Spacer(modifier = Modifier.padding(top = Spacing.S)) | |
Row(verticalAlignment = Alignment.CenterVertically) { | |
Checkbox( | |
checked = false, | |
onCheckedChange = { checkBox.actionCallback() }, | |
) | |
Text( | |
modifier = Modifier.padding(start = Spacing.XXS), | |
style = MaterialTheme.typography.p1, | |
text = checkBox.text, | |
) | |
} | |
} | |
} | |
@Composable | |
private fun NotificationButton(primaryButton: FullScreenNotificationButton) { | |
Button( | |
modifier = Modifier | |
.fillMaxWidth() | |
.defaultMinSize(54.dp) | |
.padding(top = Spacing.XXS, bottom = Spacing.XXS, start = Spacing.S, end = Spacing.S), | |
shape = RoundedCornerShape(100.dp), | |
colors = ButtonDefaults.buttonColors(backgroundColor = Palette.Matcha), | |
onClick = primaryButton.actionCallback, | |
) { | |
Text( | |
text = primaryButton.text, | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment