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
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ internal val logseqAppIcons: Map<String, ImageVector> = mapOf(
"tab-tasks" to Icons.Outlined.CheckBox,
"tab-tasks-selected" to Icons.Filled.CheckBox,
"tasks-today" to Icons.Outlined.WbSunny,
"tasks-all" to Icons.Outlined.Checklist,
"tab-notifications" to Icons.Outlined.Notifications,
"tab-notifications-selected" to Icons.Filled.Notifications,
"discussion-comment" to Icons.Outlined.ChatBubbleOutline,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ fun logseqExtensionRegistry(
val youtubeStarts = androidx.compose.runtime.mutableStateMapOf<String, Int>()
registerNodeIcon()
registerProperties()
registerTaskFilterStrip()
registerTaskDateSheet()
registerReactionSearchInput()
registerFilterSearchField()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package com.logseq.logseq.ui.extensions

import androidx.compose.animation.core.CubicBezierEasing
import androidx.compose.animation.core.animateFloatAsState
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Row
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.key
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clipToBounds
import androidx.compose.ui.graphics.graphicsLayer
import androidx.compose.ui.layout.Layout
import androidx.compose.ui.platform.LocalView
import androidx.compose.ui.semantics.clearAndSetSemantics
import androidx.compose.ui.unit.Constraints
import androidx.compose.ui.unit.dp
import androidx.core.view.HapticFeedbackConstantsCompat
import androidx.core.view.ViewCompat
import dev.lui.LuiExtensionContext
import dev.lui.LuiExtensionProperty
import dev.lui.LuiExtensionRegistry
import dev.lui.LuiExtensionValueKind
import kotlin.math.roundToInt

internal fun LuiExtensionRegistry.registerTaskFilterStrip() {
register(
"task-filter-strip",
"lui-extension-v1|17:task-filter-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:string:required:none|events:",
acceptsStandardChildren = true,
properties = listOf(LuiExtensionProperty("selected", LuiExtensionValueKind.STRING, required = true)),
) { TaskFilterStrip(this) }
register(
"task-filter-label",
"lui-extension-v1|17:task-filter-label|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:bool:required:none|events:",
acceptsStandardChildren = true,
properties = listOf(LuiExtensionProperty("selected", LuiExtensionValueKind.BOOLEAN, required = true)),
) { TaskFilterLabel(this) }
}

private val filterEasing = CubicBezierEasing(0.23f, 1f, 0.32f, 1f)

@Composable
private fun TaskFilterStrip(context: LuiExtensionContext) {
val selected = context.string("selected")
val view = LocalView.current
var previous by remember { mutableStateOf(selected) }
LaunchedEffect(selected) {
if (selected != previous) {
ViewCompat.performHapticFeedback(view, HapticFeedbackConstantsCompat.SEGMENT_TICK)
previous = selected
}
}
Row(horizontalArrangement = Arrangement.spacedBy(8.dp), verticalAlignment = Alignment.CenterVertically) {
for (child in context.children) key(child) { context.child(child) }
}
}

@Composable
private fun TaskFilterLabel(context: LuiExtensionContext) {
val progress by animateFloatAsState(
targetValue = if (context.bool("selected") == true) 1f else 0f,
animationSpec = tween(200, easing = filterEasing),
label = "Task filter selection",
)
val children = context.children
if (children.size != 2) return
Layout(
modifier = Modifier.clipToBounds(),
content = {
context.child(children[0])
Box(
Modifier.clearAndSetSemantics {}.graphicsLayer {
alpha = ((progress - 0.32f) / 0.68f).coerceIn(0f, 1f)
},
) { context.child(children[1]) }
},
) { items, constraints ->
// The surrounding button adds 14 dp of horizontal padding per side.
val collapsedWidth = 44.dp.roundToPx()
val expandedMinimum = 76.dp.roundToPx()
val gap = 8.dp.roundToPx()
val icon = items[0].measure(Constraints(maxWidth = constraints.maxWidth, maxHeight = constraints.maxHeight))
val label = items[1].measure(Constraints(
maxWidth = (constraints.maxWidth - icon.width - gap).coerceAtLeast(0),
maxHeight = constraints.maxHeight,
))
val expandedWidth = maxOf(expandedMinimum, icon.width + gap + label.width)
val width = (collapsedWidth + (expandedWidth - collapsedWidth) * progress).roundToInt()
.coerceIn(constraints.minWidth, constraints.maxWidth)
val height = maxOf(icon.height, label.height).coerceIn(constraints.minHeight, constraints.maxHeight)
val iconInset = (((collapsedWidth - icon.width).coerceAtLeast(0) / 2f) * (1 - progress)).roundToInt()
layout(width, height) {
icon.placeRelative(iconInset, (height - icon.height) / 2)
label.placeRelative(iconInset + icon.width + gap, (height - label.height) / 2)
}
}
}
123 changes: 123 additions & 0 deletions apple/Sources/Logseq/LGPropertyExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ enum LGPropertyExtension {
acceptsStandardChildren: true,
properties: [.init(name: "collapsed", kind: .string, isRequired: true)]
) { AnyView(LGJournalTaskTransition(context: $0)) })
try registry.register(LUIAppleExtension(
identifier: "task-filter-strip",
fingerprint: "lui-extension-v1|17:task-filter-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:string:required:none|events:",
acceptsStandardChildren: true,
properties: [.init(name: "selected", kind: .string, isRequired: true)]
) { AnyView(LGTaskFilterStrip(context: $0)) })
try registry.register(LUIAppleExtension(
identifier: "task-filter-label",
fingerprint: "lui-extension-v1|17:task-filter-label|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:8:selected:bool:required:none|events:",
acceptsStandardChildren: true,
properties: [.init(name: "selected", kind: .bool, isRequired: true)]
) { AnyView(LGTaskFilterLabel(context: $0)) })
try registry.register(LUIAppleExtension(
identifier: "outliner-bottom-spacer",
fingerprint: "lui-extension-v1|22:outliner-bottom-spacer|profiles:ios/swiftui|standard-children:0|children:|properties:6:height:int:required:none|events:",
Expand Down Expand Up @@ -117,6 +129,117 @@ private struct LGJournalTaskTransition: View {
}
}

private struct LGTaskFilterStrip: View {
let context: LUIAppleExtensionViewContext
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(\.dynamicTypeSize) private var dynamicTypeSize
@State private var animatedSelection: LUIExtensionValue?

init(context: LUIAppleExtensionViewContext) {
self.context = context
_animatedSelection = State(initialValue: context.property("selected"))
}

var body: some View {
let _ = context.revision
let selected = context.property("selected")
// The shared screen mounts the three filters in this order.
LGTaskFilterStripContent(context: context, fixedWidth: !dynamicTypeSize.isAccessibilitySize,
progress: AnimatablePair(
animatedSelection == .string("today") ? 1 : 0,
AnimatablePair(animatedSelection == .string("upcoming") ? 1 : 0,
animatedSelection == .string("all") ? 1 : 0)))
.onChange(of: selected) { _, selection in
withAnimation(reduceMotion ? nil : journalDisclosureAnimation) {
animatedSelection = selection
}
}
.sensoryFeedback(.selection, trigger: selected)
.frame(maxWidth: .infinity, alignment: .leading)
}
}

private extension EnvironmentValues {
@Entry var lgTaskFilterProgress: CGFloat? = nil
}

private struct LGTaskFilterStripContent: View, Animatable {
typealias Progress = AnimatablePair<CGFloat, AnimatablePair<CGFloat, CGFloat>>
let context: LUIAppleExtensionViewContext
let fixedWidth: Bool
nonisolated var progress: Progress

nonisolated var animatableData: Progress {
get { progress }
set { progress = newValue }
}

var body: some View {
let progresses = [progress.first, progress.second.first, progress.second.second]
HStack(spacing: 8) {
ForEach(Array(context.childIDs.enumerated()), id: \.element) { index, id in
context.content(for: id)
.fixedSize(horizontal: fixedWidth, vertical: false)
.environment(\.lgTaskFilterProgress, progresses.indices.contains(index) ? progresses[index] : nil)
}
}
// The shared progress drives all positions and opacities. Do not animate
// each of their intermediate values again as a separate layout change.
.transaction { $0.animation = nil }
}
}

private struct LGTaskFilterLabel: View {
let context: LUIAppleExtensionViewContext
@Environment(\.lgTaskFilterProgress) private var animatedProgress

var body: some View {
let _ = context.revision
let progress = animatedProgress ?? (context.property("selected") == .bool(true) ? 1 : 0)
let labelOpacity = Double(min(max((progress - 0.32) / 0.68, 0), 1))
LGTaskFilterLabelLayout(progress: progress) {
ForEach(Array(context.childIDs.enumerated()), id: \.element) { index, id in
context.content(for: id)
.opacity(index == 0 ? 1 : labelOpacity)
}
}
.clipped()
}
}

private struct LGTaskFilterLabelLayout: Layout {
let progress: CGFloat
private let collapsedWidth: CGFloat = 44
private let expandedMinimum: CGFloat = 76
private let gap: CGFloat = 8

func sizeThatFits(proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) -> CGSize {
guard subviews.count == 2 else { return .zero }
let icon = subviews[0].sizeThatFits(.unspecified)
let label = subviews[1].sizeThatFits(.unspecified)
let expandedWidth = max(expandedMinimum, icon.width + gap + label.width)
let width = collapsedWidth + (expandedWidth - collapsedWidth) * progress
return CGSize(width: min(width, proposal.width ?? width), height: max(icon.height, label.height))
}

func placeSubviews(in bounds: CGRect, proposal: ProposedViewSize, subviews: Subviews, cache: inout ()) {
guard subviews.count == 2 else { return }
let icon = subviews[0].sizeThatFits(.unspecified)
let inset = max(0, (collapsedWidth - icon.width) / 2) * (1 - progress)
let layoutDirection = subviews.layoutDirection
let origin = layoutDirection == .leftToRight ? bounds.minX : bounds.maxX
let direction: CGFloat = layoutDirection == .leftToRight ? 1 : -1
let anchor: UnitPoint = layoutDirection == .leftToRight ? .leading : .trailing
subviews[0].place(at: CGPoint(x: origin + direction * inset, y: bounds.midY),
anchor: anchor, proposal: ProposedViewSize(icon))
let labelLeading = inset + icon.width + gap
let labelWidth = progress < 1 ? subviews[1].sizeThatFits(.unspecified).width
: max(0, bounds.width - labelLeading)
subviews[1].place(at: CGPoint(x: origin + direction * labelLeading, y: bounds.midY),
anchor: anchor, proposal: ProposedViewSize(width: labelWidth, height: bounds.height))
}
}

private struct LGOutlinerBottomSpacer: View {
let height: CGFloat
@Environment(\.outlinerScrollRetention) private var scrollRetention
Expand Down
1 change: 1 addition & 0 deletions apple/Sources/Logseq/LGRenderer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ enum LGIconPolicy {
"tab-tasks": .systemName("checkmark.square"),
"tab-tasks-selected": .systemName("checkmark.square.fill"),
"tasks-today": .systemName("sun.max"),
"tasks-all": .systemName("checklist"),
"composer-file": .systemName("doc"),
"arrow-up": .systemName("arrow.up"),
"close": .assetName("close"),
Expand Down
43 changes: 42 additions & 1 deletion shared/bench/outliner_perf.ml
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,47 @@ let check_rtc_and_tasks db =
assert (task "today" date = None && Option.is_some (task "upcoming" date)));
print_endline "RTC edits, repeated Enter with confirmations, and Tasks edits are within budget"

let check_all_task_edits db =
let agenda = ref `Null in
let request () = Journal_task_dates.All_visible (Journal_task_dates.projection_revision !agenda) in
let agenda_payload response = Workload.member "journalTasks" (Workload.result response) in
let all_rows () = Json.Util.to_list (Workload.member "all" !agenda) in
let target () = List.find (fun row -> Workload.member "uuid" row = `String Workload.external_task) (all_rows ()) in
Workload.with_session ~show_journal_tasks:(fun () -> true) ~all_tasks_request:request db (fun session ->
let initial = agenda_payload (Workload.dispatch session "clearSelectedPage" "") in
agenda := initial;
assert (List.length (all_rows ()) = 1_040);
let full_size = String.length (Json.to_string initial) in
let transport = Workload.connected session in
Workload.edit_external_task session;
let draft, (_, _, size) = measure (fun () -> Workload.type_external_task session) in
assert (agenda_payload draft = `Null && size < 8_192);
let change label run =
let response, (ms, _, response_size) = measure (fun () -> run session) in
let payload = agenda_payload response in
let delta_size = String.length (Json.to_string payload) in
assert (Journal_task_dates.delta_base payload = Journal_task_dates.projection_revision !agenda);
assert (Workload.member "all" payload = `Null && delta_size < 8_192);
agenda := Journal_task_dates.apply_delta !agenda payload;
assert (List.length (all_rows ()) = 1_040);
let _, ack = Workload.confirm_pending session transport in
let acknowledgment = agenda_payload ack in
if acknowledgment <> `Null then begin
assert (Journal_task_dates.delta_base acknowledgment = Journal_task_dates.projection_revision !agenda);
assert (String.length (Json.to_string acknowledgment) < 8_192);
agenda := Journal_task_dates.apply_delta !agenda acknowledgment
end;
Printf.printf "All %s: %.2f ms, %d-byte agenda delta, %d-byte response (full agenda %d bytes)\n%!"
label ms delta_size response_size full_size in
change "title edit" Workload.save;
assert (Workload.member "title" (Workload.member "block" (target ())) = `String "Updated task");
change "status change" Workload.external_task_status;
assert (Workload.member "ident" (Workload.member "status" (Workload.member "block" (target ())))
= `String "logseq.property/status.doing");
let before = Workload.member "scheduled" (target ()) in
change "date change" Workload.external_task_date;
assert (before <> Workload.member "scheduled" (target ())))

let check db =
Workload.with_session db (fun session ->
let today = Workload.result (Workload.open_today session) in
Expand Down Expand Up @@ -215,6 +256,6 @@ let check db =
let () =
let db = Workload.fixture () in
match Array.to_list Sys.argv with
| [_] -> check db; check_notification_demand db; check_rtc_and_tasks db
| [_] -> check db; check_notification_demand db; check_rtc_and_tasks db; check_all_task_edits db
| [_; "--bench"; count] when int_of_string count > 0 -> benchmark db (int_of_string count)
| _ -> failwith "usage: outliner_perf [--bench ITERATIONS]"
3 changes: 2 additions & 1 deletion shared/bench/outliner_workload.ml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ let result raw =
if member "ok" response <> `Bool true then failwith raw;
member "result" response

let with_session ?show_journal_tasks ?show_notifications db f =
let with_session ?show_journal_tasks ?all_tasks_request ?show_notifications db f =
let path = Filename.temp_file "outliner-workload" ".sqlite" in
let checkpoint_path = path ^ ".checkpoint" in
let host = Mobile_session.create (fun _ -> failwith "Unexpected crypto call in the plaintext fixture") in
Expand All @@ -103,6 +103,7 @@ let with_session ?show_journal_tasks ?show_notifications db f =
let session = Session.create_session ~journal_tasks {Session.default_options with
outliner_projection_limit = options.outliner_projection_limit;
show_journal_tasks = options.show_journal_tasks;
all_tasks_request;
show_notifications;
load_graph_catalog = Some (fun () -> Some {|{"graphs":[{"graph-id":"outliner-perf","graph-name":"Outliner benchmark","graph-e2ee?":false,"graph-ready-for-use?":true}]}|});
sync_cursor = options.sync_cursor;
Expand Down
Loading
Loading