Skip to content

Commit 489d405

Browse files
committed
Fix size of camera preview on Android 8.0
1 parent 868553a commit 489d405

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

app/src/main/java/org/fairscan/app/view/CameraScreen.kt

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,12 @@ import androidx.compose.foundation.interaction.MutableInteractionSource
3333
import androidx.compose.foundation.layout.Arrangement
3434
import androidx.compose.foundation.layout.Box
3535
import androidx.compose.foundation.layout.Row
36+
import androidx.compose.foundation.layout.aspectRatio
3637
import androidx.compose.foundation.layout.fillMaxHeight
3738
import androidx.compose.foundation.layout.fillMaxSize
3839
import androidx.compose.foundation.layout.fillMaxWidth
39-
import androidx.compose.foundation.layout.height
4040
import androidx.compose.foundation.layout.padding
4141
import androidx.compose.foundation.layout.size
42-
import androidx.compose.foundation.layout.width
4342
import androidx.compose.foundation.lazy.LazyListState
4443
import androidx.compose.foundation.lazy.rememberLazyListState
4544
import androidx.compose.foundation.shape.CircleShape
@@ -347,12 +346,6 @@ private fun CameraPreviewWithOverlay(
347346
modifier: Modifier,
348347
) {
349348
val captureState = cameraUiState.captureState
350-
var width = LocalConfiguration.current.screenWidthDp
351-
var height = width * 4 / 3
352-
if (cameraUiState.isLandscape) {
353-
height = LocalConfiguration.current.screenHeightDp
354-
width = height * 4 / 3
355-
}
356349

357350
var showShutter by remember { mutableStateOf(false) }
358351
LaunchedEffect(captureState.frozenImage) {
@@ -364,9 +357,11 @@ private fun CameraPreviewWithOverlay(
364357
}
365358

366359
Box(
367-
modifier = modifier
368-
.width(width.dp)
369-
.height(height.dp)
360+
modifier = if (cameraUiState.isLandscape) {
361+
modifier.fillMaxHeight().aspectRatio(4f / 3f)
362+
} else {
363+
modifier.fillMaxWidth().aspectRatio(3f / 4f)
364+
}
370365
) {
371366
cameraPreview()
372367
AnalysisOverlay(cameraUiState.liveAnalysisState, cameraUiState.isDebugMode)

0 commit comments

Comments
 (0)