mirror of
https://github.com/sudosylabs/vnidrop.git
synced 2026-08-05 02:29:55 +02:00
Polish native shell navigation
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package com.vnidrop.app.ui.navigation
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.border
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
@@ -40,23 +39,34 @@ fun AppSidebarNavigation(
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val colors = LocalVniDropColors.current
|
||||
Column(
|
||||
Box(
|
||||
modifier = modifier
|
||||
.width(88.dp)
|
||||
.fillMaxHeight()
|
||||
.background(colors.backgroundSurface200)
|
||||
.border(width = 1.dp, color = colors.borderDefault)
|
||||
.padding(vertical = 10.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
.background(colors.backgroundSurface200),
|
||||
) {
|
||||
primaryNavigationItems.forEach { item ->
|
||||
SidebarNavigationItem(
|
||||
item = item,
|
||||
selected = item.destination == selected,
|
||||
onClick = { onDestinationSelected(item.destination) },
|
||||
)
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxHeight()
|
||||
.padding(vertical = 10.dp),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
verticalArrangement = Arrangement.spacedBy(2.dp),
|
||||
) {
|
||||
primaryNavigationItems.forEach { item ->
|
||||
SidebarNavigationItem(
|
||||
item = item,
|
||||
selected = item.destination == selected,
|
||||
onClick = { onDestinationSelected(item.destination) },
|
||||
)
|
||||
}
|
||||
}
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterEnd)
|
||||
.width(1.dp)
|
||||
.fillMaxHeight()
|
||||
.background(colors.borderDefault),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,10 +80,8 @@ fun AppBottomNavigation(
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxWidth()
|
||||
.background(colors.backgroundSurface200)
|
||||
.border(width = 1.dp, color = colors.borderDefault),
|
||||
.background(colors.backgroundSurface200),
|
||||
) {
|
||||
ActiveBottomIndicator(selected = selected)
|
||||
Row(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -107,18 +115,8 @@ private fun SidebarNavigationItem(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.selectable(selected = selected, onClick = onClick)
|
||||
.background(if (selected) colors.backgroundSurface300 else Color.Transparent)
|
||||
.padding(vertical = 13.dp),
|
||||
) {
|
||||
if (selected) {
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.align(Alignment.CenterStart)
|
||||
.size(width = 4.dp, height = 46.dp)
|
||||
.clip(RoundedCornerShape(topEnd = 4.dp, bottomEnd = 4.dp))
|
||||
.background(colors.brandLink),
|
||||
)
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
@@ -168,19 +166,3 @@ private fun BottomNavigationItem(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun ActiveBottomIndicator(selected: AppDestination) {
|
||||
val colors = LocalVniDropColors.current
|
||||
val index = primaryNavigationItems.indexOfFirst { it.destination == selected }.coerceAtLeast(0)
|
||||
Row(modifier = Modifier.fillMaxWidth()) {
|
||||
repeat(primaryNavigationItems.size) { itemIndex ->
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.weight(1f)
|
||||
.size(height = 3.dp, width = 1.dp)
|
||||
.background(if (itemIndex == index) colors.brandLink else Color.Transparent),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,17 +41,13 @@ object VniDropIcons {
|
||||
strokeLineJoin = StrokeJoin.Round,
|
||||
pathFillType = PathFillType.NonZero,
|
||||
) {
|
||||
moveTo(12f, 3f)
|
||||
lineTo(12f, 15f)
|
||||
moveTo(7f, 10f)
|
||||
lineTo(12f, 15f)
|
||||
lineTo(17f, 10f)
|
||||
moveTo(5f, 21f)
|
||||
lineTo(19f, 21f)
|
||||
moveTo(5f, 17f)
|
||||
moveTo(12f, 17f)
|
||||
lineTo(12f, 3f)
|
||||
moveTo(6f, 11f)
|
||||
lineTo(12f, 17f)
|
||||
lineTo(18f, 11f)
|
||||
moveTo(19f, 21f)
|
||||
lineTo(5f, 21f)
|
||||
moveTo(19f, 17f)
|
||||
lineTo(19f, 21f)
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
@@ -66,25 +62,22 @@ object VniDropIcons {
|
||||
strokeLineJoin = StrokeJoin.Round,
|
||||
pathFillType = PathFillType.NonZero,
|
||||
) {
|
||||
moveTo(9.671f, 4.136f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, true, 4.659f, 0f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, 3.319f, 1.915f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, true, 2.33f, 4.033f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, 0f, 3.831f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, true, -2.33f, 4.033f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, -3.319f, 1.915f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, true, -4.659f, 0f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, -3.32f, -1.915f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, true, -2.33f, -4.033f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, 0f, -3.831f)
|
||||
arcTo(2.34f, 2.34f, 0f, false, true, 6.35f, 6.051f)
|
||||
arcToRelative(2.34f, 2.34f, 0f, false, false, 3.319f, -1.915f)
|
||||
moveTo(12f, 15f)
|
||||
arcTo(3f, 3f, 0f, false, false, 12f, 9f)
|
||||
arcTo(3f, 3f, 0f, false, false, 12f, 15f)
|
||||
moveTo(19.4f, 15f)
|
||||
lineTo(20.8f, 17.4f)
|
||||
lineTo(18.4f, 21f)
|
||||
lineTo(15.8f, 20f)
|
||||
moveTo(8.2f, 4f)
|
||||
lineTo(5.6f, 3f)
|
||||
lineTo(3.2f, 6.6f)
|
||||
lineTo(4.6f, 9f)
|
||||
moveTo(15.8f, 4f)
|
||||
lineTo(18.4f, 3f)
|
||||
lineTo(20.8f, 6.6f)
|
||||
lineTo(19.4f, 9f)
|
||||
moveTo(4.6f, 15f)
|
||||
lineTo(3.2f, 17.4f)
|
||||
lineTo(5.6f, 21f)
|
||||
lineTo(8.2f, 20f)
|
||||
arcTo(3f, 3f, 0f, false, true, 12f, 9f)
|
||||
arcTo(3f, 3f, 0f, false, true, 12f, 15f)
|
||||
}
|
||||
}.build()
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ internal object DesktopSystemAppearance {
|
||||
if (!isMacOs()) return
|
||||
System.setProperty(MAC_APPEARANCE_PROPERTY, macOsAppearanceName(isDarkTheme))
|
||||
EventQueue.invokeLater {
|
||||
DesktopAppearanceBridge.applyNativeAppearance?.invoke(isDarkTheme)
|
||||
Window.getWindows().forEach { window ->
|
||||
applyWindowChrome(window, isDarkTheme)
|
||||
}
|
||||
@@ -31,6 +32,8 @@ internal object DesktopSystemAppearance {
|
||||
internal fun macOsAppearanceName(isDarkTheme: Boolean): String =
|
||||
if (isDarkTheme) "NSAppearanceNameDarkAqua" else "NSAppearanceNameAqua"
|
||||
|
||||
internal fun usesTransparentTitlebar(): Boolean = true
|
||||
|
||||
internal fun titlebarBackground(isDarkTheme: Boolean): Color =
|
||||
if (isDarkTheme) Color(0x12, 0x12, 0x12) else Color(0xF8, 0xF8, 0xF8)
|
||||
|
||||
@@ -38,9 +41,9 @@ internal object DesktopSystemAppearance {
|
||||
val background = titlebarBackground(isDarkTheme)
|
||||
window.background = background
|
||||
(window as? JFrame)?.rootPane?.let { rootPane ->
|
||||
// Keep the native macOS controls and drag behavior, but let the
|
||||
// decorated titlebar blend with the app's resolved light/dark surface.
|
||||
rootPane.putClientProperty(TRANSPARENT_TITLE_BAR_PROPERTY, true)
|
||||
// The titlebar stays native, but AppKit receives the resolved app
|
||||
// appearance so title text and controls switch contrast at runtime.
|
||||
rootPane.putClientProperty(TRANSPARENT_TITLE_BAR_PROPERTY, usesTransparentTitlebar())
|
||||
rootPane.background = background
|
||||
rootPane.contentPane.background = background
|
||||
}
|
||||
@@ -49,3 +52,8 @@ internal object DesktopSystemAppearance {
|
||||
private fun isMacOs(): Boolean =
|
||||
System.getProperty("os.name").startsWith("Mac", ignoreCase = true)
|
||||
}
|
||||
|
||||
object DesktopAppearanceBridge {
|
||||
@Volatile
|
||||
var applyNativeAppearance: ((Boolean) -> Unit)? = null
|
||||
}
|
||||
|
||||
@@ -15,4 +15,15 @@ class DesktopSystemAppearanceTest {
|
||||
assertEquals(0x121212, DesktopSystemAppearance.titlebarBackground(isDarkTheme = true).rgb and 0xFFFFFF)
|
||||
assertEquals(0xF8F8F8, DesktopSystemAppearance.titlebarBackground(isDarkTheme = false).rgb and 0xFFFFFF)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun transparentTitlebarIsAlwaysUsedWithAppKitAppearance() {
|
||||
assertEquals(true, DesktopSystemAppearance.usesTransparentTitlebar())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun runtimeAppearanceCallIsFailSoft() {
|
||||
DesktopSystemAppearance.apply(isDarkTheme = true)
|
||||
DesktopSystemAppearance.apply(isDarkTheme = false)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user