Repository navigation
Fix mobile chat shortcut scroll edge blur #7051
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
e857082
07aa5f4
ea79f27
f474e4a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -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: | ||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
@@ -100,6 +106,10 @@ public struct ChatAccessoryChipRow: View { | |||||||||||||||||
| !leadingShortcuts.isEmpty || !shortcuts.isEmpty | ||||||||||||||||||
| } | ||||||||||||||||||
|
|
||||||||||||||||||
| private var scrollNeedsEdgeBlur: Bool { | ||||||||||||||||||
| scrollContentWidth > scrollViewportWidth + 1 | ||||||||||||||||||
| } | ||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
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", | ||||||||||||||||||
|
|
@@ -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) | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both curtains appear whenever
scrollNeedsEdgeBluris 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 oncescrollOffset > 0. Tracking scroll position (e.g. viaScrollPositionon iOS 17+, or a preference-key offset reader) is needed to gateisLeading: trueindependently ofisLeading: false.