Created
August 30, 2023 18:28
-
-
Save dleonett/e6101ba3eb2ede234dbb4dc90b5d1bbb to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Column(modifier = Modifier.padding(16.dp)) { | |
var approved by remember { mutableStateOf(false) } | |
var frontCamera by remember { mutableStateOf(false) } | |
val color = if (approved) Color.Green else Color.Red | |
val image = if (frontCamera) Icons.Filled.AccountCircle else Icons.Filled.ShoppingCart | |
Button(modifier = Modifier.width(120.dp), onClick = { approved = !approved }) { | |
Text("Click me!") | |
} | |
Box { | |
// Switch camera | |
IconButton( | |
onClick = { frontCamera = !frontCamera }, | |
modifier = Modifier | |
.align(Alignment.TopEnd) | |
.size(48.dp) | |
.offset((-16).dp, 16.dp) | |
) { | |
Icon( | |
modifier = Modifier.fillMaxSize(), | |
imageVector = Icons.Filled.PlayArrow, | |
tint = Color.White, | |
contentDescription = null | |
) | |
} | |
// Camera preview | |
val largeRadialGradient = object : ShaderBrush() { | |
override fun createShader(size: Size): Shader { | |
val biggerDimension = maxOf(size.height, size.width) | |
return RadialGradientShader( | |
colors = listOf(color, Color.Transparent), | |
center = size.center, | |
radius = biggerDimension / 2f, | |
colorStops = listOf(0f, 0.95f) | |
) | |
} | |
} | |
Box( | |
modifier = Modifier | |
.aspectRatio(1f) | |
.border(32.dp, largeRadialGradient, CircleShape) | |
.padding(32.dp) | |
.border(8.dp, color, CircleShape) | |
.clip(CircleShape) | |
) { | |
Surface( | |
modifier = Modifier.fillMaxSize(), | |
color = Color.Black | |
) { | |
Icon( | |
imageVector = image, | |
contentDescription = null, | |
tint = Color.White | |
) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment