Skip to content

Commit 0499757

Browse files
committed
library: Cleanup
1 parent 30b10f7 commit 0499757

File tree

12 files changed

+110
-80
lines changed

12 files changed

+110
-80
lines changed

composeApp/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ kotlin {
8181
commonMain.dependencies {
8282
implementation(compose.runtime)
8383
implementation(compose.foundation)
84-
implementation(compose.material3)
84+
implementation(compose.material)
8585
implementation(compose.ui)
8686
implementation(compose.components.resources)
8787

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import androidx.compose.foundation.layout.PaddingValues
2-
import androidx.compose.foundation.layout.Spacer
32
import androidx.compose.foundation.layout.height
3+
import androidx.compose.foundation.layout.padding
44
import androidx.compose.runtime.Composable
55
import androidx.compose.runtime.MutableState
66
import androidx.compose.ui.Modifier
77
import androidx.compose.ui.unit.dp
8+
import top.yukonga.miuix.kmp.basic.Card
89
import top.yukonga.miuix.kmp.basic.LazyColumn
910
import top.yukonga.miuix.kmp.basic.ScrollBehavior
1011
import top.yukonga.miuix.kmp.extra.SuperDropdown
@@ -33,39 +34,44 @@ fun ThirdPage(
3334
topAppBarScrollBehavior = topAppBarScrollBehavior
3435
) {
3536
item {
36-
SuperSwitch(
37-
title = "Show FPS Monitor",
38-
checked = showFPSMonitor,
39-
onCheckedChange = onShowFPSMonitorChange
40-
)
41-
SuperSwitch(
42-
title = "Show Top App Bar",
43-
checked = showTopAppBar,
44-
onCheckedChange = onShowTopAppBarChange
45-
)
46-
SuperSwitch(
47-
title = "Show Bottom Bar",
48-
checked = showBottomBar,
49-
onCheckedChange = onShowBottomBarChange
50-
)
51-
SuperSwitch(
52-
title = "Show Floating Action Button",
53-
checked = showFloatingActionButton,
54-
onCheckedChange = onShowFloatingActionButtonChange
55-
)
56-
SuperSwitch(
57-
title = "Enable Page User Scroll",
58-
checked = enablePageUserScroll,
59-
onCheckedChange = onEnablePageUserScrollChange
60-
)
61-
SuperDropdown(
62-
title = "Color Mode",
63-
items = listOf("System", "Light", "Dark"),
64-
selectedIndex = colorMode.value,
65-
onSelectedIndexChange = { colorMode.value = it },
66-
horizontalPadding = 12.dp
67-
)
68-
Spacer(modifier = Modifier.height(padding.calculateBottomPadding()))
37+
Card(
38+
modifier = Modifier
39+
.padding(horizontal = 12.dp)
40+
.padding(top = 12.dp, bottom = 12.dp + padding.calculateBottomPadding())
41+
) {
42+
SuperSwitch(
43+
title = "Show FPS Monitor",
44+
checked = showFPSMonitor,
45+
onCheckedChange = onShowFPSMonitorChange
46+
)
47+
SuperSwitch(
48+
title = "Show Top App Bar",
49+
checked = showTopAppBar,
50+
onCheckedChange = onShowTopAppBarChange
51+
)
52+
SuperSwitch(
53+
title = "Show Bottom Bar",
54+
checked = showBottomBar,
55+
onCheckedChange = onShowBottomBarChange
56+
)
57+
SuperSwitch(
58+
title = "Show Floating Action Button",
59+
checked = showFloatingActionButton,
60+
onCheckedChange = onShowFloatingActionButtonChange
61+
)
62+
SuperSwitch(
63+
title = "Enable Page User Scroll",
64+
checked = enablePageUserScroll,
65+
onCheckedChange = onEnablePageUserScrollChange
66+
)
67+
SuperDropdown(
68+
title = "Color Mode",
69+
items = listOf("System", "Light", "Dark"),
70+
selectedIndex = colorMode.value,
71+
onSelectedIndexChange = { colorMode.value = it },
72+
horizontalPadding = 12.dp
73+
)
74+
}
6975
}
7076
}
7177
}

composeApp/src/commonMain/kotlin/UITest.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.animation.fadeIn
55
import androidx.compose.animation.fadeOut
66
import androidx.compose.animation.shrinkHorizontally
77
import androidx.compose.animation.shrinkVertically
8+
import androidx.compose.foundation.Image
89
import androidx.compose.foundation.layout.PaddingValues
910
import androidx.compose.foundation.layout.captionBarPadding
1011
import androidx.compose.foundation.layout.fillMaxSize
@@ -17,7 +18,6 @@ import androidx.compose.material.icons.Icons
1718
import androidx.compose.material.icons.rounded.Home
1819
import androidx.compose.material.icons.rounded.Settings
1920
import androidx.compose.material.icons.rounded.Star
20-
import androidx.compose.material3.Icon
2121
import androidx.compose.runtime.Composable
2222
import androidx.compose.runtime.LaunchedEffect
2323
import androidx.compose.runtime.MutableState
@@ -29,6 +29,7 @@ import androidx.compose.runtime.setValue
2929
import androidx.compose.runtime.snapshotFlow
3030
import androidx.compose.ui.Modifier
3131
import androidx.compose.ui.graphics.Color
32+
import androidx.compose.ui.graphics.ColorFilter
3233
import androidx.compose.ui.platform.LocalUriHandler
3334
import androidx.compose.ui.unit.dp
3435
import kotlinx.coroutines.FlowPreview
@@ -130,9 +131,9 @@ fun UITest(
130131
uriHandler.openUri("https://github.com/miuix-kotlin-multiplatform/miuix")
131132
}
132133
) {
133-
Icon(
134+
Image(
134135
imageVector = MiuixIcons.GitHub,
135-
tint = Color.White,
136+
colorFilter = ColorFilter.tint(Color.White),
136137
contentDescription = "GitHub"
137138
)
138139
}

miuix/build.gradle.kts

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,20 +44,9 @@ kotlin {
4444
commonMain.dependencies {
4545
implementation(compose.runtime)
4646
implementation(compose.foundation)
47-
implementation(compose.material3)
47+
implementation(compose.material)
4848
implementation(compose.ui)
4949
implementation(compose.components.resources)
50-
}
51-
desktopMain.dependencies {
52-
implementation(libs.jetbrains.compose.window.size)
53-
}
54-
jsMain.dependencies {
55-
implementation(libs.jetbrains.compose.window.size)
56-
}
57-
macosMain.dependencies {
58-
implementation(libs.jetbrains.compose.window.size)
59-
}
60-
wasmJsMain.dependencies {
6150
implementation(libs.jetbrains.compose.window.size)
6251
}
6352
}

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/NavigationBar.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
1919
import androidx.compose.foundation.layout.only
2020
import androidx.compose.foundation.layout.padding
2121
import androidx.compose.foundation.layout.size
22-
import androidx.compose.material3.HorizontalDivider
2322
import androidx.compose.runtime.Composable
2423
import androidx.compose.runtime.getValue
2524
import androidx.compose.runtime.mutableStateOf
@@ -38,6 +37,7 @@ import androidx.compose.ui.unit.Dp
3837
import androidx.compose.ui.unit.dp
3938
import androidx.compose.ui.unit.sp
4039
import top.yukonga.miuix.kmp.theme.MiuixTheme
40+
import top.yukonga.miuix.kmp.utils.HorizontalDivider
4141
import top.yukonga.miuix.kmp.utils.Platform
4242
import top.yukonga.miuix.kmp.utils.platform
4343

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/Surface.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import androidx.compose.foundation.BorderStroke
44
import androidx.compose.foundation.background
55
import androidx.compose.foundation.border
66
import androidx.compose.foundation.clickable
7-
import androidx.compose.material3.minimumInteractiveComponentSize
7+
import androidx.compose.material.minimumInteractiveComponentSize
88
import androidx.compose.runtime.Composable
99
import androidx.compose.runtime.NonRestartableComposable
1010
import androidx.compose.runtime.Stable

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/basic/TopAppBar.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,10 @@ private class ExitUntilCollapsedScrollBehavior(
411411
}
412412
}
413413

414+
/**
415+
* Settles the app bar by flinging, in case the given velocity is greater than zero, and snapping
416+
* after the fling settles.
417+
*/
414418
private suspend fun settleAppBar(
415419
state: TopAppBarState,
416420
velocity: Float,
@@ -424,6 +428,7 @@ private suspend fun settleAppBar(
424428
if (state.collapsedFraction < 0.01f || state.collapsedFraction == 1f) {
425429
return Velocity.Zero
426430
}
431+
var remainingVelocity = velocity
427432
// In case there is an initial velocity that was left after a previous user fling, animate to
428433
// continue the motion to expand or collapse the app bar.
429434
if (flingAnimationSpec != null && abs(velocity) > 1f) {
@@ -438,6 +443,7 @@ private suspend fun settleAppBar(
438443
state.heightOffset = initialHeightOffset + delta
439444
val consumed = abs(initialHeightOffset - state.heightOffset)
440445
lastValue = value
446+
remainingVelocity = this.velocity
441447
// avoid rounding errors and stop if anything is unconsumed
442448
if (abs(delta - consumed) > 0.5f) this.cancelAnimation()
443449
}
@@ -458,7 +464,7 @@ private suspend fun settleAppBar(
458464
}
459465
}
460466

461-
return Velocity.Zero
467+
return Velocity(0f, velocity - remainingVelocity)
462468
}
463469

464470
/** A functional interface for providing an app-bar scroll offset. */

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/extra/SuperDialog.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ import top.yukonga.miuix.kmp.basic.Box
3333
import top.yukonga.miuix.kmp.basic.Text
3434
import top.yukonga.miuix.kmp.theme.MiuixTheme
3535
import top.yukonga.miuix.kmp.utils.BackHandler
36-
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.isDialogShowing
3736
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.showDialog
3837
import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
3938
import top.yukonga.miuix.kmp.utils.getRoundedCorner
@@ -87,7 +86,7 @@ fun SuperDialog(
8786
val bottomCornerRadius by remember { derivedStateOf { if (roundedCorner != 0.dp) roundedCorner - outsideMargin.width else 32.dp } }
8887
val contentAlignment by rememberUpdatedState { derivedStateOf { if (windowHeight >= 480.dp && windowWidth >= 840.dp) Alignment.Center else Alignment.BottomCenter } }
8988

90-
BackHandler(enabled = isDialogShowing()) {
89+
BackHandler(enabled = show.value) {
9190
onDismissRequest?.invoke()
9291
}
9392

miuix/src/commonMain/kotlin/top/yukonga/miuix/kmp/theme/MiuixTheme.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package top.yukonga.miuix.kmp.theme
22

33
import androidx.compose.foundation.LocalIndication
4-
import androidx.compose.material3.ripple
4+
import androidx.compose.material.ripple
55
import androidx.compose.runtime.Composable
66
import androidx.compose.runtime.CompositionLocalProvider
77
import androidx.compose.runtime.ReadOnlyComposable
@@ -32,7 +32,7 @@ fun MiuixTheme(
3232
)
3333
}
3434
val miuixRipple = remember(colorScheme.onBackground) {
35-
ripple(color = colorScheme.onBackground.copy(alpha = 0.5f))
35+
ripple(color = colorScheme.onBackground)
3636
}
3737
CompositionLocalProvider(
3838
LocalMiuixColor provides colorScheme,
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package top.yukonga.miuix.kmp.utils
2+
3+
import androidx.compose.foundation.Canvas
4+
import androidx.compose.foundation.layout.fillMaxWidth
5+
import androidx.compose.foundation.layout.height
6+
import androidx.compose.runtime.Composable
7+
import androidx.compose.ui.Modifier
8+
import androidx.compose.ui.geometry.Offset
9+
import androidx.compose.ui.graphics.Color
10+
import androidx.compose.ui.unit.Dp
11+
12+
/**
13+
* A divider is a thin line that groups content in lists and layouts.
14+
*
15+
* @param modifier the [Modifier] to be applied to this divider line.
16+
* @param thickness thickness of this divider line. Using [Dp.Hairline] will produce a single pixel
17+
* divider regardless of screen density.
18+
* @param color color of this divider line.
19+
*/
20+
@Composable
21+
fun HorizontalDivider(
22+
modifier: Modifier = Modifier,
23+
thickness: Dp,
24+
color: Color,
25+
) =
26+
Canvas(modifier.fillMaxWidth().height(thickness)) {
27+
drawLine(
28+
color = color,
29+
strokeWidth = thickness.toPx(),
30+
start = Offset(0f, thickness.toPx() / 2),
31+
end = Offset(size.width, thickness.toPx() / 2),
32+
)
33+
}

0 commit comments

Comments
 (0)