/* NewPlayer * * @author Christian Schabesberger * * Copyright (C) NewPipe e.V. 2024 * * NewPlayer is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * NewPlayer is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NewPlayer. If not, see . */ package net.newpipe.newplayer.ui import android.app.Activity import android.content.Context import android.content.ContextWrapper import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect import androidx.compose.ui.platform.LocalContext import androidx.core.view.WindowCompat @Composable fun LockScreenOrientation(orientation: Int) { val context = LocalContext.current DisposableEffect(orientation) { val activity = context.findActivity() ?: return@DisposableEffect onDispose {} val originalOrientation = activity.requestedOrientation activity.requestedOrientation = orientation onDispose { // restore original orientation when view disappears activity.requestedOrientation = originalOrientation } } } fun Context.findActivity(): Activity? = when (this) { is Activity -> this is ContextWrapper -> baseContext.findActivity() else -> null }