21 lines
657 B
Kotlin
21 lines
657 B
Kotlin
package com.example.livingai.utils
|
|
|
|
import android.app.Activity
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.DisposableEffect
|
|
import androidx.compose.ui.platform.LocalContext
|
|
|
|
@Composable
|
|
fun SetScreenOrientation(orientation: Int) {
|
|
val context = LocalContext.current
|
|
DisposableEffect(Unit) {
|
|
val activity = context as Activity
|
|
val originalOrientation = activity.requestedOrientation
|
|
activity.requestedOrientation = orientation
|
|
onDispose {
|
|
// restore original orientation when view disappears
|
|
activity.requestedOrientation = originalOrientation
|
|
}
|
|
}
|
|
}
|