Skip to content

Commit

Permalink
library: Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
YuKongA committed Oct 17, 2024
1 parent 30b10f7 commit 0499757
Show file tree
Hide file tree
Showing 12 changed files with 110 additions and 80 deletions.
2 changes: 1 addition & 1 deletion composeApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ kotlin {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)

Expand Down
74 changes: 40 additions & 34 deletions composeApp/src/commonMain/kotlin/ThirdPage.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import top.yukonga.miuix.kmp.basic.Card
import top.yukonga.miuix.kmp.basic.LazyColumn
import top.yukonga.miuix.kmp.basic.ScrollBehavior
import top.yukonga.miuix.kmp.extra.SuperDropdown
Expand Down Expand Up @@ -33,39 +34,44 @@ fun ThirdPage(
topAppBarScrollBehavior = topAppBarScrollBehavior
) {
item {
SuperSwitch(
title = "Show FPS Monitor",
checked = showFPSMonitor,
onCheckedChange = onShowFPSMonitorChange
)
SuperSwitch(
title = "Show Top App Bar",
checked = showTopAppBar,
onCheckedChange = onShowTopAppBarChange
)
SuperSwitch(
title = "Show Bottom Bar",
checked = showBottomBar,
onCheckedChange = onShowBottomBarChange
)
SuperSwitch(
title = "Show Floating Action Button",
checked = showFloatingActionButton,
onCheckedChange = onShowFloatingActionButtonChange
)
SuperSwitch(
title = "Enable Page User Scroll",
checked = enablePageUserScroll,
onCheckedChange = onEnablePageUserScrollChange
)
SuperDropdown(
title = "Color Mode",
items = listOf("System", "Light", "Dark"),
selectedIndex = colorMode.value,
onSelectedIndexChange = { colorMode.value = it },
horizontalPadding = 12.dp
)
Spacer(modifier = Modifier.height(padding.calculateBottomPadding()))
Card(
modifier = Modifier
.padding(horizontal = 12.dp)
.padding(top = 12.dp, bottom = 12.dp + padding.calculateBottomPadding())
) {
SuperSwitch(
title = "Show FPS Monitor",
checked = showFPSMonitor,
onCheckedChange = onShowFPSMonitorChange
)
SuperSwitch(
title = "Show Top App Bar",
checked = showTopAppBar,
onCheckedChange = onShowTopAppBarChange
)
SuperSwitch(
title = "Show Bottom Bar",
checked = showBottomBar,
onCheckedChange = onShowBottomBarChange
)
SuperSwitch(
title = "Show Floating Action Button",
checked = showFloatingActionButton,
onCheckedChange = onShowFloatingActionButtonChange
)
SuperSwitch(
title = "Enable Page User Scroll",
checked = enablePageUserScroll,
onCheckedChange = onEnablePageUserScrollChange
)
SuperDropdown(
title = "Color Mode",
items = listOf("System", "Light", "Dark"),
selectedIndex = colorMode.value,
onSelectedIndexChange = { colorMode.value = it },
horizontalPadding = 12.dp
)
}
}
}
}
7 changes: 4 additions & 3 deletions composeApp/src/commonMain/kotlin/UITest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkHorizontally
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.captionBarPadding
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -17,7 +18,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Home
import androidx.compose.material.icons.rounded.Settings
import androidx.compose.material.icons.rounded.Star
import androidx.compose.material3.Icon
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.MutableState
Expand All @@ -29,6 +29,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.runtime.snapshotFlow
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.FlowPreview
Expand Down Expand Up @@ -130,9 +131,9 @@ fun UITest(
uriHandler.openUri("https://github.com/miuix-kotlin-multiplatform/miuix")
}
) {
Icon(
Image(
imageVector = MiuixIcons.GitHub,
tint = Color.White,
colorFilter = ColorFilter.tint(Color.White),
contentDescription = "GitHub"
)
}
Expand Down
13 changes: 1 addition & 12 deletions miuix/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,9 @@ kotlin {
commonMain.dependencies {
implementation(compose.runtime)
implementation(compose.foundation)
implementation(compose.material3)
implementation(compose.material)
implementation(compose.ui)
implementation(compose.components.resources)
}
desktopMain.dependencies {
implementation(libs.jetbrains.compose.window.size)
}
jsMain.dependencies {
implementation(libs.jetbrains.compose.window.size)
}
macosMain.dependencies {
implementation(libs.jetbrains.compose.window.size)
}
wasmJsMain.dependencies {
implementation(libs.jetbrains.compose.window.size)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.only
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material3.HorizontalDivider
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand All @@ -38,6 +37,7 @@ import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import top.yukonga.miuix.kmp.theme.MiuixTheme
import top.yukonga.miuix.kmp.utils.HorizontalDivider
import top.yukonga.miuix.kmp.utils.Platform
import top.yukonga.miuix.kmp.utils.platform

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.background
import androidx.compose.foundation.border
import androidx.compose.foundation.clickable
import androidx.compose.material3.minimumInteractiveComponentSize
import androidx.compose.material.minimumInteractiveComponentSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.NonRestartableComposable
import androidx.compose.runtime.Stable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,10 @@ private class ExitUntilCollapsedScrollBehavior(
}
}

/**
* Settles the app bar by flinging, in case the given velocity is greater than zero, and snapping
* after the fling settles.
*/
private suspend fun settleAppBar(
state: TopAppBarState,
velocity: Float,
Expand All @@ -424,6 +428,7 @@ private suspend fun settleAppBar(
if (state.collapsedFraction < 0.01f || state.collapsedFraction == 1f) {
return Velocity.Zero
}
var remainingVelocity = velocity
// In case there is an initial velocity that was left after a previous user fling, animate to
// continue the motion to expand or collapse the app bar.
if (flingAnimationSpec != null && abs(velocity) > 1f) {
Expand All @@ -438,6 +443,7 @@ private suspend fun settleAppBar(
state.heightOffset = initialHeightOffset + delta
val consumed = abs(initialHeightOffset - state.heightOffset)
lastValue = value
remainingVelocity = this.velocity
// avoid rounding errors and stop if anything is unconsumed
if (abs(delta - consumed) > 0.5f) this.cancelAnimation()
}
Expand All @@ -458,7 +464,7 @@ private suspend fun settleAppBar(
}
}

return Velocity.Zero
return Velocity(0f, velocity - remainingVelocity)
}

/** A functional interface for providing an app-bar scroll offset. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ import top.yukonga.miuix.kmp.basic.Box
import top.yukonga.miuix.kmp.basic.Text
import top.yukonga.miuix.kmp.theme.MiuixTheme
import top.yukonga.miuix.kmp.utils.BackHandler
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.isDialogShowing
import top.yukonga.miuix.kmp.utils.MiuixPopupUtil.Companion.showDialog
import top.yukonga.miuix.kmp.utils.SmoothRoundedCornerShape
import top.yukonga.miuix.kmp.utils.getRoundedCorner
Expand Down Expand Up @@ -87,7 +86,7 @@ fun SuperDialog(
val bottomCornerRadius by remember { derivedStateOf { if (roundedCorner != 0.dp) roundedCorner - outsideMargin.width else 32.dp } }
val contentAlignment by rememberUpdatedState { derivedStateOf { if (windowHeight >= 480.dp && windowWidth >= 840.dp) Alignment.Center else Alignment.BottomCenter } }

BackHandler(enabled = isDialogShowing()) {
BackHandler(enabled = show.value) {
onDismissRequest?.invoke()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package top.yukonga.miuix.kmp.theme

import androidx.compose.foundation.LocalIndication
import androidx.compose.material3.ripple
import androidx.compose.material.ripple
import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.ReadOnlyComposable
Expand Down Expand Up @@ -32,7 +32,7 @@ fun MiuixTheme(
)
}
val miuixRipple = remember(colorScheme.onBackground) {
ripple(color = colorScheme.onBackground.copy(alpha = 0.5f))
ripple(color = colorScheme.onBackground)
}
CompositionLocalProvider(
LocalMiuixColor provides colorScheme,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package top.yukonga.miuix.kmp.utils

import androidx.compose.foundation.Canvas
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp

/**
* A divider is a thin line that groups content in lists and layouts.
*
* @param modifier the [Modifier] to be applied to this divider line.
* @param thickness thickness of this divider line. Using [Dp.Hairline] will produce a single pixel
* divider regardless of screen density.
* @param color color of this divider line.
*/
@Composable
fun HorizontalDivider(
modifier: Modifier = Modifier,
thickness: Dp,
color: Color,
) =
Canvas(modifier.fillMaxWidth().height(thickness)) {
drawLine(
color = color,
strokeWidth = thickness.toPx(),
start = Offset(0f, thickness.toPx() / 2),
end = Offset(size.width, thickness.toPx() / 2),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ class MiuixPopupUtil {
dialogContext.value = content
}

/**
* Check if the dialog is showing.
*/
fun isDialogShowing(): Boolean {
return isDialogShowing.value
}

/**
* Dismiss the dialog.
*
Expand All @@ -80,13 +73,6 @@ class MiuixPopupUtil {
popupContext.value = content
}

/**
* Check if the popup is showing.
*/
fun isPopupShowing(): Boolean {
return isPopupShowing.value
}

/**
* Dismiss the popup.
*
Expand Down
Loading

0 comments on commit 0499757

Please sign in to comment.