Skip to content

Commit f81a4bd

Browse files
authored
Merge pull request #27 from android/remove-camera-preview-constraints
Remove BoxWithConstraints for Camera preview.
2 parents 5ca8da3 + 657bcb8 commit f81a4bd

File tree

1 file changed

+1
-12
lines changed
  • app/src/main/java/com/google/android/samples/socialite/ui/camera

1 file changed

+1
-12
lines changed

app/src/main/java/com/google/android/samples/socialite/ui/camera/ViewFinder.kt

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,14 @@ package com.google.android.samples.socialite.ui.camera
1818

1919
import android.view.Display
2020
import android.view.View
21-
import androidx.camera.core.AspectRatio
2221
import androidx.camera.core.Preview
2322
import androidx.camera.view.PreviewView
2423
import androidx.compose.foundation.background
2524
import androidx.compose.foundation.gestures.detectTapGestures
2625
import androidx.compose.foundation.gestures.rememberTransformableState
2726
import androidx.compose.foundation.gestures.transformable
2827
import androidx.compose.foundation.layout.Box
29-
import androidx.compose.foundation.layout.BoxWithConstraints
3028
import androidx.compose.foundation.layout.fillMaxSize
31-
import androidx.compose.foundation.layout.height
32-
import androidx.compose.foundation.layout.width
3329
import androidx.compose.runtime.Composable
3430
import androidx.compose.runtime.getValue
3531
import androidx.compose.runtime.mutableStateOf
@@ -55,7 +51,7 @@ fun ViewFinder(
5551
onZoomChange(zoomChange)
5652
},
5753
)
58-
BoxWithConstraints(
54+
Box(
5955
Modifier
6056
.background(Color.Black)
6157
.fillMaxSize()
@@ -76,15 +72,8 @@ fun ViewFinder(
7672
},
7773
contentAlignment = Alignment.Center,
7874
) {
79-
val maxAspectRatio: Float = maxWidth / maxHeight
80-
val aspectRatio: Float = CameraViewModel.aspectRatios.getValue(AspectRatio.RATIO_16_9)
81-
val shouldUseMaxWidth = maxAspectRatio <= aspectRatio
82-
val width = if (shouldUseMaxWidth) maxWidth else maxHeight * aspectRatio
83-
val height = if (!shouldUseMaxWidth) maxHeight else maxWidth / aspectRatio
8475
Box(
8576
modifier = Modifier
86-
.width(width)
87-
.height(height)
8877
.transformable(state = transformableState),
8978
) {
9079
CameraPreview(

0 commit comments

Comments
 (0)