Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FC] Use light status bar and navigation bar. #6403

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package com.stripe.android.financialconnections.ui.theme

import android.app.Activity
import android.content.Context
import android.content.ContextWrapper
import android.view.Window
import androidx.compose.foundation.text.selection.LocalTextSelectionColors
import androidx.compose.foundation.text.selection.TextSelectionColors
import androidx.compose.material.Colors
Expand All @@ -9,11 +13,16 @@ import androidx.compose.material.ripple.RippleTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.Immutable
import androidx.compose.runtime.SideEffect
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.text.TextStyle
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogWindowProvider
import androidx.core.view.WindowCompat

private val LightColorPalette = FinancialConnectionsColors(
backgroundSurface = Color.White,
Expand Down Expand Up @@ -150,6 +159,20 @@ internal fun FinancialConnectionsTheme(content: @Composable () -> Unit) {
LocalFinancialConnectionsTypography provides Typography,
LocalFinancialConnectionsColors provides LightColorPalette
) {
val view = LocalView.current
val window = findWindow()
val barColor = FinancialConnectionsTheme.colors.borderDefault
if (!view.isInEditMode) {
SideEffect {
window?.let { window ->
val insets = WindowCompat.getInsetsController(window, view)
window.statusBarColor = barColor.toArgb()
window.navigationBarColor = barColor.toArgb()
insets.isAppearanceLightStatusBars = true
insets.isAppearanceLightNavigationBars = true
}
}
}
MaterialTheme(
colors = debugColors(),
content = {
Expand All @@ -164,9 +187,22 @@ internal fun FinancialConnectionsTheme(content: @Composable () -> Unit) {
}
}

private val LocalFinancialConnectionsTypography = staticCompositionLocalOf<FinancialConnectionsTypography> {
error("no FinancialConnectionsTypography provided")
}
@Composable
private fun findWindow(): Window? =
(LocalView.current.parent as? DialogWindowProvider)?.window
?: LocalView.current.context.findWindow()

private tailrec fun Context.findWindow(): Window? =
when (this) {
is Activity -> window
is ContextWrapper -> baseContext.findWindow()
else -> null
}

private val LocalFinancialConnectionsTypography =
staticCompositionLocalOf<FinancialConnectionsTypography> {
error("no FinancialConnectionsTypography provided")
}

private val LocalFinancialConnectionsColors = staticCompositionLocalOf<FinancialConnectionsColors> {
error("No FinancialConnectionsColors provided")
Expand Down