Skip to content

Commit bd5bc3e

Browse files
committed
Merge branch 'main' into riggaroo/deps-update
2 parents e3ec76e + f01bade commit bd5bc3e

File tree

1 file changed

+17
-0
lines changed
  • feature/camera/src/main/java/com/android/developers/androidify/camera

1 file changed

+17
-0
lines changed

feature/camera/src/main/java/com/android/developers/androidify/camera/CameraScreen.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import androidx.compose.runtime.mutableFloatStateOf
4747
import androidx.compose.runtime.remember
4848
import androidx.compose.runtime.rememberCoroutineScope
4949
import androidx.compose.runtime.setValue
50+
import androidx.compose.runtime.snapshotFlow
5051
import androidx.compose.ui.Alignment
5152
import androidx.compose.ui.Modifier
5253
import androidx.compose.ui.geometry.Offset
@@ -70,6 +71,7 @@ import com.google.accompanist.permissions.ExperimentalPermissionsApi
7071
import com.google.accompanist.permissions.isGranted
7172
import com.google.accompanist.permissions.rememberPermissionState
7273
import com.google.accompanist.permissions.shouldShowRationale
74+
import kotlinx.coroutines.flow.takeWhile
7375
import kotlinx.coroutines.launch
7476

7577
@OptIn(
@@ -129,6 +131,21 @@ fun CameraPreviewScreen(
129131
}
130132

131133
uiState.surfaceRequest?.let { surface ->
134+
// Workaround for https://issuetracker.google.com/275157240
135+
// When switching to/from tabletop posture, the underlying SurfaceView
136+
// destroys its Surface. Invalidate the SurfaceRequest when this happens
137+
// so CameraX can retrieve the new Surface.
138+
LaunchedEffect(surface) {
139+
val oldIsTableTop = isTableTopPosture(foldingFeature)
140+
snapshotFlow { foldingFeature }
141+
.takeWhile {
142+
val newIsTableTop = isTableTopPosture(it)
143+
val shouldInvalidate = oldIsTableTop != newIsTableTop
144+
if (shouldInvalidate) surface.invalidate()
145+
!shouldInvalidate
146+
}.collect {}
147+
}
148+
132149
CameraPreviewContent(
133150
surfaceRequest = surface,
134151
autofocusUiState = uiState.autofocusUiState,

0 commit comments

Comments
 (0)