Skip to content

Commit

Permalink
Merge pull request #27 from android/remove-camera-preview-constraints
Browse files Browse the repository at this point in the history
Remove BoxWithConstraints for Camera preview.
  • Loading branch information
donovanfm authored Mar 12, 2024
2 parents 5ca8da3 + 657bcb8 commit f81a4bd
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,14 @@ package com.google.android.samples.socialite.ui.camera

import android.view.Display
import android.view.View
import androidx.camera.core.AspectRatio
import androidx.camera.core.Preview
import androidx.camera.view.PreviewView
import androidx.compose.foundation.background
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.gestures.rememberTransformableState
import androidx.compose.foundation.gestures.transformable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -55,7 +51,7 @@ fun ViewFinder(
onZoomChange(zoomChange)
},
)
BoxWithConstraints(
Box(
Modifier
.background(Color.Black)
.fillMaxSize()
Expand All @@ -76,15 +72,8 @@ fun ViewFinder(
},
contentAlignment = Alignment.Center,
) {
val maxAspectRatio: Float = maxWidth / maxHeight
val aspectRatio: Float = CameraViewModel.aspectRatios.getValue(AspectRatio.RATIO_16_9)
val shouldUseMaxWidth = maxAspectRatio <= aspectRatio
val width = if (shouldUseMaxWidth) maxWidth else maxHeight * aspectRatio
val height = if (!shouldUseMaxWidth) maxHeight else maxWidth / aspectRatio
Box(
modifier = Modifier
.width(width)
.height(height)
.transformable(state = transformableState),
) {
CameraPreview(
Expand Down

0 comments on commit f81a4bd

Please sign in to comment.