Repository navigation
iOS: stop open menus from flickering when their parent views re-render #8611
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
200 changes: 200 additions & 0 deletions
200
...iOS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Artifacts/ChatArtifactViewerActionsMenu.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| #if os(iOS) | ||
| import SwiftUI | ||
| import UIKit | ||
|
|
||
| struct ChatArtifactViewerActionsMenu: View, Equatable { | ||
| let value: ChatArtifactViewerActionsMenuValue | ||
| let actions: ChatArtifactViewerActionsMenuActions | ||
|
|
||
| nonisolated static func == (lhs: Self, rhs: Self) -> Bool { | ||
| lhs.value == rhs.value | ||
| } | ||
|
|
||
| private var snapshot: ChatArtifactViewerPageSnapshot { value.snapshot } | ||
|
|
||
| var body: some View { | ||
| Menu { | ||
| if snapshot.hasFileActions { | ||
| Section { | ||
| fileActionButtons | ||
| } | ||
| } | ||
| if snapshot.shouldShowTextJumpControls { | ||
| Section { | ||
| textViewerActionButtons | ||
| } | ||
| } | ||
| if snapshot.state == .markdown, | ||
| snapshot.markdownPresentation.isRenderedAvailable { | ||
| Section { | ||
| Picker( | ||
| String( | ||
| localized: "chat.artifact.markdown.view", | ||
| defaultValue: "Markdown view", | ||
| bundle: .module | ||
| ), | ||
| selection: Binding( | ||
| get: { snapshot.markdownPresentation.mode }, | ||
| set: { actions.selectMarkdownMode(snapshot.path, $0) } | ||
| ) | ||
| ) { | ||
| Text(String( | ||
| localized: "chat.artifact.markdown.raw", | ||
| defaultValue: "Raw", | ||
| bundle: .module | ||
| )) | ||
| .tag(ChatArtifactMarkdownMode.raw) | ||
| Text(String( | ||
| localized: "chat.artifact.markdown.rendered", | ||
| defaultValue: "Rendered", | ||
| bundle: .module | ||
| )) | ||
| .tag(ChatArtifactMarkdownMode.rendered) | ||
| } | ||
| } | ||
| } | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.viewer.actions", | ||
| defaultValue: "Viewer actions", | ||
| bundle: .module | ||
| ), | ||
| systemImage: "ellipsis.circle" | ||
| ) | ||
| } | ||
| .disabled(snapshot.fileActionState.isRunning) | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var fileActionButtons: some View { | ||
| Button { | ||
| actions.prepareShare(snapshot.path) | ||
| } label: { | ||
| Label( | ||
| String(localized: "chat.artifact.share", defaultValue: "Share", bundle: .module), | ||
| systemImage: "square.and.arrow.up" | ||
| ) | ||
| } | ||
| Button { | ||
| actions.prepareSave(snapshot.path) | ||
| } label: { | ||
| Label( | ||
| String(localized: "chat.artifact.save_to_files", defaultValue: "Save to Files", bundle: .module), | ||
| systemImage: "folder.badge.plus" | ||
| ) | ||
| } | ||
| if snapshot.isTextFile { | ||
| Button { | ||
| UIPasteboard.general.string = snapshot.renderedText | ||
| actions.notifyCopied() | ||
| } label: { | ||
| Label( | ||
| String(localized: "chat.artifact.copy_contents", defaultValue: "Copy contents", bundle: .module), | ||
| systemImage: "doc.on.doc" | ||
| ) | ||
| } | ||
| .disabled(!snapshot.canCopyContents) | ||
| } | ||
| Button { | ||
| UIPasteboard.general.string = snapshot.path | ||
| actions.notifyPathCopied() | ||
| } label: { | ||
| Label( | ||
| String(localized: "chat.artifact.copy_path", defaultValue: "Copy path", bundle: .module), | ||
| systemImage: "link" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private var textViewerActionButtons: some View { | ||
| Button { | ||
| withAnimation(.snappy) { | ||
| actions.toggleSearch(snapshot.path) | ||
| } | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.search.title", | ||
| defaultValue: "Search", | ||
| bundle: .module | ||
| ), | ||
| systemImage: "magnifyingglass" | ||
| ) | ||
| } | ||
| Button { | ||
| withAnimation(.snappy) { | ||
| actions.toggleGoToLine(snapshot.path) | ||
| } | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.line.goto", | ||
| defaultValue: "Go to line", | ||
| bundle: .module | ||
| ), | ||
| systemImage: "text.line.first.and.arrowtriangle.forward" | ||
| ) | ||
| } | ||
| Button { | ||
| actions.requestTop(snapshot.path) | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.jump.top", | ||
| defaultValue: "Top", | ||
| bundle: .module | ||
| ), | ||
| systemImage: "arrow.up.to.line" | ||
| ) | ||
| } | ||
| Button { | ||
| actions.requestBottom(snapshot.path) | ||
| } label: { | ||
| Label(jumpToEndTitle, systemImage: "arrow.down.to.line") | ||
| } | ||
| Button { | ||
| actions.toggleLineNumbers(snapshot.path) | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.line.numbers", | ||
| defaultValue: "Line numbers", | ||
| bundle: .module | ||
| ), | ||
| systemImage: snapshot.showsLineNumbers ? "checkmark" : "number" | ||
| ) | ||
| } | ||
| Button { | ||
| actions.toggleWordWrap(snapshot.path) | ||
| } label: { | ||
| Label( | ||
| String( | ||
| localized: "chat.artifact.wrap", | ||
| defaultValue: "Word wrap", | ||
| bundle: .module | ||
| ), | ||
| systemImage: snapshot.wrapsLines ? "checkmark" : "text.justify.left" | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| private var jumpToEndTitle: String { | ||
| switch ChatArtifactTextEndJumpTarget(reachedEOF: snapshot.textReachedEOF) { | ||
| case .end: | ||
| return String( | ||
| localized: "chat.artifact.jump.end", | ||
| defaultValue: "End", | ||
| bundle: .module | ||
| ) | ||
| case .latest: | ||
| return String( | ||
| localized: "chat.artifact.jump.latest", | ||
| defaultValue: "Latest", | ||
| bundle: .module | ||
| ) | ||
| } | ||
| } | ||
| } | ||
| #endif |
15 changes: 15 additions & 0 deletions
15
...xAgentChatUI/Sources/CmuxAgentChatUI/Artifacts/ChatArtifactViewerActionsMenuActions.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| #if os(iOS) | ||
| struct ChatArtifactViewerActionsMenuActions { | ||
| let prepareShare: (String) -> Void | ||
| let prepareSave: (String) -> Void | ||
| let toggleSearch: (String) -> Void | ||
| let toggleGoToLine: (String) -> Void | ||
| let requestTop: (String) -> Void | ||
| let requestBottom: (String) -> Void | ||
| let toggleLineNumbers: (String) -> Void | ||
| let toggleWordWrap: (String) -> Void | ||
| let selectMarkdownMode: (String, ChatArtifactMarkdownMode) -> Void | ||
| let notifyCopied: () -> Void | ||
| let notifyPathCopied: () -> Void | ||
| } | ||
| #endif |
8 changes: 8 additions & 0 deletions
8
...muxAgentChatUI/Sources/CmuxAgentChatUI/Artifacts/ChatArtifactViewerActionsMenuValue.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| #if os(iOS) | ||
| struct ChatArtifactViewerActionsMenuValue: Equatable, Sendable { | ||
| let snapshot: ChatArtifactViewerPageSnapshot | ||
| let loaderScope: ChatArtifactLoaderScope | ||
| let loaderSupportsArtifacts: Bool | ||
| let loaderSupportsDirectoryBrowsing: Bool | ||
| } | ||
| #endif | ||
2 changes: 1 addition & 1 deletion
2
...CmuxAgentChatUI/Sources/CmuxAgentChatUI/Artifacts/ChatArtifactViewerFileActionState.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...OS/CmuxAgentChatUI/Sources/CmuxAgentChatUI/Artifacts/ChatArtifactViewerPageSnapshot.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.