Skip to content
Open
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
56 changes: 53 additions & 3 deletions apple/Sources/Logseq/LGBottomTabStrip.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import SwiftUI
import UIKit
#endif

extension EnvironmentValues {
@Entry var lgPlacesTabsOnSide = false
@Entry var lgRendersSideTabs = false
}

@MainActor
struct LGBottomTabStrip: View {
let context: LUIAppleExtensionViewContext
Expand All @@ -12,6 +17,8 @@ struct LGBottomTabStrip: View {
@Environment(\.layoutDirection) private var layoutDirection
@Environment(\.accessibilityReduceMotion) private var reduceMotion
@Environment(\.accessibilityReduceTransparency) private var reduceTransparency
@Environment(\.lgPlacesTabsOnSide) private var placesTabsOnSide
@Environment(\.lgRendersSideTabs) private var rendersSideTabs
@GestureState private var dragPosition: CGFloat?
@State private var pendingSelection: Int?
@State private var size: CGSize = .zero
Expand All @@ -37,7 +44,9 @@ struct LGBottomTabStrip: View {
@ViewBuilder var body: some View {
let _ = context.revision
#if os(iOS)
if #available(iOS 26.0, *), let items = nativeItems {
if rendersSideTabs, let items = nativeItems {
sideStrip(items)
} else if !placesTabsOnSide, #available(iOS 26.0, *), let items = nativeItems {
let horizontalMargin: CGFloat = 21
LGNativeBottomTabBar(
items: items, selectedIndex: selectedIndex,
Expand All @@ -50,7 +59,7 @@ struct LGBottomTabStrip: View {
.background(LGSidebarPanExclusion())
// Align the floating items within UITabBar with the trailing actions.
.offset(y: 11)
} else {
} else if !placesTabsOnSide {
fallbackStrip
}
#else
Expand Down Expand Up @@ -93,6 +102,47 @@ struct LGBottomTabStrip: View {
}

#if os(iOS)
private func sideStrip(_ items: [LGNativeBottomTabBar.Item]) -> some View {
let primary = colors["foreground"] ?? .primary
let accent = colors["link"] ?? .accentColor
return VStack(spacing: 2) {
ForEach(items.indices, id: \.self) { index in
let item = items[index]
let selected = index == selectedIndex
Button {
guard context.isUserInteractionEnabled else { return }
try? context.emit(name: "select", values: ["index": .int(index)])
} label: {
if let icon = item.icon(selected ? item.selectedImage : item.image,
foreground: UIColor(primary), accent: UIColor(accent)) {
Image(uiImage: icon)
.renderingMode(item.unread == true ? .original : .template)
.font(.system(size: 23))
.foregroundStyle(selected ? accent : primary)
.frame(width: 44, height: 44)
.background {
if selected { indicator(dragging: false) }
}
.contentShape(Rectangle())
}
}
.buttonStyle(.plain)
.accessibilityLabel(item.title)
.accessibilityIdentifier("tab.bottom.\(item.name)")
.accessibilityAddTraits(selected ? .isSelected : [])
.simultaneousGesture(TapGesture(count: 2).onEnded {
guard item.name == "home", context.isUserInteractionEnabled else { return }
try? context.emit(name: "home-double-tap")
})
}
}
.padding(.horizontal, 2)
.padding(.vertical, 4)
.modifier(LGLiquidGlassSurface(shape: .capsule))
.accessibilityElement(children: .contain)
.accessibilityIdentifier("group.side.tabs")
}

private var nativeItems: [LGNativeBottomTabBar.Item]? {
guard case let .string(json) = context.property("items") else { return nil }
return try? JSONDecoder().decode([LGNativeBottomTabBar.Item].self, from: Data(json.utf8))
Expand Down Expand Up @@ -175,7 +225,7 @@ private struct LGNativeBottomTabBar: UIViewRepresentable {
item.accessibilityIdentifier = "tab.bottom.\(name)"
}

@MainActor private func icon(_ iconName: String, foreground: UIColor, accent: UIColor) -> UIImage? {
@MainActor func icon(_ iconName: String, foreground: UIColor, accent: UIColor) -> UIImage? {
switch LGIconPolicy.icons[iconName] {
case let .systemName(symbol):
if name == "notifications",
Expand Down
186 changes: 186 additions & 0 deletions apple/Sources/Logseq/LGDuoJournalBook.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
#if os(iOS)
import LUIAppleBackend
import SwiftUI
import UIKit

@available(iOS 18.0, *)
@MainActor
private struct LGDuoJournalPages: View {
let context: LUIAppleExtensionViewContext
let pages: [Int]
let width: CGFloat
let height: CGFloat
@State private var position: Int?
@Environment(\.layoutDirection) private var layoutDirection
@Environment(\.accessibilityReduceMotion) private var reduceMotion

private var first: Int { context.property("first-index")?.intValue ?? 0 }
private var selected: Int { context.property("selected-index")?.intValue ?? 0 }
private var canTurn: Bool { context.property("can-turn") != .bool(false) }

var body: some View {
let pageTurnAngle = reduceMotion ? 0.0 : 4.0
ScrollView(.horizontal) {
LazyHStack(spacing: 0) {
ForEach(Array(pages.enumerated().reversed()), id: \.element) { offset, node in
context.nodeView(of: node)
.frame(width: width, height: height)
.overlay { spineShade }
.scrollTransition(.interactive, axis: .horizontal) { spread, phase in
spread.rotation3DEffect(
.degrees(-phase.value * pageTurnAngle),
axis: (x: 0, y: 1, z: 0),
anchor: phase.value < 0 ? .trailing : .leading,
perspective: 0.30
)
}
.environment(\.layoutDirection, layoutDirection)
.accessibilityHidden(first + offset != selected)
.id(first + offset)
}
}
.scrollTargetLayout()
.background(LGJournalPagingPan(enabled: canTurn))
}
.defaultScrollAnchor(.trailing)
.scrollTargetBehavior(.viewAligned(limitBehavior: .alwaysByOne))
.scrollIndicators(.hidden)
.clipped()
.scrollPosition(id: $position)
.onChange(of: selected, initial: true) { _, index in
if position != index { position = index }
}
.onScrollPhaseChange { _, phase in
if phase == .idle { select(position) }
}
.onChange(of: canTurn) { _, enabled in
if !enabled { position = selected }
}
.accessibilityScrollAction { edge in
switch edge {
case .leading: select(selected + 1)
case .trailing: select(selected - 1)
default: break
}
}
// Page positions are chronological. The notes themselves still use the app language.
.environment(\.layoutDirection, .leftToRight)
.accessibilityIdentifier("journal.duo.book")
}

private var spineShade: some View {
LinearGradient(
stops: [
.init(color: .clear, location: 0),
.init(color: .primary.opacity(0.07), location: 0.50),
.init(color: .clear, location: 1),
],
startPoint: .leading,
endPoint: .trailing
)
.frame(width: 14)
.allowsHitTesting(false)
.accessibilityHidden(true)
}

private func select(_ index: Int?) {
guard canTurn, let index,
index != selected, (first..<(first + pages.count)).contains(index) else { return }
try? context.emit(name: "select", values: ["index": .int(index)])
}
}

// Suspend the horizontal gesture while leaving both notes free to scroll vertically.
private struct LGJournalPagingPan: UIViewRepresentable {
let enabled: Bool

func makeUIView(context: Context) -> Marker {
let view = Marker()
view.isUserInteractionEnabled = false
return view
}

func updateUIView(_ view: Marker, context: Context) {
view.enabled = enabled
view.updatePan()
}

static func dismantleUIView(_ view: Marker, coordinator: ()) {
view.pan?.isEnabled = true
}

final class Marker: UIView {
var enabled = true
weak var pan: UIPanGestureRecognizer?

override func didMoveToSuperview() {
super.didMoveToSuperview()
updatePan()
}

func updatePan() {
var ancestor = superview
while let view = ancestor {
if let scroll = view as? UIScrollView {
pan = scroll.panGestureRecognizer
pan?.isEnabled = enabled
return
}
ancestor = view.superview
}
}
}
}

@MainActor
struct LGDuoJournalBook: View {
static let identifier = "duo-journal-book"
let context: LUIAppleExtensionViewContext

static func register(in registry: LUIAppleExtensionRegistry) throws {
try registry.register(LUIAppleExtension(
identifier: identifier,
fingerprint: "lui-extension-v1|16:duo-journal-book|profiles:ios/swiftui|standard-children:1|children:|properties:8:can-turn:bool:required:none,11:first-index:int:required:none,14:selected-index:int:required:none|events:6:resize[5:width:int:required],6:select[5:index:int:required]",
acceptsStandardChildren: true,
properties: [
.init(name: "can-turn", kind: .bool, isRequired: true),
.init(name: "first-index", kind: .int, isRequired: true),
.init(name: "selected-index", kind: .int, isRequired: true),
],
events: [
.init(name: "resize", fields: [.init(name: "width", kind: .int, isRequired: true)]),
.init(name: "select", fields: [.init(name: "index", kind: .int, isRequired: true)]),
]
) { AnyView(LGDuoJournalBook(context: $0)) })
}

var body: some View {
let _ = context.revision
let children = context.childIDs
if #available(iOS 18.0, *), LGSidebarOverlay.isDuo, children.count == 2 {
GeometryReader { geometry in
let _ = context.measureStamp(of: children[1])
let spreads = context.childIDs(of: children[1])
if geometry.size.width >= 600, !spreads.isEmpty {
LGDuoJournalPages(context: context, pages: spreads,
width: geometry.size.width, height: geometry.size.height)
} else {
context.content(for: children[0])
}
}
.onGeometryChange(for: Bool.self) { $0.size.width >= 600 } action: { wide in
try? context.emit(name: "resize", values: ["width": .int(wide ? 600 : 0)])
}
} else if let classic = children.first {
context.content(for: classic)
}
}
}

private extension LUIExtensionValue {
var intValue: Int? {
if case let .int(value) = self { return value }
return nil
}
}
#endif
53 changes: 45 additions & 8 deletions apple/Sources/Logseq/LGNavigationExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,9 @@ private struct LGNavigationContent: View {
@Environment(\.luiSemanticColors) private var semanticColors
@Environment(\.locale) private var locale
@Environment(\.accessibilityReduceMotion) private var reduceMotion
#if os(iOS)
@Environment(\.horizontalSizeClass) private var horizontalSizeClass
#endif

private var search: LGNativeSearchState? { toolbarStartIndex == nil ? nil : inheritedSearch }
private func nativeSearchHost(_ search: LGNativeSearchState?) -> LGNativeSearchHost {
Expand All @@ -768,6 +771,17 @@ private struct LGNavigationContent: View {
}
private var searchVisible: Bool { search?.isVisible == true }
private var verticalToolbar: Bool { verticalToolbarEdge != nil }
private var usesUnfoldedDuoHeading: Bool {
#if os(iOS)
return verticalToolbar && LGSidebarOverlay.isDuo && horizontalSizeClass == .regular
#else
return false
#endif
}

private var showsVerticalRootHeading: Bool {
verticalToolbar && toolbarStartIndex != nil && !pdfWorkspaceOpen
}
private var searchRoutes: [Int] {
guard searchVisible, let search else { return [] }
return pageRoutes(in: search.context, depth: search.depth)
Expand Down Expand Up @@ -799,6 +813,16 @@ private struct LGNavigationContent: View {
verticalToolbar && !selectionActive && hasCollapsedComposer && captureActionIDs.count == 4
}

private var sideTabsID: Int? {
guard usesSideCaptureActions, let index = bottomChromeIndex, let chrome = childID(at: index) else { return nil }
func tabStrip(in node: Int) -> Int? {
if context.extensionIdentifier(of: node) == "bottom-tab-strip" { return node }
let _ = context.measureStamp(of: node)
return context.childIDs(of: node).lazy.compactMap(tabStrip(in:)).first
}
return tabStrip(in: chrome)
}

private var rootTitleContent: Int? {
guard let toolbarStartIndex,
let titleSlot = childID(at: toolbarStartIndex + 1) else { return nil }
Expand Down Expand Up @@ -1119,14 +1143,15 @@ private struct LGNavigationContent: View {
@ViewBuilder
private var rootNavigationSurface: some View {
let base = AnyView(transformedRootContent.safeAreaInset(edge: .top, spacing: 0) {
if verticalToolbar, toolbarStartIndex != nil {
// A principal item would create a second, horizontal bar on Duo.
let hideTitle = searchVisible || pdfWorkspaceOpen
if showsVerticalRootHeading {
// Keep the heading inside the active pane so the graph menu remains tappable.
rootHeaderTitle
.frame(maxWidth: .infinity, minHeight: 44)
.opacity(hideTitle ? 0 : 1)
.allowsHitTesting(!hideTitle)
.accessibilityHidden(hideTitle)
.frame(maxWidth: .infinity, minHeight: 44,
alignment: usesUnfoldedDuoHeading ? .leading : .center)
.padding(.horizontal, 16)
.opacity(searchVisible ? 0 : 1)
.allowsHitTesting(!searchVisible)
.accessibilityHidden(searchVisible)
}
})
withAppTint(searchSurface(base, active: path.isEmpty))
Expand All @@ -1141,7 +1166,7 @@ private struct LGNavigationContent: View {
.background {
if toolbarStartIndex != nil {
LGCaptureRailHost(
content: AnyView(captureRail
content: AnyView(sideControls
.environment(\.luiSemanticColors, semanticColors)
.environment(\.locale, locale)
.environment(\.colorScheme, colorScheme)),
Expand All @@ -1154,6 +1179,17 @@ private struct LGNavigationContent: View {
#endif
}

private var sideControls: some View {
VStack(spacing: 9) {
captureRail
if let tabs = sideTabsID {
context.nodeView(of: tabs)
.environment(\.lgRendersSideTabs, true)
}
}
.fixedSize()
}

private var captureRail: some View {
VStack(spacing: 14) {
ForEach(captureActionIDs, id: \.self) { actionID in
Expand Down Expand Up @@ -1423,6 +1459,7 @@ private struct LGNavigationContent: View {
private var floatingBottomChrome: some View {
sizedBottomChrome
.environment(\.lgUsesSideCaptureActions, usesSideCaptureActions)
.environment(\.lgPlacesTabsOnSide, sideTabsID != nil)
.fixedSize(horizontal: false, vertical: true)
}

Expand Down
Loading
Loading