Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.wrapContentSize
import androidx.compose.foundation.shape.CircleShape
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.automirrored.filled.ArrowBack
Expand Down Expand Up @@ -63,6 +64,7 @@ import androidx.compose.ui.unit.round
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.compose.LocalLifecycleOwner
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import androidx.lifecycle.viewmodel.compose.viewModel
import coil.compose.rememberAsyncImagePainter
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.PermissionState
Expand Down Expand Up @@ -92,14 +94,14 @@ fun CameraXBasic(modifier: Modifier = Modifier) {
}
}

Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = modifier.fillMaxSize()) {
ContentWithPermissionHandling(
cameraPermissionState = cameraPermissionState,
showCapturedImage = showCapturedImage,
onShowCapturedImageChange = { showCapturedImage = it },
viewModel = viewModel,
imageCaptureCallbackExecutor = imageCaptureCallbackExecutor,
modifier = modifier,
modifier = Modifier,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just omit this

)
}
}
Expand Down Expand Up @@ -131,7 +133,7 @@ private fun ContentWithPermissionHandling(
when (cameraPermissionState.status) {
is PermissionStatus.Granted -> {
if (showCapturedImage != null) {
CapturedImageView(uri = showCapturedImage) {
CapturedImageView(uri = showCapturedImage, modifier = modifier) {
onShowCapturedImageChange(null)
}
} else {
Expand All @@ -152,8 +154,9 @@ private fun ContentWithPermissionHandling(
}

is PermissionStatus.Denied -> CameraPermissionDeniedView(
cameraPermissionState.status,
cameraPermissionState,
status = cameraPermissionState.status,
cameraPermissionState = cameraPermissionState,
modifier = modifier
)
}
}
Expand All @@ -171,9 +174,10 @@ private fun ContentWithPermissionHandling(
private fun CameraPermissionDeniedView(
status: PermissionStatus,
cameraPermissionState: PermissionState,
modifier: Modifier = Modifier
) {
Column(
modifier = Modifier
modifier = modifier
.fillMaxSize()
.padding(16.dp),
horizontalAlignment = Alignment.CenterHorizontally,
Expand Down Expand Up @@ -232,7 +236,7 @@ private fun CameraPreviewContent(

surfaceRequest?.let { request ->
val coordinateTransformer = remember { MutableCoordinateTransformer() }
Box(modifier = Modifier.fillMaxSize()) {
Box(modifier = modifier.fillMaxSize()) {
CameraXViewfinder(
surfaceRequest = request,
coordinateTransformer = coordinateTransformer,
Expand Down Expand Up @@ -263,14 +267,13 @@ private fun CameraPreviewContent(
.size(48.dp),
)
}
Column(
modifier = Modifier

Button(
onClick = onTakePhotoClick,
modifier
.align(Alignment.BottomCenter)
.padding(16.dp),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The Button's modifier is currently chaining off the modifier parameter of the CameraPreviewContent composable (modifier.align(...).padding(...)).

While this might work by coincidence in the current setup (where CameraPreviewContent's modifier parameter effectively resolves to Modifier), it's conceptually incorrect. The modifier parameter of CameraPreviewContent is intended for styling the CameraPreviewContent component as a whole (e.g., its root Box), not for dictating the specific layout modifiers of its internal children like this Button.

If CameraPreviewContent were ever called with a non-default modifier (e.g., Modifier.background(Color.Red)), that modifier would unintentionally be applied to this Button before the .align and .padding modifiers.

The Button's layout modifiers (.align and .padding) should be self-contained, starting from a fresh Modifier instance to ensure proper encapsulation and prevent unexpected styling side effects.

Could we change this to start with Modifier for the button's specific layout needs?

Suggested change
modifier
.align(Alignment.BottomCenter)
.padding(16.dp),
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(16.dp),

horizontalAlignment = Alignment.CenterHorizontally,
) {
Button(onClick = onTakePhotoClick) { Text("Take Photo") }
}
) { Text("Take Photo") }
}
}
}
Expand All @@ -283,9 +286,9 @@ private fun CameraPreviewContent(
* (e.g., clicks the back button).
*/
@Composable
fun CapturedImageView(uri: Uri, onDismiss: () -> Unit) {
fun CapturedImageView(uri: Uri, modifier: Modifier = Modifier, onDismiss: () -> Unit = {}) {
Box(
modifier = Modifier.fillMaxSize(),
modifier = modifier.fillMaxSize(),
) {
Image(
painter = rememberAsyncImagePainter(uri),
Expand Down
Loading