diff --git a/Packages/iOS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Composer/ChatAccessoryChipRow.swift b/Packages/iOS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Composer/ChatAccessoryChipRow.swift index acc2f01c8367..e5602e87351d 100644 --- a/Packages/iOS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Composer/ChatAccessoryChipRow.swift +++ b/Packages/iOS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Composer/ChatAccessoryChipRow.swift @@ -4,12 +4,17 @@ import SwiftUI /// The horizontal shortcut row above the composer field. public struct ChatAccessoryChipRow: View { + private static let scrollEdgeFadeWidth: 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: @@ -49,27 +54,18 @@ public struct ChatAccessoryChipRow: View { chip(shortcut) } } - // Inset the row content slightly so the fade reveals/clips - // 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 + } + .padding(.horizontal, scrollNeedsEdgeFade ? Self.scrollEdgeFadeWidth : 2) } .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. + .onGeometryChange(for: CGFloat.self, of: { $0.size.width }) { width in + scrollViewportWidth = width + } .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 - ) + scrollEdgeFadeMask } } } @@ -100,6 +96,10 @@ public struct ChatAccessoryChipRow: View { !leadingShortcuts.isEmpty || !shortcuts.isEmpty } + private var scrollNeedsEdgeFade: Bool { + scrollContentWidth > scrollViewportWidth + 1 + } + private var stopShortcut: ChatAccessoryShortcut { ChatAccessoryShortcut( id: "chat.chip.stop", @@ -169,4 +169,31 @@ public struct ChatAccessoryChipRow: View { Text(shortcut.title) } } + + @ViewBuilder + private var scrollEdgeFadeMask: some View { + if scrollNeedsEdgeFade { + HStack(spacing: 0) { + LinearGradient( + colors: [.clear, .black], + startPoint: .leading, + endPoint: .trailing + ) + .frame(width: Self.scrollEdgeFadeWidth) + + Rectangle() + .fill(.black) + + LinearGradient( + colors: [.black, .clear], + startPoint: .leading, + endPoint: .trailing + ) + .frame(width: Self.scrollEdgeFadeWidth) + } + } else { + Rectangle() + .fill(.black) + } + } } diff --git a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/AgentChatDemoScreen.swift b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/AgentChatDemoScreen.swift index b2abac12e856..f0d9d234f65c 100644 --- a/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/AgentChatDemoScreen.swift +++ b/Packages/iOS/CmuxMobileShellUI/Sources/CmuxMobileShellUI/AgentChatDemoScreen.swift @@ -2,6 +2,7 @@ import CmuxAgentChat import CmuxAgentChatUI import CmuxMobileSupport +import CmuxMobileTerminal import Foundation import SwiftUI @@ -113,11 +114,22 @@ struct AgentChatDemoScreen: View { } private func baseChatScreen(for stack: DemoStack) -> some View { - ChatScreen( - store: stack.store, - providesOwnChrome: false, - onOpenTerminal: {} - ) + switch style { + case .standalone: + ChatScreen( + store: stack.store, + providesOwnChrome: false, + onOpenTerminal: {} + ) + case .inlineWorkspace: + ChatScreen( + store: stack.store, + accessoryLeadingShortcuts: previewLeadingShortcuts, + accessoryShortcuts: previewScrollableShortcuts(for: stack), + providesOwnChrome: false, + onOpenTerminal: {} + ) + } } private func header(for stack: DemoStack) -> some View { @@ -131,6 +143,60 @@ struct AgentChatDemoScreen: View { ) } + private var previewLeadingShortcuts: [ChatAccessoryShortcut] { + [ + ChatAccessoryShortcut( + id: "terminal.inputAccessory.hideKeyboard", + title: "", + systemImage: "keyboard.chevron.compact.down", + accessibilityLabel: L10n.string( + "terminal.input_accessory.hideKeyboard", + defaultValue: "Hide Keyboard" + ), + tint: .secondary, + semanticAction: .dismissKeyboard + ) {}, + ChatAccessoryShortcut( + id: "terminal.inputAccessory.composer", + title: "", + systemImage: "terminal", + accessibilityLabel: L10n.string( + "mobile.terminal.select", + defaultValue: "Terminal" + ) + ) {}, + ] + } + + private func previewScrollableShortcuts(for stack: DemoStack) -> [ChatAccessoryShortcut] { + TerminalInputAccessoryAction.defaultConfigurableOrder.compactMap { action in + guard action.isSupportedInAgentChat else { return nil } + return ChatAccessoryShortcut( + id: action.accessibilityIdentifier, + title: action.title(isMacRemote: true), + systemImage: action.symbolName, + accessibilityLabel: action.accessibilityLabel ?? action.settingsDisplayName, + semanticAction: action == .paste ? .paste : nil + ) { + performPreviewShortcut(action, store: stack.store) + } + } + } + + private func performPreviewShortcut( + _ action: TerminalInputAccessoryAction, + store: ChatConversationStore + ) { + switch action { + case .escape: + Task { await store.interrupt(hard: false) } + case .ctrlC: + Task { await store.interrupt(hard: true) } + default: + break + } + } + private var inlineWorkspaceTitle: String? { guard style == .inlineWorkspace else { return nil } return UITestConfig.value(