Skip to content

Commit 2631bcc

Browse files
committed
example: Re-add haze
* Use snapshot version with macos native support
1 parent 1dc9a16 commit 2631bcc

File tree

4 files changed

+46
-2
lines changed

4 files changed

+46
-2
lines changed

composeApp/build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ kotlin {
9090
implementation(compose.ui)
9191
implementation(compose.components.resources)
9292

93+
implementation(libs.haze)
94+
9395
implementation(project(":miuix"))
9496
}
9597
desktopMain.dependencies {

composeApp/src/commonMain/kotlin/UITest.kt

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ import androidx.compose.ui.hapticfeedback.HapticFeedbackType
3030
import androidx.compose.ui.platform.LocalHapticFeedback
3131
import androidx.compose.ui.platform.LocalUriHandler
3232
import androidx.compose.ui.unit.dp
33+
import androidx.compose.ui.util.lerp
34+
import dev.chrisbanes.haze.HazeState
35+
import dev.chrisbanes.haze.HazeStyle
36+
import dev.chrisbanes.haze.HazeTint
37+
import dev.chrisbanes.haze.hazeEffect
38+
import dev.chrisbanes.haze.hazeSource
3339
import kotlinx.coroutines.FlowPreview
3440
import kotlinx.coroutines.flow.collectLatest
3541
import kotlinx.coroutines.flow.debounce
@@ -58,6 +64,7 @@ import top.yukonga.miuix.kmp.icon.icons.useful.More
5864
import top.yukonga.miuix.kmp.icon.icons.useful.NavigatorSwitch
5965
import top.yukonga.miuix.kmp.icon.icons.useful.Order
6066
import top.yukonga.miuix.kmp.icon.icons.useful.Settings
67+
import top.yukonga.miuix.kmp.theme.MiuixTheme
6168
import top.yukonga.miuix.kmp.utils.MiuixPopupUtils.Companion.dismissPopup
6269
import utils.FPSMonitor
6370

@@ -97,6 +104,23 @@ fun UITest(
97104
}
98105
}
99106

107+
val hazeState = remember { HazeState() }
108+
109+
val hazeStyleTopBar = HazeStyle(
110+
backgroundColor = if (currentScrollBehavior.state.heightOffset > -1) Color.Transparent else MiuixTheme.colorScheme.background,
111+
tint = HazeTint(
112+
MiuixTheme.colorScheme.background.copy(
113+
if (currentScrollBehavior.state.heightOffset > -1) 1f
114+
else lerp(1f, 0.67f, (currentScrollBehavior.state.heightOffset + 1) / -143f)
115+
)
116+
)
117+
)
118+
119+
val hazeStyleBottomBar = HazeStyle(
120+
backgroundColor = MiuixTheme.colorScheme.background,
121+
tint = HazeTint(MiuixTheme.colorScheme.background.copy(0.67f))
122+
)
123+
100124
val showFPSMonitor = remember { mutableStateOf(false) }
101125
val showTopAppBar = remember { mutableStateOf(true) }
102126
val showBottomBar = remember { mutableStateOf(true) }
@@ -119,11 +143,19 @@ fun UITest(
119143
enter = fadeIn() + expandVertically(),
120144
exit = fadeOut() + shrinkVertically()
121145
) {
122-
BoxWithConstraints {
146+
BoxWithConstraints(
147+
modifier = Modifier
148+
.hazeEffect(hazeState) {
149+
style = hazeStyleTopBar
150+
blurRadius = 25.dp
151+
noiseFactor = 0f
152+
}
153+
) {
123154
if (maxWidth > 840.dp) {
124155
SmallTopAppBar(
125156
title = "Miuix",
126157
scrollBehavior = currentScrollBehavior,
158+
color = Color.Transparent,
127159
actions = {
128160
if (isTopPopupExpanded.value) {
129161
ListPopup(
@@ -174,6 +206,7 @@ fun UITest(
174206
TopAppBar(
175207
title = "Miuix",
176208
scrollBehavior = currentScrollBehavior,
209+
color = Color.Transparent,
177210
actions = {
178211
if (isTopPopupExpanded.value) {
179212
ListPopup(
@@ -262,6 +295,12 @@ fun UITest(
262295
showBottomPopup.value = true
263296
}
264297
NavigationBar(
298+
modifier = Modifier
299+
.hazeEffect(hazeState) {
300+
style = hazeStyleBottomBar
301+
blurRadius = 25.dp
302+
noiseFactor = 0f
303+
},
265304
items = items,
266305
selected = targetPage,
267306
onClick = { index ->
@@ -294,7 +333,7 @@ fun UITest(
294333
}
295334
) { padding ->
296335
AppHorizontalPager(
297-
modifier = Modifier.imePadding(),
336+
modifier = Modifier.imePadding().hazeSource(state = hazeState),
298337
pagerState = pagerState,
299338
topAppBarScrollBehaviorList = topAppBarScrollBehaviorList,
300339
padding = padding,

gradle/libs.versions.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ androidx-window = "1.3.0"
99
androidx-graphics-shapes = "1.0.0-alpha04"
1010
compose-plugin = "1.8.0-alpha04"
1111
dokka = "2.0.0"
12+
haze = "1.6.0-SNAPSHOT"
1213
kotlin = "2.1.10"
1314

1415
[libraries]
1516
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity-compose" }
1617
androidx-graphics-shapes = { module = "org.jetbrains.androidx.graphics:graphics-shapes", version.ref = "androidx-graphics-shapes" }
1718
androidx-window = { group = "androidx.window", name = "window", version.ref = "androidx-window" }
1819
compose-window-size = { module = "org.jetbrains.compose.material3:material3-window-size-class", version.ref = "compose-plugin" }
20+
haze = { module = "dev.chrisbanes.haze:haze", version.ref = "haze" }
1921

2022
[plugins]
2123
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ dependencyResolutionManagement {
2525
}
2626
}
2727
mavenCentral()
28+
maven("https://raw.githubusercontent.com/miuix-kotlin-multiplatform/maven-repository/main/repository/snapshots")
2829
}
2930
}
3031

0 commit comments

Comments
 (0)