Keep screen on during recording.

This commit is contained in:
Greyson Parrelli
2026-09-02 16:11:27 -03:00
committed by Alex Hart
parent 6b13b69008
commit 68dcb851eb
2 changed files with 11 additions and 6 deletions
@@ -5,22 +5,24 @@
package org.signal.core.ui.compose
import android.app.Activity
import android.view.WindowManager
import androidx.activity.compose.LocalActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext
/**
* Keeps the screen on while this composable is in the composition by toggling
* [WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON] on the host activity window.
*
* @param enabled When false, the flag is left alone, letting callers scope the effect to a piece of state without
* having to conditionally compose it.
*/
@Composable
fun KeepScreenOnEffect() {
val context = LocalContext.current
fun KeepScreenOnEffect(enabled: Boolean = true) {
val activity = LocalActivity.current
DisposableEffect(Unit) {
val window = (context as? Activity)?.window
DisposableEffect(activity, enabled) {
val window = if (enabled) activity?.window else null
window?.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
onDispose {
@@ -43,6 +43,7 @@ import androidx.lifecycle.compose.LocalLifecycleOwner
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.signal.core.ui.compose.AllNightPreviews
import org.signal.core.ui.compose.KeepScreenOnEffect
import org.signal.core.ui.compose.Previews
import kotlin.time.Duration.Companion.milliseconds
import androidx.camera.core.Preview as CameraPreview
@@ -92,6 +93,8 @@ fun CameraScreen(
var surfaceRequest by remember { mutableStateOf<SurfaceRequest?>(null) }
KeepScreenOnEffect(enabled = state.isRecording)
// Bind once; a screen rotation rebuilds just the preview (below), not the whole camera.
LaunchedEffect(lifecycleOwner, state.lensFacing) {
val cameraProvider = ProcessCameraProvider.getInstance(context).get()