Skip to content

Commit

Permalink
Merge pull request DroidKaigi#790 from mannodermaus/feature/inverted-…
Browse files Browse the repository at this point in the history
…system-bar-content-on-profile-card

Invert the system bar appearance on the ProfileCardScreen, matching its light background
  • Loading branch information
takahirom authored Aug 25, 2024
2 parents d2aa10d + 049697f commit 961c75c
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.droidkaigi.confsched.profilecard.component

import android.app.Activity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat

@Composable
internal actual fun InvertSystemBarAppearance() {
val activity = LocalContext.current as Activity
val insetsController = WindowCompat.getInsetsController(activity.window, activity.window.decorView)

val originalIsAppearanceLight = remember { insetsController.isAppearanceLightStatusBars }

DisposableEffect(Unit) {
insetsController.isAppearanceLightStatusBars = !originalIsAppearanceLight

onDispose {
insetsController.isAppearanceLightStatusBars = originalIsAppearanceLight
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import io.github.droidkaigi.confsched.model.ProfileCard
import io.github.droidkaigi.confsched.model.ProfileCardType
import io.github.droidkaigi.confsched.profilecard.component.CapturableCard
import io.github.droidkaigi.confsched.profilecard.component.FlipCard
import io.github.droidkaigi.confsched.profilecard.component.InvertSystemBarAppearance
import io.github.droidkaigi.confsched.profilecard.component.PhotoPickerButton
import io.ktor.util.decodeBase64Bytes
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -712,6 +713,10 @@ internal fun CardScreen(
val graphicsLayer = rememberGraphicsLayer()
var isShareReady by remember { mutableStateOf(false) }

// The background of this screen is light, contrasting any other screen in the app.
// Invert the content color of system bars to accommodate this unique property.
InvertSystemBarAppearance()

ProvideProfileCardTheme(uiState.cardType.toString()) {
Box {
// Not for display, for sharing
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package io.github.droidkaigi.confsched.profilecard.component

import androidx.compose.runtime.Composable

@Composable
internal expect fun InvertSystemBarAppearance()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.github.droidkaigi.confsched.profilecard.component

import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.remember
import platform.UIKit.UIApplication
import platform.UIKit.UIUserInterfaceStyle.UIUserInterfaceStyleDark
import platform.UIKit.UIUserInterfaceStyle.UIUserInterfaceStyleLight
import platform.UIKit.UIWindow
import platform.UIKit.UIWindowScene

@Composable
internal actual fun InvertSystemBarAppearance() {
val application = UIApplication.sharedApplication
val scene = application.connectedScenes.firstOrNull() as? UIWindowScene
val window = scene?.windows?.firstOrNull() as? UIWindow ?: return

val originalUserInterfaceStyle = remember { window.overrideUserInterfaceStyle }

DisposableEffect(Unit) {
window.overrideUserInterfaceStyle = if (originalUserInterfaceStyle == UIUserInterfaceStyleDark) {
UIUserInterfaceStyleLight
} else {
UIUserInterfaceStyleDark
}

onDispose { window.overrideUserInterfaceStyle = originalUserInterfaceStyle }
}
}

0 comments on commit 961c75c

Please sign in to comment.