@Composable
fun GoogleButton(
modifier: Modifier = Modifier,
text: String = "Sign Up with Google",
loadingText: String = "Creating Account...",
icon: Int = R.drawable.ic_google_logo,
shape: Shape = MaterialTheme.shapes.medium,
borderColor: Color = Color.LightGray,
backgroundColor: Color = MaterialTheme.colorScheme.surface,
progressIndicatorColor: Color = MaterialTheme.colorScheme.primary,
onClicked: () -> Unit,
) {
var clicked by remember { mutableStateOf(false) }
Surface(
modifier = modifier
.clip(MaterialTheme.shapes.medium)
.clickable {
clicked = !clicked
onClicked()
},
shape = shape,
border = BorderStroke(width = 1.dp, color = borderColor),
color = backgroundColor
) {
Row(
modifier = Modifier
.padding(
start = 12.dp,
end = 16.dp,
top = 12.dp,
bottom = 12.dp
)
.animateContentSize(
animationSpec = tween(
durationMillis = 300,
easing = LinearOutSlowInEasing
)
),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.Center
) {
Icon(
painter = painterResource(id = icon),
contentDescription = "Google Button",
tint = Color.Unspecified
)
Spacer(modifier = Modifier.width(8.dp))
Text(text = if (clicked) loadingText else text)
if (clicked) {
Spacer(modifier = Modifier.width(16.dp))
CircularProgressIndicator(
modifier = Modifier
.height(16.dp)
.width(16.dp),
strokeWidth = 2.dp,
color = progressIndicatorColor
)
}
}
}
}
0 Comments