From addb047f3f0a6f30ef5958438642441a8ad17d40 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 20 Nov 2026 14:09:10 +0800 Subject: [PATCH] Polish iOS search transitions and sheet colors --- apple/Sources/Logseq/LGMediaPanel.swift | 4 ++-- .../Logseq/LGNavigationExtension.swift | 21 +++++++++++++------ .../Logseq/LGPlatformPresentation.swift | 4 +++- .../Sources/Logseq/LogseqThemeSettings.swift | 6 +----- apple/Tests/UI/settings-control-colors.swift | 6 +++--- shared/src/logseq/view_base.ml | 6 ++++-- 6 files changed, 28 insertions(+), 19 deletions(-) diff --git a/apple/Sources/Logseq/LGMediaPanel.swift b/apple/Sources/Logseq/LGMediaPanel.swift index 09fed230..feca5ca3 100644 --- a/apple/Sources/Logseq/LGMediaPanel.swift +++ b/apple/Sources/Logseq/LGMediaPanel.swift @@ -94,7 +94,7 @@ struct LGMediaPanel: View { maxSelectionCount: 20, selectionBehavior: .ordered, matching: .images) } else { - let foreground = isDark ? sheetBackground : Color.white + let foreground = Color.white Button(action: addSelectedPhotos) { HStack(spacing: 8) { if isImporting { ProgressView().tint(foreground) } @@ -104,7 +104,7 @@ struct LGMediaPanel: View { .foregroundStyle(foreground) .padding(.horizontal, 20) .frame(height: 44) - .background(LogseqThemePolicy.sheetAccent(isDark: isDark), in: Capsule()) + .background(LogseqThemePolicy.accent, in: Capsule()) } .disabled(isImporting) .accessibilityIdentifier("media.add-selected") diff --git a/apple/Sources/Logseq/LGNavigationExtension.swift b/apple/Sources/Logseq/LGNavigationExtension.swift index c476db78..74650d4e 100644 --- a/apple/Sources/Logseq/LGNavigationExtension.swift +++ b/apple/Sources/Logseq/LGNavigationExtension.swift @@ -808,6 +808,10 @@ private struct LGNavigationContent: View { } .frame(maxWidth: .infinity, maxHeight: .infinity) .ignoresSafeArea(.all, edges: .bottom) + // Keep the layout mounted without drawing the capture controls + // beneath the native search bar and its Cancel button. + .opacity(searchVisible ? 0 : 1) + .animation(nil, value: searchVisible) .allowsHitTesting(!searchVisible) .accessibilityHidden(searchVisible) } else { @@ -1272,9 +1276,12 @@ private struct LGNativeSearchControllerBridge: UIViewControllerRepresentable { } if !controller.isActive { needsInitialFocus = true - controller.isActive = true + // Let editing activate the integrated search bar so UIKit can + // coordinate its expansion with the keyboard in one transition. + if #available(iOS 26.0, *) { focusIfNeeded() } + if !controller.isActive { controller.isActive = true } } - if needsInitialFocus, controller.searchBar.searchTextField.becomeFirstResponder() { needsInitialFocus = false } + if #unavailable(iOS 26.0) { focusIfNeeded() } } else if !state.nativePresented, controller.isActive { controller.isActive = false } else if !state.isVisible, !controller.isActive { @@ -1292,11 +1299,13 @@ private struct LGNativeSearchControllerBridge: UIViewControllerRepresentable { host.navigationItem.searchController = nil } + private func focusIfNeeded() { + guard state.nativePresented, needsInitialFocus else { return } + if controller.searchBar.searchTextField.becomeFirstResponder() { needsInitialFocus = false } + } + func didPresentSearchController(_ searchController: UISearchController) { - DispatchQueue.main.async { [weak self] in - guard let self, self.state.nativePresented else { return } - if searchController.searchBar.searchTextField.becomeFirstResponder() { self.needsInitialFocus = false } - } + DispatchQueue.main.async { [weak self] in self?.focusIfNeeded() } } func willDismissSearchController(_ searchController: UISearchController) { needsInitialFocus = false diff --git a/apple/Sources/Logseq/LGPlatformPresentation.swift b/apple/Sources/Logseq/LGPlatformPresentation.swift index 17358c41..75480661 100644 --- a/apple/Sources/Logseq/LGPlatformPresentation.swift +++ b/apple/Sources/Logseq/LGPlatformPresentation.swift @@ -145,7 +145,7 @@ private struct LGSheetSurface: ViewModifier { content .background(background.ignoresSafeArea()) .presentationBackground(background) - .tint(LogseqThemePolicy.sheetAccent(isDark: dark)) + .tint(LogseqThemePolicy.accent) } } @@ -168,9 +168,11 @@ struct LGJournalCalendar: View { .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel") { dismiss() } + .foregroundStyle(.primary) } ToolbarItem(placement: .confirmationAction) { Button("Today") { select(Date()) } + .foregroundStyle(.primary) .accessibilityIdentifier("button.journal-calendar.today") } } diff --git a/apple/Sources/Logseq/LogseqThemeSettings.swift b/apple/Sources/Logseq/LogseqThemeSettings.swift index 3c16f1b1..ba7e0c20 100644 --- a/apple/Sources/Logseq/LogseqThemeSettings.swift +++ b/apple/Sources/Logseq/LogseqThemeSettings.swift @@ -62,12 +62,8 @@ enum LogseqThemePolicy { : Color(red: 27.0 / 255, green: 104.0 / 255, blue: 152.0 / 255) } - static func sheetAccent(isDark: Bool) -> Color { - isDark ? linkColor(isDark: true) : accent - } - static func sheetBackground(isDark: Bool) -> Color { - (isDark ? dark : light).background + isDark ? dark.background : Color(red: 242.0 / 255, green: 242.0 / 255, blue: 247.0 / 255) } static let light = LogseqThemePalette( diff --git a/apple/Tests/UI/settings-control-colors.swift b/apple/Tests/UI/settings-control-colors.swift index af8ce672..7019d2a4 100644 --- a/apple/Tests/UI/settings-control-colors.swift +++ b/apple/Tests/UI/settings-control-colors.swift @@ -98,12 +98,12 @@ import Vision } } let dark = style == .dark - let background = dark ? (0, 45, 56) : (252, 252, 252) + let background = dark ? (0, 45, 56) : (242, 242, 247) let gutter = CGRect(x: 7, y: (1 - spell.midY) * window.bounds.height - 4, width: 5, height: 8) guard matchingPixels(in: gutter, where: { r, g, b in abs(r - background.0) <= 3 && abs(g - background.1) <= 3 && abs(b - background.2) <= 3 - }) > 20 else { throw failure("Settings sheet must use the graph background") } - let accent = dark ? (155, 211, 212) : (3, 125, 186) + }) > 20 else { throw failure("Settings sheet must use the themed canvas behind its groups") } + let accent = (3, 125, 186) func usesAccent(_ r: Int, _ g: Int, _ b: Int) -> Bool { abs(r - accent.0) <= 12 && abs(g - accent.1) <= 12 && abs(b - accent.2) <= 12 } diff --git a/shared/src/logseq/view_base.ml b/shared/src/logseq/view_base.ml index 8c7dc3dc..65819d77 100644 --- a/shared/src/logseq/view_base.ml +++ b/shared/src/logseq/view_base.ml @@ -11,6 +11,7 @@ let property_title current ~attr ~title = open Lui_protocol let main_background = Lui_ui.Adaptive { light = "#FCFCFC"; dark = "#002D38" } +let sheet_background = Lui_ui.Adaptive { light = "#F2F2F7"; dark = "#002D38" } let grouped_row_background = Lui_ui.Adaptive { light = "#FFFFFF"; dark = "#FFFFFF14" } let dark_accent = "#9BD3D4" @@ -22,12 +23,13 @@ let sheet ?height ?style_class ?detents ?detents_signal ?accessibility_identifie match Lui_ui.profile context with | { profile_os = IOS; profile_host = SwiftUIHost } -> (* The Apple modal host reads theme tokens from the sheet's ancestors. *) - let accent = Lui_ui.Adaptive { light = "#037DBA"; dark = dark_accent } in + let accent = Lui_ui.Fixed "#037DBA" in let list_sheet = Option.fold ~none:false ~some:(fun style -> List.mem "navigation-list" (String.split_on_char ' ' style)) style_class in Lui_elements.themed ~tokens:[ (* The list presentation uses the background token for the modal itself. *) - "surface", (if list_sheet then grouped_row_background else main_background); + "background", sheet_background; + "surface", (if list_sheet then grouped_row_background else sheet_background); "card", grouped_row_background; "input", grouped_row_background; "primary", accent;