Skip to content

Instantly share code, notes, and snippets.

@arulwastaken
Last active July 18, 2025 11:03
Show Gist options
  • Save arulwastaken/396755faae61f619fa6cdb0e6f3dd69e to your computer and use it in GitHub Desktop.
Save arulwastaken/396755faae61f619fa6cdb0e6f3dd69e to your computer and use it in GitHub Desktop.
Common ImageCaptureView Includes with custom camera design
@Preview
@Composable
fun ImageCaptureView(onImageCaptured: (Path?) -> Unit, onClose: () -> Unit = {}) {
val scope = rememberCoroutineScope()
val callback = remember {
object : CameraCallback() {
override fun onCaptureImage(image: Path?, error: String?) {
showToast("Image Captured $image")
onImageCaptured(image)
}
}
}
fun takePicture() = scope.launch {
callback.sendEvent(CameraEvent.CaptureImage)
}
fun switchCamera() = scope.launch {
callback.sendEvent(CameraEvent.SwitchCamera)
}
Box(modifier = Modifier.fillMaxSize()) {
// CameraView from each platform using expect/actual functionality
CameraView(callback)
// Custom Capture View Design
Row(
modifier = Modifier.align(Alignment.BottomCenter).fillMaxWidth()
.height(120.dp)
.background(color = Color.Black.copy(alpha = 0.5f))
.padding(16.dp),
horizontalArrangement = Arrangement.SpaceBetween,
verticalAlignment = Alignment.CenterVertically
) {
IconButton(
modifier = Modifier
.size(60.dp),
onClick = onClose, colors = IconButtonDefaults.iconButtonColors(
containerColor = Color.White.copy(alpha = 0.2f),
contentColor = MaterialTheme.colorScheme.onPrimary
)
) {
Icon(
imageVector = vectorResource(Res.drawable.close),
contentDescription = "Settings",
modifier = Modifier.size(48.dp),
tint = Color.Red
)
}
IconButton(
onClick = ::takePicture,
modifier = Modifier
.size(80.dp),
colors = IconButtonDefaults.iconButtonColors(
containerColor = MaterialTheme.colorScheme.primary.copy(alpha = 0.5f),
contentColor = MaterialTheme.colorScheme.onPrimary
)
) {
Icon(
imageVector = vectorResource(Res.drawable.ic_camera_capture),
contentDescription = "Take photo",
modifier = Modifier.size(48.dp)
)
}
IconButton(
modifier = Modifier
.size(60.dp),
onClick = ::switchCamera, colors = IconButtonDefaults.iconButtonColors(
containerColor = Color.White.copy(alpha = 0.2f),
contentColor = Color.Black
)
) {
Icon(
imageVector = vectorResource(Res.drawable.ic_camera_rotate),
contentDescription = "Settings",
modifier = Modifier.size(48.dp),
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment