Skip to content

Commit 31854b4

Browse files
authored
Merge pull request #13 from DiskTools/WindowsMica
Windows mica
2 parents 0bf987c + f5b8f00 commit 31854b4

File tree

6 files changed

+95
-57
lines changed

6 files changed

+95
-57
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ allprojects {
1212
google()
1313
mavenCentral()
1414
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
15+
maven("https://s01.oss.sonatype.org/content/repositories/snapshots/")
1516
}
1617
}

example/android/src/main/kotlin/com/konyaco/fluent/example/MainActivity.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class MainActivity : ComponentActivity() {
88
override fun onCreate(savedInstanceState: Bundle?) {
99
super.onCreate(savedInstanceState)
1010
setContent {
11-
App()
11+
ExampleTheme {
12+
App()
13+
}
1214
}
1315
}
1416
}

example/common/src/commonMain/kotlin/com/konyaco/fluent/example/App.kt

Lines changed: 31 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,22 @@ package com.konyaco.fluent.example
22

33
import androidx.compose.animation.*
44
import androidx.compose.animation.core.tween
5-
import androidx.compose.foundation.isSystemInDarkTheme
65
import androidx.compose.foundation.layout.Row
76
import androidx.compose.foundation.layout.fillMaxHeight
87
import androidx.compose.foundation.layout.fillMaxSize
98
import androidx.compose.runtime.*
109
import androidx.compose.ui.Modifier
1110
import androidx.compose.ui.graphics.vector.ImageVector
12-
import com.konyaco.fluent.FluentTheme
1311
import com.konyaco.fluent.animation.FluentDuration
1412
import com.konyaco.fluent.animation.FluentEasing
15-
import com.konyaco.fluent.background.Mica
1613
import com.konyaco.fluent.component.Icon
1714
import com.konyaco.fluent.component.SideNav
1815
import com.konyaco.fluent.component.SideNavItem
1916
import com.konyaco.fluent.component.Text
20-
import com.konyaco.fluent.darkColors
2117
import com.konyaco.fluent.example.screen.HomeScreen
2218
import com.konyaco.fluent.example.screen.TodoScreen
2319
import com.konyaco.fluent.icons.Icons
2420
import com.konyaco.fluent.icons.regular.*
25-
import com.konyaco.fluent.lightColors
2621

2722
private data class NavItem(
2823
val label: String,
@@ -52,63 +47,44 @@ private val navs = listOf(
5247
)
5348

5449

55-
internal val LocalStore = compositionLocalOf<Store> { error("Not provided") }
56-
class Store(
57-
systemDarkMode: Boolean
58-
) {
59-
var darkMode by mutableStateOf(systemDarkMode)
60-
}
61-
6250
@OptIn(ExperimentalAnimationApi::class)
6351
@Composable
6452
fun App() {
65-
val systemDarkMode = isSystemInDarkTheme()
66-
67-
val store = remember { Store(systemDarkMode) }
68-
69-
LaunchedEffect(systemDarkMode) {
70-
store.darkMode = systemDarkMode
71-
}
72-
73-
CompositionLocalProvider(LocalStore provides store) {
74-
FluentTheme(colors = if (store.darkMode) darkColors() else lightColors()) {
75-
Mica(Modifier.fillMaxSize()) {
76-
Row(Modifier.fillMaxSize()) {
77-
var expanded by remember { mutableStateOf(true) }
78-
var selected by remember { mutableStateOf(0) }
7953

80-
SideNav(Modifier.fillMaxHeight(), expanded, { expanded = it },
81-
footer = {
82-
SideNavItem(false, onClick = {
83-
// TODO
84-
}, icon = { Icon(Icons.Default.Settings, "Settings") }) {
85-
Text("Settings")
86-
}
87-
}
88-
) {
89-
navs.forEachIndexed { index, navItem ->
90-
SideNavItem(
91-
selected == index,
92-
onClick = { selected = index },
93-
icon = { Icon(navItem.icon, null) },
94-
content = { Text(navItem.label) }
95-
)
96-
}
97-
}
54+
Row(Modifier.fillMaxSize()) {
55+
var expanded by remember { mutableStateOf(true) }
56+
var selected by remember { mutableStateOf(0) }
9857

99-
AnimatedContent(selected, Modifier.fillMaxHeight().weight(1f), transitionSpec = {
100-
fadeIn(tween(FluentDuration.ShortDuration, easing = FluentEasing.FastInvokeEasing)) +
101-
slideInVertically(
102-
tween(
103-
FluentDuration.ShortDuration,
104-
easing = FluentEasing.FastInvokeEasing
105-
), { it / 6 }) with
106-
fadeOut(tween(FluentDuration.QuickDuration, easing = FluentEasing.FastInvokeEasing))
107-
}) {
108-
navs[it].content()
109-
}
58+
SideNav(Modifier.fillMaxHeight(), expanded, { expanded = it },
59+
footer = {
60+
SideNavItem(false, onClick = {
61+
// TODO
62+
}, icon = { Icon(Icons.Default.Settings, "Settings") }) {
63+
Text("Settings")
11064
}
11165
}
66+
) {
67+
navs.forEachIndexed { index, navItem ->
68+
SideNavItem(
69+
selected == index,
70+
onClick = { selected = index },
71+
icon = { Icon(navItem.icon, null) },
72+
content = { Text(navItem.label) }
73+
)
74+
}
75+
}
76+
77+
AnimatedContent(selected, Modifier.fillMaxHeight().weight(1f), transitionSpec = {
78+
fadeIn(tween(FluentDuration.ShortDuration, easing = FluentEasing.FastInvokeEasing)) +
79+
slideInVertically(
80+
tween(
81+
FluentDuration.ShortDuration,
82+
easing = FluentEasing.FastInvokeEasing
83+
)
84+
) { it / 6 } with
85+
fadeOut(tween(FluentDuration.QuickDuration, easing = FluentEasing.FastInvokeEasing))
86+
}) {
87+
navs[it].content()
11288
}
11389
}
11490
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.konyaco.fluent.example
2+
3+
import androidx.compose.foundation.isSystemInDarkTheme
4+
import androidx.compose.foundation.layout.fillMaxSize
5+
import androidx.compose.runtime.*
6+
import androidx.compose.ui.Modifier
7+
import com.konyaco.fluent.FluentTheme
8+
import com.konyaco.fluent.LocalContentColor
9+
import com.konyaco.fluent.background.Mica
10+
import com.konyaco.fluent.darkColors
11+
import com.konyaco.fluent.lightColors
12+
13+
val LocalStore = compositionLocalOf<Store> { error("Not provided") }
14+
15+
class Store(
16+
systemDarkMode: Boolean
17+
) {
18+
var darkMode by mutableStateOf(systemDarkMode)
19+
}
20+
21+
@Composable
22+
fun ExampleTheme(
23+
displayMicaLayer: Boolean = true,
24+
content: @Composable () -> Unit
25+
) {
26+
val systemDarkMode = isSystemInDarkTheme()
27+
28+
val store = remember { Store(systemDarkMode) }
29+
30+
LaunchedEffect(systemDarkMode) {
31+
store.darkMode = systemDarkMode
32+
}
33+
CompositionLocalProvider(
34+
LocalStore provides store
35+
) {
36+
FluentTheme(colors = if (store.darkMode) darkColors() else lightColors()) {
37+
if (displayMicaLayer) {
38+
Mica(modifier = Modifier.fillMaxSize()) {
39+
content()
40+
}
41+
} else {
42+
CompositionLocalProvider(
43+
LocalContentColor provides FluentTheme.colors.text.text.primary,
44+
content = content
45+
)
46+
}
47+
}
48+
}
49+
}

example/desktop/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ kotlin {
1111
val jvmMain by getting {
1212
dependencies {
1313
implementation(project(":example:common"))
14+
implementation("com.mayakapps.compose:window-styler:0.3.2")
1415
}
1516
}
1617
val jvmTest by getting

example/desktop/src/jvmMain/kotlin/com/konyaco/fluent/example/Main.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,22 @@ import androidx.compose.ui.window.Window
55
import androidx.compose.ui.window.WindowPosition
66
import androidx.compose.ui.window.application
77
import androidx.compose.ui.window.rememberWindowState
8+
import com.mayakapps.compose.windowstyler.WindowBackdrop
9+
import com.mayakapps.compose.windowstyler.WindowStyle
10+
import org.jetbrains.skiko.hostOs
811

912
fun main() = application {
1013
Window(
1114
onCloseRequest = ::exitApplication,
1215
state = rememberWindowState(position = WindowPosition(Alignment.Center)),
1316
title = "Compose Fluent"
1417
) {
15-
App()
18+
ExampleTheme(displayMicaLayer = !hostOs.isWindows) {
19+
WindowStyle(
20+
isDarkTheme = LocalStore.current.darkMode,
21+
backdropType = WindowBackdrop.Mica
22+
)
23+
App()
24+
}
1625
}
1726
}

0 commit comments

Comments
 (0)