Skip to content
Merged
Changes from all commits
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 @@ -47,6 +47,7 @@ import androidx.compose.runtime.mutableFloatStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
Expand All @@ -70,6 +71,7 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.isGranted
import com.google.accompanist.permissions.rememberPermissionState
import com.google.accompanist.permissions.shouldShowRationale
import kotlinx.coroutines.flow.takeWhile
import kotlinx.coroutines.launch

@OptIn(
Expand Down Expand Up @@ -129,6 +131,21 @@ fun CameraPreviewScreen(
}

uiState.surfaceRequest?.let { surface ->
// Workaround for https://issuetracker.google.com/275157240
// When switching to/from tabletop posture, the underlying SurfaceView
// destroys its Surface. Invalidate the SurfaceRequest when this happens
// so CameraX can retrieve the new Surface.
LaunchedEffect(surface) {
val oldIsTableTop = isTableTopPosture(foldingFeature)
snapshotFlow { foldingFeature }
.takeWhile {
val newIsTableTop = isTableTopPosture(it)
val shouldInvalidate = oldIsTableTop != newIsTableTop
if (shouldInvalidate) surface.invalidate()
!shouldInvalidate
}.collect {}
}

CameraPreviewContent(
surfaceRequest = surface,
autofocusUiState = uiState.autofocusUiState,
Expand Down