Skip to content

Commit

Permalink
Merge pull request #28 from element-hq/misc/remove-accompanist-systemui
Browse files Browse the repository at this point in the history
Remove Accompanist SystemUiController library
  • Loading branch information
jmartinesp authored Apr 5, 2024
2 parents 5d7c45e + db0d62a commit 7af76e3
Show file tree
Hide file tree
Showing 16 changed files with 215 additions and 56 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions compound/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,19 @@ android {
}

dependencies {
implementation(libs.androidx.activity.activity)
implementation(libs.androidx.compose.material3)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.ui.tooling.preview.android)
implementation(libs.kotlinx.collections)

// Showkase
implementation(libs.showkase)
ksp(libs.showkase.processor)
kspTest(libs.showkase.processor)

implementation(libs.accompanist.systemui)

// Tests
testImplementation(libs.test.junit)

testImplementation(libs.androidx.activity.activity)
testImplementation(libs.androidx.compose.ui.test.junit)
testImplementation(libs.test.robolectric)
testImplementation(libs.test.roborazzi)
Expand Down
4 changes: 2 additions & 2 deletions compound/screenshots/Compound Icons - Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions compound/screenshots/Compound Icons - Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions compound/screenshots/Compound Vector Icons - Dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions compound/screenshots/Compound Vector Icons - Light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
package io.element.android.compound.theme

import android.os.Build
import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.ColorScheme
import androidx.compose.material3.LocalContentColor
Expand All @@ -31,9 +34,8 @@ import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.runtime.remember
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext
import com.google.accompanist.systemuicontroller.SystemUiController
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import io.element.android.compound.tokens.compoundColorsDark
import io.element.android.compound.tokens.compoundColorsLight
import io.element.android.compound.tokens.compoundTypography
Expand Down Expand Up @@ -112,7 +114,6 @@ fun ElementTheme(
typography: Typography = compoundTypography,
content: @Composable () -> Unit,
) {
val systemUiController = rememberSystemUiController()
val currentCompoundColor = remember(darkTheme) {
compoundColors.copy()
}.apply { updateColorsFrom(compoundColors) }
Expand All @@ -127,7 +128,7 @@ fun ElementTheme(

val statusBarColorScheme = if (dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val context = LocalContext.current
if (darkTheme) {
if (lightStatusBar) {
dynamicDarkColorScheme(context)
} else {
dynamicLightColorScheme(context)
Expand All @@ -137,10 +138,21 @@ fun ElementTheme(
}

if (applySystemBarsUpdate) {
val activity = LocalContext.current as? ComponentActivity
LaunchedEffect(statusBarColorScheme, darkTheme, lightStatusBar) {
systemUiController.applyTheme(
colorScheme = statusBarColorScheme,
darkTheme = darkTheme && !lightStatusBar
activity?.enableEdgeToEdge(
// For Status bar use the background color of the app
statusBarStyle = SystemBarStyle.auto(
lightScrim = statusBarColorScheme.background.toArgb(),
darkScrim = statusBarColorScheme.background.toArgb(),
detectDarkMode = { !lightStatusBar }
),
// For Navigation bar use a transparent color so the content can be seen through it
navigationBarStyle = if (darkTheme) {
SystemBarStyle.dark(Color.Transparent.toArgb())
} else {
SystemBarStyle.light(Color.Transparent.toArgb(), Color.Transparent.toArgb())
}
)
}
}
Expand All @@ -155,17 +167,3 @@ fun ElementTheme(
)
}
}

internal fun SystemUiController.applyTheme(
colorScheme: ColorScheme,
darkTheme: Boolean,
) {
val useDarkIcons = !darkTheme
setStatusBarColor(
color = colorScheme.background
)
setSystemBarsColor(
color = Color.Transparent,
darkIcons = useDarkIcons
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,15 @@

package io.element.android.compound.theme

import androidx.activity.ComponentActivity
import androidx.activity.SystemBarStyle
import androidx.activity.enableEdgeToEdge
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.platform.LocalContext

/**
* Can be used to force a composable in dark theme.
Expand All @@ -30,12 +35,25 @@ fun ForcedDarkElementTheme(
lightStatusBar: Boolean = false,
content: @Composable () -> Unit,
) {
val systemUiController = rememberSystemUiController()
val colorScheme = MaterialTheme.colorScheme
val wasDarkTheme = !ElementTheme.colors.isLight
val activity = LocalContext.current as? ComponentActivity
DisposableEffect(Unit) {
onDispose {
systemUiController.applyTheme(colorScheme, wasDarkTheme)
activity?.enableEdgeToEdge(
statusBarStyle = SystemBarStyle.auto(
lightScrim = colorScheme.background.toArgb(),
darkScrim = colorScheme.background.toArgb(),
),
navigationBarStyle = if (wasDarkTheme) {
SystemBarStyle.dark(Color.Transparent.toArgb())
} else {
SystemBarStyle.light(
scrim = Color.Transparent.toArgb(),
darkScrim = Color.Transparent.toArgb()
)
}
)
}
}
ElementTheme(darkTheme = true, lightStatusBar = lightStatusBar, content = content)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,21 @@ internal val compoundColorsLight = SemanticColors(
iconSuccessPrimary = LightColorTokens.colorGreen900,
iconInfoPrimary = LightColorTokens.colorBlue900,
iconOnSolidPrimary = LightColorTokens.colorThemeBg,
bgAccentRest = LightColorTokens.colorGreen900,
bgAccentHovered = LightColorTokens.colorGreen1000,
bgAccentPressed = LightColorTokens.colorGreen1100,
bgDecorative1 = LightColorTokens.colorLime300,
bgDecorative2 = LightColorTokens.colorCyan300,
bgDecorative3 = LightColorTokens.colorFuchsia300,
bgDecorative4 = LightColorTokens.colorPurple300,
bgDecorative5 = LightColorTokens.colorPink300,
bgDecorative6 = LightColorTokens.colorOrange300,
textDecorative1 = LightColorTokens.colorLime1100,
textDecorative2 = LightColorTokens.colorCyan1100,
textDecorative3 = LightColorTokens.colorFuchsia1100,
textDecorative4 = LightColorTokens.colorPurple1100,
textDecorative5 = LightColorTokens.colorPink1100,
textDecorative6 = LightColorTokens.colorOrange1100,
isLight = true,
)

Expand Down Expand Up @@ -133,5 +148,20 @@ internal val compoundColorsDark = SemanticColors(
iconSuccessPrimary = DarkColorTokens.colorGreen900,
iconInfoPrimary = DarkColorTokens.colorBlue900,
iconOnSolidPrimary = DarkColorTokens.colorThemeBg,
bgAccentRest = LightColorTokens.colorGreen900,
bgAccentHovered = LightColorTokens.colorGreen1000,
bgAccentPressed = LightColorTokens.colorGreen1100,
bgDecorative1 = LightColorTokens.colorLime300,
bgDecorative2 = LightColorTokens.colorCyan300,
bgDecorative3 = LightColorTokens.colorFuchsia300,
bgDecorative4 = LightColorTokens.colorPurple300,
bgDecorative5 = LightColorTokens.colorPink300,
bgDecorative6 = LightColorTokens.colorOrange300,
textDecorative1 = LightColorTokens.colorLime1100,
textDecorative2 = LightColorTokens.colorCyan1100,
textDecorative3 = LightColorTokens.colorFuchsia1100,
textDecorative4 = LightColorTokens.colorPurple1100,
textDecorative5 = LightColorTokens.colorPink1100,
textDecorative6 = LightColorTokens.colorOrange1100,
isLight = false,
)
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,9 @@ object CompoundIcons {
@Composable fun TakePhoto(): ImageVector {
return ImageVector.vectorResource(R.drawable.ic_compound_take_photo)
}
@Composable fun TakePhotoSolid(): ImageVector {
return ImageVector.vectorResource(R.drawable.ic_compound_take_photo_solid)
}
@Composable fun TextFormatting(): ImageVector {
return ImageVector.vectorResource(R.drawable.ic_compound_text_formatting)
}
Expand Down Expand Up @@ -521,7 +524,7 @@ object CompoundIcons {
return ImageVector.vectorResource(R.drawable.ic_compound_web_browser)
}

val all @Composable get() = persistentListOf(
val all @Composable get() = persistentListOf<ImageVector>(
Admin(),
ArrowDown(),
ArrowLeft(),
Expand Down Expand Up @@ -658,6 +661,7 @@ object CompoundIcons {
Strikethrough(),
SwitchCameraSolid(),
TakePhoto(),
TakePhotoSolid(),
TextFormatting(),
Threads(),
ThreadsSolid(),
Expand Down Expand Up @@ -826,6 +830,7 @@ object CompoundIcons {
R.drawable.ic_compound_strikethrough,
R.drawable.ic_compound_switch_camera_solid,
R.drawable.ic_compound_take_photo,
R.drawable.ic_compound_take_photo_solid,
R.drawable.ic_compound_text_formatting,
R.drawable.ic_compound_threads,
R.drawable.ic_compound_threads_solid,
Expand Down
Loading

0 comments on commit 7af76e3

Please sign in to comment.