Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ dependencies {
implementation("androidx.profileinstaller:profileinstaller:1.4.1")
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("ru.noties:jlatexmath-android:0.2.0")
implementation("dev.chrisbanes.haze:haze:2.1.0")
implementation("dev.chrisbanes.haze:haze-glass:2.1.0")

// Android provides org.json; only host JVM tests need the separate library.
testImplementation("org.json:json:20260814")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.logseq.logseq.ui.extensions

import android.os.Build
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.shadow
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.Dp
import androidx.compose.ui.unit.dp
import dev.chrisbanes.haze.HazeInput
import dev.chrisbanes.haze.HazeState
import dev.chrisbanes.haze.glass.GlassStyle
import dev.chrisbanes.haze.glass.hazeGlass
import dev.chrisbanes.haze.rememberHazeState

/** Shared capture state for the small floating chrome surfaces. */
val LocalLogseqHazeState = compositionLocalOf<HazeState?> { null }

/**
* Android Liquid Glass implemented with Haze's source-backed Glass renderer.
* Only small floating chrome surfaces use the Glass effect; scrolling content
* is captured as the backdrop source and is otherwise ordinary Compose drawing.
*/
@Composable
fun Modifier.logseqLiquidGlass(
shape: RoundedCornerShape,
elevation: Dp = 8.dp,
): Modifier {
val state = LocalLogseqHazeState.current ?: rememberHazeState()
// Haze's non-shader Glass fallback (Android 12L and below) does not
// synthesize Regular's base fill, so give only that path a theme tint.
val fallbackTint = MaterialTheme.colorScheme.surface.copy(alpha = 0.82f)
val style = remember(shape, fallbackTint) {
GlassStyle.regular.then {
shape(shape)
// Centered light reads as a white dot inside small circular chrome.
lightPosition(Alignment.TopCenter)
if (Build.VERSION.SDK_INT < 33) {
tint(fallbackTint)
}
}
}
return this
.shadow(
elevation = elevation,
shape = shape,
clip = false,
ambientColor = Color.Black.copy(alpha = 0.16f),
spotColor = Color.Black.copy(alpha = 0.20f),
)
.hazeGlass(
input = HazeInput.Backdrop(state),
style = style,
)
}

@Composable
fun LogseqLiquidGlassSurface(
shape: RoundedCornerShape,
modifier: Modifier = Modifier,
elevation: Dp = 8.dp,
content: @Composable BoxScope.() -> Unit,
) {
Box(modifier.logseqLiquidGlass(shape, elevation), content = content)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package com.logseq.logseq.ui.extensions

import androidx.activity.compose.BackHandler
import androidx.compose.foundation.BorderStroke
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.spring
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.detectHorizontalDragGestures
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxWithConstraints
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
Expand Down Expand Up @@ -37,6 +40,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberUpdatedState
import androidx.compose.runtime.setValue
import androidx.compose.runtime.staticCompositionLocalOf
import androidx.compose.ui.Alignment
Expand All @@ -45,14 +49,17 @@ import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.draw.clip
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.platform.LocalSoftwareKeyboardController
import androidx.compose.ui.platform.LocalFocusManager
import androidx.compose.ui.platform.LocalLayoutDirection
import androidx.compose.ui.semantics.Role
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.unit.LayoutDirection
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.logseq.logseq.runtime.logseqIconResolver
Expand All @@ -63,6 +70,9 @@ import dev.lui.LuiExtensionProperty
import dev.lui.LuiExtensionRegistry
import dev.lui.LuiExtensionValueKind
import dev.lui.luiThemeColor
import dev.chrisbanes.haze.hazeSource
import dev.chrisbanes.haze.rememberHazeState
import kotlin.math.roundToInt

// Port of the former logseq_extensions.dart — the Logseq-specific
// extension hosts. Fingerprints are generated by the OCaml core and must
Expand Down Expand Up @@ -145,6 +155,17 @@ fun logseqExtensionRegistry(
val group = luiThemeColor("settings-group") ?: colors.surface
MaterialTheme(colorScheme = colors.copy(surface = group)) { Children() }
}
registerTweak(
"liquid-glass",
"lui-tweak-v1|12:liquid-glass|profiles:android/kotlin,ios/swiftui|properties:5:shape:string:required:none",
properties = listOf(LuiExtensionProperty("shape", LuiExtensionValueKind.STRING, required = true)),
) {
val shape = when (string("shape")) {
"container", "rounded-rectangle" -> RoundedCornerShape(20.dp)
else -> CircleShape
}
Box(Modifier.logseqLiquidGlass(shape)) { Children() }
}
register(
"outliner-row-swipe",
"lui-extension-v1|18:outliner-row-swipe|profiles:android/kotlin|standard-children:1|children:|properties:12:marker-inset:int:required:none,7:enabled:bool:required:none,8:block-id:string:required:none|events:16:toggle-selection[4:uuid:string:required]",
Expand Down Expand Up @@ -285,41 +306,106 @@ fun logseqExtensionRegistry(
) {
val encoded = string("items") ?: "[]"
val items = remember(encoded) { JSONArray(encoded) }
val count = items.length()
val selected = int("selected-index")
val cellWidth = (int("cell-width") ?: 50).dp
val inset = (int("inset") ?: 4).dp
val accent = luiThemeColor("link", foreground = true) ?: MaterialTheme.colorScheme.primary
val foreground = luiThemeColor("foreground", foreground = true) ?: MaterialTheme.colorScheme.onSurface
val glass = luiThemeColor("glass") ?: MaterialTheme.colorScheme.surfaceContainer
val selection = luiThemeColor("bottom-tab-selected") ?: MaterialTheme.colorScheme.secondaryContainer
Surface(
shape = CircleShape,
color = glass,
border = BorderStroke(1.dp, luiThemeColor("border") ?: MaterialTheme.colorScheme.outlineVariant),
) {
Row(Modifier.padding(inset).selectableGroup(), verticalAlignment = Alignment.CenterVertically) {
for (index in 0 until items.length()) {
val item = items.getJSONObject(index)
val title = item.getString("title")
val name = item.getString("name")
val active = index == selected
val symbol = logseqIconResolver.icon(item.getString(if (active) "selectedImage" else "image"))
Box(
modifier = Modifier.size(width = cellWidth, height = 50.dp)
.clip(CircleShape)
.background(if (active) selection else Color.Transparent)
.selectable(selected = active, role = Role.Tab, onClick = { emit("select", "index" to index) })
.testTag("tab.bottom.$name")
.semantics { contentDescription = title },
contentAlignment = Alignment.Center,
) {
if (symbol != null) {
Box(Modifier.size(26.dp)) {
Icon(symbol, contentDescription = null, modifier = Modifier.fillMaxSize(),
tint = if (active) accent else foreground)
if (item.optBoolean("unread")) {
Box(Modifier.align(Alignment.TopCenter).padding(top = 9.dp).size(4.dp)
.background(accent, CircleShape).testTag("notifications.unread-dot"))
var dragPosition by remember { mutableStateOf<Float?>(null) }
var pendingSelection by remember { mutableStateOf<Int?>(null) }
val currentSelected by rememberUpdatedState(selected)
LaunchedEffect(selected) { pendingSelection = null }
val settledPosition = (pendingSelection ?: selected ?: 0).coerceIn(0, maxOf(0, count - 1)).toFloat()
val animatedPosition by animateFloatAsState(
targetValue = settledPosition,
animationSpec = spring(),
label = "bottom-tab-indicator",
)
val indicatorPosition = dragPosition ?: animatedPosition
val density = LocalDensity.current
val layoutDirection = LocalLayoutDirection.current
val cellWidthPx = with(density) { cellWidth.toPx() }
val insetPx = with(density) { inset.toPx() }
val stripWidthPx = count * cellWidthPx + 2 * insetPx

fun rawIndexAt(x: Float): Float {
val horizontal = if (layoutDirection == LayoutDirection.Rtl) stripWidthPx - x else x
return (horizontal - insetPx) / cellWidthPx - 0.5f
}

fun elasticIndex(raw: Float): Float {
val clamped = raw.coerceIn(0f, (count - 1).toFloat())
val overshoot = ((raw - clamped) * 0.2f).coerceIn(-0.08f, 0.08f)
return clamped + overshoot
}

LogseqLiquidGlassSurface(shape = CircleShape) {
Box(
Modifier.size(width = cellWidth * count + inset * 2, height = 50.dp + inset * 2)
.selectableGroup()
.pointerInput(count, cellWidthPx, insetPx, layoutDirection) {
if (count == 0 || cellWidthPx <= 0f) return@pointerInput
detectHorizontalDragGestures(
onDragStart = { offset -> dragPosition = elasticIndex(rawIndexAt(offset.x)) },
onDragEnd = {
dragPosition?.let { position ->
val target = position.roundToInt().coerceIn(0, count - 1)
if (target != currentSelected) {
pendingSelection = target
emit("select", "index" to target)
}
}
dragPosition = null
},
onDragCancel = { dragPosition = null },
) { change, _ ->
dragPosition = elasticIndex(rawIndexAt(change.position.x))
change.consume()
}
},
) {
val hasIndicator = count > 0 &&
(dragPosition != null || pendingSelection != null || (selected != null && selected in 0 until count))
if (hasIndicator) {
val indicatorX = if (layoutDirection == LayoutDirection.Rtl) {
inset + cellWidth * (count - 1 - indicatorPosition)
} else {
inset + cellWidth * indicatorPosition
}
var indicatorModifier = Modifier.offset(x = indicatorX, y = inset)
.size(width = cellWidth, height = 50.dp)
.clip(CircleShape)
.background(selection)
if (dragPosition != null) {
indicatorModifier = indicatorModifier.logseqLiquidGlass(CircleShape, elevation = 0.dp)
}
Box(indicatorModifier)
}
Row(Modifier.padding(inset), verticalAlignment = Alignment.CenterVertically) {
for (index in 0 until count) {
val item = items.getJSONObject(index)
val title = item.getString("title")
val name = item.getString("name")
val active = index == (dragPosition?.roundToInt() ?: pendingSelection ?: selected)
val symbol = logseqIconResolver.icon(item.getString(if (active) "selectedImage" else "image"))
Box(
modifier = Modifier.size(width = cellWidth, height = 50.dp)
.clip(CircleShape)
.selectable(selected = active, role = Role.Tab, onClick = { emit("select", "index" to index) })
.testTag("tab.bottom.$name")
.semantics { contentDescription = title },
contentAlignment = Alignment.Center,
) {
if (symbol != null) {
Box(Modifier.size(26.dp)) {
Icon(symbol, contentDescription = null, modifier = Modifier.fillMaxSize(),
tint = if (active) accent else foreground)
if (item.optBoolean("unread")) {
Box(Modifier.align(Alignment.TopCenter).padding(top = 9.dp).size(4.dp)
.background(accent, CircleShape).testTag("notifications.unread-dot"))
}
}
}
}
Expand Down Expand Up @@ -436,12 +522,14 @@ private fun NavigationBoundary(context: LuiExtensionContext) {
}
}
var journalTitle by remember { mutableStateOf<String?>(null) }
val hazeState = rememberHazeState()
BoxWithConstraints(Modifier.fillMaxSize()) {
val width = maxWidth.value.toInt()
LaunchedEffect(width) { context.emit("viewport-changed", "width" to width) }
CompositionLocalProvider(
dev.lui.LocalLuiSectionTitle provides journalTitle,
dev.lui.LocalLuiSectionTitleChanged provides { journalTitle = it },
LocalLogseqHazeState provides hazeState,
) {
val childIds = context.children
if (childIds.size == 2) {
Expand All @@ -458,7 +546,9 @@ private fun NavigationBoundary(context: LuiExtensionContext) {
val chromeHeight = remember { mutableIntStateOf(0) }
Box(Modifier.fillMaxSize()) {
CompositionLocalProvider(LocalBottomChromeHeight provides chromeHeight) {
Column(Modifier.fillMaxSize()) { NavigationContent(context, childIds[0], dismissesComposer) }
Column(Modifier.fillMaxSize().hazeSource(hazeState, zIndex = 1f)) {
NavigationContent(context, childIds[0], dismissesComposer)
}
}
val chromeModifier = Modifier
.align(Alignment.BottomCenter)
Expand Down Expand Up @@ -486,6 +576,13 @@ private fun NavigationContent(context: LuiExtensionContext, contentId: Long, dis
val focus = LocalFocusManager.current
val keyboard = LocalSoftwareKeyboardController.current
Box(Modifier.fillMaxSize()) {
LocalLogseqHazeState.current?.let { state ->
Box(
Modifier.fillMaxSize()
.hazeSource(state, zIndex = 0f)
.background(MaterialTheme.colorScheme.background),
)
}
context.child(contentId)
if (dismissesComposer) {
Box(Modifier.fillMaxSize()
Expand Down
2 changes: 1 addition & 1 deletion apple/Sources/Logseq/LGLiquidGlassTweak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import SwiftUI
enum LGLiquidGlassTweak {
static let identifier = "liquid-glass"
static let fingerprint =
"lui-tweak-v1|12:liquid-glass|profiles:ios/swiftui|properties:5:shape:string:required:none"
"lui-tweak-v1|12:liquid-glass|profiles:android/kotlin,ios/swiftui|properties:5:shape:string:required:none"

static func register(in registry: LUIAppleExtensionRegistry) throws {
try registry.registerTweak(
Expand Down
3 changes: 2 additions & 1 deletion shared/src/logseq/view.ml
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,8 @@ let native_search_presentation_schema () =
let liquid_glass_schema () =
let open Lui_protocol in
let open Lui_extension in
Lui_extension.tweak "liquid-glass" [ profile IOS SwiftUIHost ]
Lui_extension.tweak "liquid-glass"
[ profile IOS SwiftUIHost; profile AndroidOS KotlinHost ]
[ Lui_extension.property "shape" StringScalar true None ]

let native_control_tint_schema () =
Expand Down
17 changes: 17 additions & 0 deletions shared/src/logseq/view_base.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1682,6 +1682,23 @@ let with_liquid_glass shape (elem : Lui_elements.t) : Lui_elements.t =
tweak
| _ -> Lui_elements.mount context ?parent elem)

let with_native_liquid_glass shape (elem : Lui_elements.t) : Lui_elements.t =
Lui_elements.custom (fun context parent ->
match Lui_ui.profile context with
| { Lui_protocol.profile_os = Lui_protocol.IOS;
profile_host = Lui_protocol.SwiftUIHost;
}
| { Lui_protocol.profile_os = Lui_protocol.AndroidOS;
profile_host = Lui_protocol.KotlinHost;
} ->
let tweak = Lui_ui.platform_tweak context "liquid-glass" in
Lui_ui.extension_property context tweak "shape"
(StringValue shape);
ignore (Lui_elements.mount context ~parent:tweak elem);
Lui_elements.attach context parent tweak;
tweak
| _ -> Lui_elements.mount context ?parent elem)

let rich_block_content ?(show_code_language = true) ?interaction ?row_actions row_source ~on_event : Lui_elements.t =
Lui_elements.custom (fun context parent ->
let node = Lui_ui.extension context "outliner-block-content" in
Expand Down
1 change: 1 addition & 0 deletions shared/src/logseq/view_base.mli
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ val with_float_prop_signal :
float Signal.signal -> Lui_elements.t -> Lui_elements.t

val with_liquid_glass : string -> Lui_elements.t -> Lui_elements.t
val with_native_liquid_glass : string -> Lui_elements.t -> Lui_elements.t
val rich_block_content :
?show_code_language:bool -> ?interaction:string ->
?row_actions:Lui_protocol.wire_value Signal.signal -> Model.outline_row Signal.signal ->
Expand Down
Loading
Loading