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 @@ -263,7 +263,7 @@ fun logseqExtensionRegistry(
registerOutlinerBlockRow(resolveAssetPath, youtubeStarts, onOpenImage, loadImage)
register(
"bottom-tab-strip",
"lui-extension-v1|16:bottom-tab-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:10:cell-width:int:required:none,14:selected-index:int:required:none,5:inset:int:required:none,5:items:string:required:none|events:15:home-double-tap[],6:select[5:index:int:required]",
"lui-extension-v1|16:bottom-tab-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:10:cell-width:int:required:none,14:selected-index:int:required:none,5:inset:int:required:none,5:items:string:required:none|events:6:select[5:index:int:required]",
acceptsStandardChildren = true,
properties = listOf(
LuiExtensionProperty("cell-width", LuiExtensionValueKind.INTEGER, required = true),
Expand All @@ -272,7 +272,6 @@ fun logseqExtensionRegistry(
LuiExtensionProperty("items", LuiExtensionValueKind.STRING, required = true),
),
events = listOf(
LuiExtensionEventSchema("home-double-tap", emptyList()),
LuiExtensionEventSchema("select", listOf(LuiExtensionProperty("index", LuiExtensionValueKind.INTEGER, required = true))),
),
) {
Expand Down
43 changes: 5 additions & 38 deletions apple/Sources/Logseq/LGBottomTabStrip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct LGBottomTabStrip: View {
static func register(in registry: LUIAppleExtensionRegistry) throws {
try registry.register(LUIAppleExtension(
identifier: "bottom-tab-strip",
fingerprint: "lui-extension-v1|16:bottom-tab-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:10:cell-width:int:required:none,14:selected-index:int:required:none,5:inset:int:required:none,5:items:string:required:none|events:15:home-double-tap[],6:select[5:index:int:required]",
fingerprint: "lui-extension-v1|16:bottom-tab-strip|profiles:android/kotlin,ios/swiftui|standard-children:1|children:|properties:10:cell-width:int:required:none,14:selected-index:int:required:none,5:inset:int:required:none,5:items:string:required:none|events:6:select[5:index:int:required]",
acceptsStandardChildren: true,
properties: [
.init(name: "selected-index", kind: .int, isRequired: true),
Expand All @@ -29,7 +29,6 @@ struct LGBottomTabStrip: View {
],
events: [
.init(name: "select", fields: [.init(name: "index", kind: .int, isRequired: true)]),
.init(name: "home-double-tap", fields: []),
]
) { AnyView(LGBottomTabStrip(context: $0)) })
}
Expand All @@ -42,7 +41,7 @@ struct LGBottomTabStrip: View {
LGNativeBottomTabBar(
items: items, selectedIndex: selectedIndex,
tint: colors["link"], foreground: colors["foreground"], layoutDirection: layoutDirection,
horizontalMargin: horizontalMargin, context: context
context: context
)
// UITabBar reserves horizontal margins around its floating capsule.
.frame(width: CGFloat(items.count) * tabWidth + inset * 2 + 2 * horizontalMargin, height: 58)
Expand Down Expand Up @@ -80,11 +79,6 @@ struct LGBottomTabStrip: View {
.onGeometryChange(for: CGSize.self, of: \.size) { size = $0 }
.contentShape(Capsule())
.highPriorityGesture(tabDrag(count: count, cellWidth: cellWidth, inset: inset))
.simultaneousGesture(SpatialTapGesture(count: 2).onEnded { tap in
guard cellWidth > 0, horizontalPosition(tap.location.x) < inset + cellWidth,
context.isUserInteractionEnabled else { return }
try? context.emit(name: "home-double-tap")
})
.onChange(of: selected) { pendingSelection = nil }
#if os(iOS)
.background(LGSidebarPanExclusion())
Expand Down Expand Up @@ -206,22 +200,15 @@ private struct LGNativeBottomTabBar: UIViewRepresentable {
let tint: Color?
let foreground: Color?
let layoutDirection: LayoutDirection
let horizontalMargin: CGFloat
let context: LUIAppleExtensionViewContext

func makeCoordinator() -> Coordinator {
Coordinator(context: context, horizontalMargin: horizontalMargin)
Coordinator(context: context)
}

func makeUIView(context: Context) -> UITabBar {
let bar = UITabBar()
bar.delegate = context.coordinator
let doubleTap = UITapGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.doubleTapHome))
doubleTap.numberOfTapsRequired = 2
doubleTap.cancelsTouchesInView = false
doubleTap.delaysTouchesEnded = false
doubleTap.delegate = context.coordinator
bar.addGestureRecognizer(doubleTap)
return bar
}

Expand Down Expand Up @@ -254,16 +241,14 @@ private struct LGNativeBottomTabBar: UIViewRepresentable {
bar.semanticContentAttribute = layoutDirection == .rightToLeft ? .forceRightToLeft : .forceLeftToRight
}

@MainActor final class Coordinator: NSObject, UITabBarDelegate, UIGestureRecognizerDelegate {
@MainActor final class Coordinator: NSObject, UITabBarDelegate {
var context: LUIAppleExtensionViewContext
var items: [Item] = []
var unreadColors: [UIColor] = []
var selectedIndex: Int?
let horizontalMargin: CGFloat

init(context: LUIAppleExtensionViewContext, horizontalMargin: CGFloat) {
init(context: LUIAppleExtensionViewContext) {
self.context = context
self.horizontalMargin = horizontalMargin
}

func tabBar(_ tabBar: UITabBar, didSelect item: UITabBarItem) {
Expand All @@ -273,24 +258,6 @@ private struct LGNativeBottomTabBar: UIViewRepresentable {
tabBar.selectedItem = tabBar.items?.first(where: { $0.tag == selectedIndex })
}
}

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
guard let bar = gestureRecognizer.view as? UITabBar, items.first?.name == "home" else { return false }
let x = touch.location(in: bar).x
let leadingX = bar.effectiveUserInterfaceLayoutDirection == .rightToLeft ? bar.bounds.width - x : x
let itemWidth = (bar.bounds.width - 2 * horizontalMargin) / CGFloat(items.count)
return leadingX >= horizontalMargin && leadingX < horizontalMargin + itemWidth
}

func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer,
shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {
true
}

@objc func doubleTapHome() {
guard context.isUserInteractionEnabled else { return }
try? context.emit(name: "home-double-tap")
}
}
}
#endif
49 changes: 49 additions & 0 deletions apple/Sources/Logseq/LGComposerAttachmentRemove.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#if os(iOS)
import LUIAppleBackend
import SwiftUI

struct LGComposerAttachmentRemove: View {
let context: LUIAppleExtensionViewContext

static func register(in registry: LUIAppleExtensionRegistry) throws {
try registry.register(LUIAppleExtension(
identifier: "composer-attachment-remove",
fingerprint: "lui-extension-v1|26:composer-attachment-remove|profiles:ios/swiftui|standard-children:1|children:|properties:5:label:string:required:none|events:6:remove[]",
acceptsStandardChildren: true,
properties: [.init(name: "label", kind: .string, isRequired: true)],
events: [.init(name: "remove", fields: [])]
) { AnyView(LGComposerAttachmentRemove(context: $0)) })
}

var body: some View {
let _ = context.revision
context.content
.allowsHitTesting(false)
.overlay(alignment: .topTrailing) { removeButton }
}

private var removeButton: some View {
Button {
guard context.isUserInteractionEnabled else { return }
try? context.emit(name: "remove")
} label: {
Image(systemName: "xmark")
.font(.system(size: 11, weight: .semibold))
.foregroundStyle(.white)
.frame(width: 22, height: 22)
.background(.black.opacity(0.6), in: Circle())
.padding([.top, .trailing], 8)
.frame(width: 44, height: 44, alignment: .topTrailing)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityLabel(Text(verbatim: label))
.accessibilityIdentifier("composer.asset.remove")
}

private var label: String {
guard case let .string(label) = context.property("label") else { return "Remove attachment" }
return label
}
}
#endif
7 changes: 7 additions & 0 deletions apple/Sources/Logseq/LGLiquidGlassTweak.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,17 @@ struct LGBottomChromeSwitch: View {

private struct LGBottomBarActions: ViewModifier {
@Environment(\.lgUsesSideCaptureActions) private var usesSideCaptureActions
#if os(iOS)
@Environment(\.lgPlatformPresentation) private var presentation
#endif

func body(content: Content) -> some View {
if !usesSideCaptureActions {
content.modifier(LGBottomBarGlass(surface: .trailing))
#if os(iOS)
// A held Capture button can release after the picker has opened.
.disabled(presentation?.attachmentService == .quickPhotos)
#endif
}
}
}
Expand Down
121 changes: 100 additions & 21 deletions apple/Sources/Logseq/LGMediaPanel.swift
Original file line number Diff line number Diff line change
@@ -1,11 +1,82 @@
#if os(iOS)
import AVFoundation
import PhotosUI
@preconcurrency import PhotosUI
import SwiftUI
import UIKit
import UniformTypeIdentifiers
import ImageIO

struct LGQuickPhotoPicker: View {
let onPhoto: (Data, String) async throws -> Void
@Environment(\.dismiss) private var dismiss
@State private var selection: [PhotosPickerItem] = []
@State private var showAllPhotos = false
@State private var isImporting = false
@State private var importError: String?
@State private var pickerID = UUID()

var body: some View {
VStack(spacing: 4) {
HStack {
Button(role: .cancel) { dismiss() } label: {
Text("Cancel").frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
}
Spacer()
if isImporting {
ProgressView()
}
Spacer()
Button { showAllPhotos = true } label: {
Text("All Photos").frame(minWidth: 44, minHeight: 44)
.contentShape(Rectangle())
}
.photosPicker(isPresented: $showAllPhotos, selection: $selection,
maxSelectionCount: 1, matching: .images)
}
.padding(.horizontal, 20)
LGEmbeddedPhotos(importedIDs: [], compact: true) { results in
guard let photo = results.first else { return }
importPhoto { try await loadEmbeddedPhoto(photo) }
}
.id(pickerID)
.frame(height: 104)
.clipShape(.rect(cornerRadius: 14))
.padding(.horizontal, 12)
}
.frame(maxHeight: .infinity)
.disabled(isImporting)
.interactiveDismissDisabled(isImporting)
Comment on lines +48 to +49

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 No exit during photo loading

importPhoto blocks Cancel and swipe dismissal while it waits for the selected photo. With an iCloud-only photo, the wait can include a download.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

.onChange(of: selection) { _, items in
guard let item = items.first else { return }
importPhoto { try await item.loadImageForAttachment() }
}
.alert("Photo import failed", isPresented: Binding(
get: { importError != nil }, set: { if !$0 { importError = nil } }
)) {
Button("OK") { importError = nil }
} message: {
Text(importError ?? "")
}
}

private func importPhoto(load: @escaping () async throws -> (Data, String)) {
guard !isImporting else { return }
isImporting = true
Task {
do {
let (data, fileExtension) = try await load()
try await onPhoto(data, fileExtension)
} catch {
selection = []
pickerID = UUID()
importError = error.localizedDescription
}
isImporting = false
}
}
}

struct LGMediaPanel: View {
let initialService: LGAttachmentService
let onPhotos: ([PhotosPickerItem]) -> Void
Expand Down Expand Up @@ -137,21 +208,8 @@ struct LGMediaPanel: View {
Task { @MainActor in
for photo in photos {
do {
let provider = photo.itemProvider
guard let type = provider.registeredTypeIdentifiers.compactMap(UTType.init)
.first(where: { $0.conforms(to: .image) }) else {
throw CocoaError(.fileReadUnknown)
}
let data: Data = try await withCheckedThrowingContinuation { continuation in
provider.loadDataRepresentation(forTypeIdentifier: type.identifier) { data, error in
if let data { continuation.resume(returning: data) }
else { continuation.resume(throwing: error ?? CocoaError(.fileReadUnknown)) }
}
}
let imageType = CGImageSourceCreateWithData(data as CFData, nil)
.flatMap(CGImageSourceGetType).flatMap { UTType($0 as String) }
onPhotoData(data, imageType?.preferredFilenameExtension
?? type.preferredFilenameExtension ?? "jpg")
let (data, fileExtension) = try await loadEmbeddedPhoto(photo)
onPhotoData(data, fileExtension)
if let id = photo.assetIdentifier { importedPhotoIDs.insert(id) }
selectedPhotos.removeAll { $0.assetIdentifier == photo.assetIdentifier }
} catch {
Expand Down Expand Up @@ -179,25 +237,45 @@ struct LGMediaPanel: View {

}

@MainActor private func loadEmbeddedPhoto(_ photo: PHPickerResult) async throws -> (Data, String) {
let provider = photo.itemProvider
guard let type = provider.registeredTypeIdentifiers.compactMap(UTType.init)
.first(where: { $0.conforms(to: .image) }) else {
throw CocoaError(.fileReadUnknown)
}
let data: Data = try await withCheckedThrowingContinuation { continuation in
provider.loadDataRepresentation(forTypeIdentifier: type.identifier) { data, error in
if let data { continuation.resume(returning: data) }
else { continuation.resume(throwing: error ?? CocoaError(.fileReadUnknown)) }
}
}
let imageType = CGImageSourceCreateWithData(data as CFData, nil)
.flatMap(CGImageSourceGetType).flatMap { UTType($0 as String) }
return (data, imageType?.preferredFilenameExtension ?? type.preferredFilenameExtension ?? "jpg")
}

// Isolate the embedded picker from the surrounding SwiftUI sheet's presentation traits.
private struct LGEmbeddedPhotos: UIViewControllerRepresentable {
let importedIDs: Set<String>
var compact = false
let onSelection: ([PHPickerResult]) -> Void

func makeUIViewController(context: Context) -> Container {
Container(onSelection: onSelection)
Container(compact: compact, onSelection: onSelection)
}

func updateUIViewController(_ controller: Container, context: Context) {
controller.deselectImported(importedIDs)
}

final class Container: UIViewController, PHPickerViewControllerDelegate {
let compact: Bool
let onSelection: ([PHPickerResult]) -> Void
private var picker: PHPickerViewController?
private var importedIDs: Set<String> = []

init(onSelection: @escaping ([PHPickerResult]) -> Void) {
init(compact: Bool, onSelection: @escaping ([PHPickerResult]) -> Void) {
self.compact = compact
self.onSelection = onSelection
super.init(nibName: nil, bundle: nil)
}
Expand All @@ -208,8 +286,9 @@ private struct LGEmbeddedPhotos: UIViewControllerRepresentable {
super.viewDidLoad()
var configuration = PHPickerConfiguration(photoLibrary: .shared())
configuration.filter = .images
configuration.selectionLimit = 20
configuration.selection = .continuousAndOrdered
configuration.selectionLimit = compact ? 1 : 20
configuration.selection = compact ? .continuous : .continuousAndOrdered
configuration.mode = compact ? .compact : .default
configuration.edgesWithoutContentMargins = .all
configuration.disabledCapabilities = [.selectionActions]
let picker = PHPickerViewController(configuration: configuration)
Expand All @@ -225,7 +304,7 @@ private struct LGEmbeddedPhotos: UIViewControllerRepresentable {
picker.view.bottomAnchor.constraint(equalTo: view.bottomAnchor),
])
picker.didMove(toParent: self)
picker.zoomIn()
if !compact { picker.zoomIn() }
}

func deselectImported(_ identifiers: Set<String>) {
Expand Down
Loading
Loading