Skip to content
Open
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
50 changes: 29 additions & 21 deletions Sources/Pesty/UI/BarView.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import SwiftUI

struct BarView: View {
private static let stripTopInset: CGFloat = 16
private static let stripBottomInset: CGFloat = 26

@Bindable private var store = ClipboardStore.shared
@Bindable private var settings = Settings.shared

Expand Down Expand Up @@ -87,31 +90,36 @@ struct BarView: View {
}

private var strip: some View {
ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(spacing: Theme.cardSpacing) {
ForEach(Array(store.visibleItems.enumerated()), id: \.element.id) { index, item in
ClipCardView(item: item,
index: index,
selected: item.id == store.selectedID)
.id(item.id)
.transition(.asymmetric(
insertion: .scale(scale: 0.92).combined(with: .opacity),
removal: .opacity))
GeometryReader { geometry in
let cardHeight = max(1, geometry.size.height - Self.stripTopInset - Self.stripBottomInset)

ScrollViewReader { proxy in
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack(alignment: .top, spacing: Theme.cardSpacing) {
ForEach(Array(store.visibleItems.enumerated()), id: \.element.id) { index, item in
ClipCardView(item: item,
index: index,
selected: item.id == store.selectedID)
.frame(height: cardHeight)
.id(item.id)
.transition(.asymmetric(
insertion: .scale(scale: 0.92).combined(with: .opacity),
removal: .opacity))
}
}
.padding(.horizontal, 18)
.padding(.top, Self.stripTopInset)
.padding(.bottom, Self.stripBottomInset)
.animation(.spring(response: 0.34, dampingFraction: 0.8), value: store.visibleItems.count)
}
.padding(.horizontal, 18)
.padding(.top, 4)
.padding(.bottom, 18)
.animation(.spring(response: 0.34, dampingFraction: 0.8), value: store.visibleItems.count)
}
.onChange(of: store.selectedID) { _, id in
guard let id else { return }
withAnimation(.spring(response: 0.3, dampingFraction: 0.78)) {
proxy.scrollTo(id, anchor: .center)
.onChange(of: store.selectedID) { _, id in
guard let id else { return }
withAnimation(.spring(response: 0.3, dampingFraction: 0.78)) {
proxy.scrollTo(id, anchor: .center)
}
}
.overlay { if store.visibleItems.isEmpty { emptyState } }
}
.overlay { if store.visibleItems.isEmpty { emptyState } }
}
.frame(maxHeight: .infinity)
}
Expand Down