diff --git a/shared/src/androidMain/kotlin/com/lagradost/cloudstream4/compose/ComposeFragment.kt b/shared/src/androidMain/kotlin/com/lagradost/cloudstream4/compose/ComposeFragment.kt index 9a91e3e1688..ad2b8400c21 100644 --- a/shared/src/androidMain/kotlin/com/lagradost/cloudstream4/compose/ComposeFragment.kt +++ b/shared/src/androidMain/kotlin/com/lagradost/cloudstream4/compose/ComposeFragment.kt @@ -1,15 +1,21 @@ package com.lagradost.cloudstream4.compose +import android.app.Activity import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.activity.compose.LocalOnBackPressedDispatcherOwner +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.CompositionLocalProvider +import androidx.compose.runtime.SideEffect import androidx.compose.runtime.getValue +import androidx.compose.ui.graphics.luminance +import androidx.compose.ui.graphics.toArgb import androidx.compose.ui.platform.ComposeView import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.ViewCompositionStrategy +import androidx.core.view.WindowCompat import com.lagradost.cloudstream4.rememberAppSettings import com.lagradost.cloudstream4.theme.CloudStreamTheme import com.lagradost.cloudstream4.theme.perfToColor @@ -40,6 +46,22 @@ fun Screen.createComposeView( "No OnBackPressedDispatcherOwner was provided via LocalOnBackPressedDispatcherOwner" }.onBackPressedDispatcher + /** Sync status bar and background color with optional HasStatusBarColor + * or else colors might be messed up. */ + val statusBarColor = (this@createComposeView as? HasStatusBarColor)?.statusBarColor() + if (statusBarColor != null) { + SideEffect { + setBackgroundColor(statusBarColor.toArgb()) + (context as? Activity)?.window?.let { + WindowCompat.getInsetsController( + it, + this@apply + ).isAppearanceLightStatusBars = + statusBarColor.luminance() > 0.5f + } + } + } + CompositionLocalProvider( LocalBackPress provides backDispatcher::onBackPressed, DeviceLayout.LocalLayout provides layoutFlag diff --git a/shared/src/commonMain/kotlin/com/lagradost/cloudstream4/compose/Screen.kt b/shared/src/commonMain/kotlin/com/lagradost/cloudstream4/compose/Screen.kt index a99b623e828..cab41f56dfc 100644 --- a/shared/src/commonMain/kotlin/com/lagradost/cloudstream4/compose/Screen.kt +++ b/shared/src/commonMain/kotlin/com/lagradost/cloudstream4/compose/Screen.kt @@ -1,8 +1,16 @@ package com.lagradost.cloudstream4.compose +import androidx.compose.material3.MaterialTheme import androidx.compose.runtime.Composable +import androidx.compose.ui.graphics.Color // https://github.com/adrielcafe/voyager interface Screen { @Composable fun Content() +} + +/** Use to sync status bar color with top app bar. */ +interface HasStatusBarColor { + @Composable + fun statusBarColor(): Color = MaterialTheme.colorScheme.surface } \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/com/mihon/presentation/settings/SearchableSettings.kt b/shared/src/commonMain/kotlin/com/mihon/presentation/settings/SearchableSettings.kt index c114f0dd048..11d3b1393c3 100644 --- a/shared/src/commonMain/kotlin/com/mihon/presentation/settings/SearchableSettings.kt +++ b/shared/src/commonMain/kotlin/com/mihon/presentation/settings/SearchableSettings.kt @@ -3,10 +3,11 @@ package com.mihon.presentation.settings import androidx.compose.foundation.layout.RowScope import androidx.compose.runtime.Composable import androidx.compose.runtime.ReadOnlyComposable +import com.lagradost.cloudstream4.compose.HasStatusBarColor import com.lagradost.cloudstream4.compose.Screen import com.mihon.presentation.LocalBackPress -interface SearchableSettings : Screen { +interface SearchableSettings : Screen, HasStatusBarColor { @Composable @ReadOnlyComposable fun getTitleRes(): String