Skip to content
Merged
Changes from 1 commit
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 @@ -4,12 +4,17 @@ import SwiftUI

/// The horizontal shortcut row above the composer field.
public struct ChatAccessoryChipRow: View {
private static let scrollEdgeBlurWidth: CGFloat = 34

private let agentState: ChatAgentState
private let leadingShortcuts: [ChatAccessoryShortcut]
private let shortcuts: [ChatAccessoryShortcut]
private let onInterrupt: (Bool) -> Void
private let onOpenTerminal: () -> Void

@State private var scrollContentWidth: CGFloat = 0
@State private var scrollViewportWidth: CGFloat = 0

/// Creates the chip row.
///
/// - Parameters:
Expand Down Expand Up @@ -53,23 +58,24 @@ public struct ChatAccessoryChipRow: View {
// chips rather than cropping the very first/last chip flush
// at the edge.
.padding(.horizontal, 2)
.onGeometryChange(for: CGFloat.self, of: { $0.size.width }) { width in
scrollContentWidth = width
}
}
.frame(height: 32)
.layoutPriority(1)
// Soft horizontal scroll-edge fade so chips dissolve at the
// margins instead of being hard-clipped by the scroll view's
// straight edge.
.mask {
LinearGradient(
stops: [
.init(color: .clear, location: 0),
.init(color: .black, location: 0.035),
.init(color: .black, location: 0.965),
.init(color: .clear, location: 1),
],
startPoint: .leading,
endPoint: .trailing
)
.onGeometryChange(for: CGFloat.self, of: { $0.size.width }) { width in
scrollViewportWidth = width
}
.overlay(alignment: .leading) {
if scrollNeedsEdgeBlur {
scrollEdgeBlur(isLeading: true)
}
}
.overlay(alignment: .trailing) {
if scrollNeedsEdgeBlur {
scrollEdgeBlur(isLeading: false)
}
}

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.

P1 Leading blur visible at scroll position 0

Both curtains appear whenever scrollNeedsEdgeBlur is true, but at the initial scroll position (0) there is no content hidden behind the leading edge — the first chip is right at the left boundary. The 34pt leading curtain will overlap and visually obscure the first chip(s) for every overflowing row before the user has scrolled right at all, which is the common case. Only the trailing curtain is correct at position 0; the leading one should only appear once scrollOffset > 0. Tracking scroll position (e.g. via ScrollPosition on iOS 17+, or a preference-key offset reader) is needed to gate isLeading: true independently of isLeading: false.

}
}
Expand Down Expand Up @@ -100,6 +106,10 @@ public struct ChatAccessoryChipRow: View {
!leadingShortcuts.isEmpty || !shortcuts.isEmpty
}

private var scrollNeedsEdgeBlur: Bool {
scrollContentWidth > scrollViewportWidth + 1
}

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.

P2 The scrollContentWidth measurement is taken on the view after .padding(.horizontal, 2) is applied, so it is always 4pt wider than the raw chip content. When compared against scrollViewportWidth with a tolerance of only + 1, this means the blur curtains can appear even when the chips fit the viewport exactly (4pt padding > 1pt tolerance). Subtracting the padding from the content measurement corrects the comparison.

Suggested change
private var scrollNeedsEdgeBlur: Bool {
scrollContentWidth > scrollViewportWidth + 1
}
private var scrollNeedsEdgeBlur: Bool {
// scrollContentWidth is measured on the padded HStack (2pt on each side = 4pt total),
// so subtract the padding before comparing to the bare viewport width.
scrollContentWidth - 4 > scrollViewportWidth + 1
}

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!


private var stopShortcut: ChatAccessoryShortcut {
ChatAccessoryShortcut(
id: "chat.chip.stop",
Expand Down Expand Up @@ -169,4 +179,22 @@ public struct ChatAccessoryChipRow: View {
Text(shortcut.title)
}
}

private func scrollEdgeBlur(isLeading: Bool) -> some View {
Rectangle()
.fill(.regularMaterial)
.frame(width: Self.scrollEdgeBlurWidth)
.mask {
LinearGradient(
stops: [
.init(color: isLeading ? .black : .clear, location: 0),
.init(color: isLeading ? .black : .clear, location: 0.18),
.init(color: isLeading ? .clear : .black, location: 1),
],
startPoint: .leading,
endPoint: .trailing
)
}
.allowsHitTesting(false)
}
}
Loading