-
Notifications
You must be signed in to change notification settings - Fork 24
feat: large document previews - WPB-21022 #3785
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
Open
OlivellaO
wants to merge
5
commits into
develop
Choose a base branch
from
feature/large-document-previews
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
b0b1426
extract header part from WireCellsDocumentAttachmentPreview
OlivellaO 7697cf1
add subline2 style to WireTextStyle
OlivellaO e40a8c3
new WireCellsLargeDodumentPreviewView
OlivellaO cff4011
update WireCellsAttachmentsPreviewItemView to use new large documents…
OlivellaO 99cbb32
update UI snapshot test for WireTextStyleMapping
OlivellaO 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
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
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
137 changes: 137 additions & 0 deletions
137
...ingUI/WireCells/Components/AttachmentsPreviewView/WireCellsLargeDocumentPreviewView.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,137 @@ | ||
| // | ||
| // Wire | ||
| // Copyright (C) 2025 Wire Swiss GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see http://www.gnu.org/licenses/. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import WireDesign | ||
| import WireFoundation | ||
|
|
||
| struct WireCellsLargeDocumentPreviewView: View { | ||
| private static let imageAspectRatio = CGFloat(8.0 / 3.0) | ||
| private static let errorMessage = L10n.Localizable.Conversation.Message.Attachment.previewNotAvailable | ||
| private static let downloadErrorMessage = L10n.Localizable.Conversation.Message.Attachment.unableToDownload | ||
| private static let loadingMessage = L10n.Localizable.Conversation.Message.Attachment.loadingContent | ||
|
|
||
| let headerIcon: Image | ||
| let headerText: String | ||
| let labelText: String | ||
| let progress: Double? | ||
| let downloadError: Bool | ||
| let url: URL? | ||
|
|
||
| var body: some View { | ||
| WireCellsAttachmentPreview( | ||
| progress: progress, | ||
| progressColor: downloadError | ||
| ? ColorTheme.Base.error.color : ColorTheme.Base.primary.color | ||
| ) { | ||
| VStack { | ||
| WireCellsDocumentHeaderView( | ||
| headerIcon: headerIcon, | ||
| headerText: headerText, | ||
| labelText: labelText, | ||
| progress: progress, | ||
| isError: downloadError | ||
| ) | ||
| .background(ColorTheme.Backgrounds.surfaceVariant.color) | ||
| .frame(height: 74) // This might break the UI if text font is too big | ||
| .frame(maxWidth: .infinity) | ||
WilhelmOks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| previewContainer { | ||
| if downloadError { | ||
| errorView(text: Self.downloadErrorMessage) | ||
| } else { | ||
| if let url { | ||
| asyncImage(url: url) | ||
| } else { | ||
| errorView(text: Self.errorMessage) | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func asyncImage(url: URL) -> some View { | ||
| AsyncImage(url: url) { phase in | ||
| switch phase { | ||
| case .empty: | ||
| loadingView(text: Self.loadingMessage) | ||
| case let .success(image): | ||
| image | ||
| .resizable() | ||
| .scaledToFill() | ||
| case .failure: | ||
| errorView(text: Self.errorMessage) | ||
| @unknown default: | ||
| EmptyView() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func previewContainer(@ViewBuilder content: () -> some View) | ||
| -> some View { | ||
| Color.clear | ||
| .aspectRatio(Self.imageAspectRatio, contentMode: .fit) | ||
| .background(alignment: .top) { | ||
| content() | ||
| } | ||
| .clipped() | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func loadingView(text: String) -> some View { | ||
| ZStack { | ||
| Color(ColorTheme.Backdrop.background) | ||
| VStack { | ||
| ProgressView() | ||
| Text(text) | ||
| .wireTextStyle(.subline2) | ||
| .foregroundColor(ColorTheme.Backgrounds.surface.color) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func errorView(text: String) -> some View { | ||
| ZStack { | ||
| Color(ColorTheme.Backdrop.background) | ||
| Text(text) | ||
| .wireTextStyle(.subline2) | ||
| .foregroundColor(ColorTheme.Backgrounds.surface.color) | ||
| .multilineTextAlignment(.center) | ||
| .padding() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| WireCellsLargeDocumentPreviewView( | ||
| headerIcon: Image(FileIcon.pdf.resource), | ||
| headerText: "PDF (336 KB)", | ||
| labelText: "CDR_20220120 Accessibility Review Reviewed Final Plus", | ||
| progress: 0.7, | ||
| downloadError: false, | ||
| url: URL( | ||
| string: | ||
| "https://i.kym-cdn.com/entries/icons/facebook/000/018/012/this_is_fine.jpg" | ||
| ) | ||
| ) | ||
| .environment(\.wireTextStyleMapping, WireTextStyleMapping()) | ||
| } | ||
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
87 changes: 87 additions & 0 deletions
87
...g/Sources/WireMessagingUI/WireCells/Components/Previews/WireCellsDocumentHeaderView.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,87 @@ | ||
| // | ||
| // Wire | ||
| // Copyright (C) 2025 Wire Swiss GmbH | ||
| // | ||
| // This program is free software: you can redistribute it and/or modify | ||
| // it under the terms of the GNU General Public License as published by | ||
| // the Free Software Foundation, either version 3 of the License, or | ||
| // (at your option) any later version. | ||
| // | ||
| // This program is distributed in the hope that it will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| // GNU General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU General Public License | ||
| // along with this program. If not, see http://www.gnu.org/licenses/. | ||
| // | ||
|
|
||
| import SwiftUI | ||
| import WireDesign | ||
| import WireFoundation | ||
|
|
||
| struct WireCellsDocumentHeaderView: View { | ||
| enum Constants { | ||
| static let errorColor = ColorTheme.Base.error.color | ||
WilhelmOks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @ScaledMetric private var scale: CGFloat = 1 | ||
|
|
||
| let headerIcon: Image | ||
| let headerText: String | ||
| let labelText: String | ||
| let progress: Double? | ||
| let isError: Bool | ||
|
|
||
| var body: some View { | ||
| header() | ||
| } | ||
|
|
||
| @ViewBuilder | ||
| private func header() -> some View { | ||
| VStack(alignment: .leading) { | ||
| HStack(spacing: 4) { | ||
| if isError { | ||
| Image(systemName: "exclamationmark.triangle") | ||
| .fontWeight(.semibold) | ||
| .font(.system(size: 14 * scale)) | ||
| .foregroundStyle(Constants.errorColor) | ||
| } else { | ||
| headerIcon | ||
| .resizable() | ||
| .aspectRatio(contentMode: .fit) | ||
| .frame(height: 16 * scale) | ||
| } | ||
|
|
||
| Text(headerText) | ||
| .foregroundStyle(ColorTheme.Base.secondaryText.color) | ||
| .wireTextStyle(.subline1) | ||
| .lineLimit(1) | ||
|
|
||
| Spacer() | ||
| } | ||
| .padding([.horizontal, .top], 8) | ||
|
|
||
| Spacer(minLength: 0) | ||
|
|
||
| Text(labelText) | ||
| .foregroundStyle(ColorTheme.Backgrounds.onSurfaceVariant.color) | ||
| .wireTextStyle(.h5) | ||
| .lineLimit(2) | ||
| .frame(maxWidth: .infinity, alignment: .leading) | ||
| .padding([.horizontal, .bottom], 8) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #Preview { | ||
| WireCellsDocumentHeaderView( | ||
| headerIcon: Image(FileIcon.pdf.resource), | ||
| headerText: "PDF (336 KB)", | ||
| labelText: "CDR_20220120 Accessibility Review Reviewed Final Plus", | ||
| progress: 0.7, | ||
| isError: false | ||
| ) | ||
| .frame(width: 222, height: 74) | ||
| .environment(\.wireTextStyleMapping, WireTextStyleMapping()) | ||
| } | ||
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
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
4 changes: 2 additions & 2 deletions
4
.../ReferenceImages/WireTextStyleMappingTests/testFontDarkUserInterfaceStyle.1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...Images/WireTextStyleMappingTests/testFontDynamicTypeVariants.accessibility1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...Images/WireTextStyleMappingTests/testFontDynamicTypeVariants.accessibility2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...Images/WireTextStyleMappingTests/testFontDynamicTypeVariants.accessibility3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...Images/WireTextStyleMappingTests/testFontDynamicTypeVariants.accessibility4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...Images/WireTextStyleMappingTests/testFontDynamicTypeVariants.accessibility5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...ReferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.large.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...eferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.medium.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...ReferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.small.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...eferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.xLarge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...eferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.xSmall.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions
4
...ferenceImages/WireTextStyleMappingTests/testFontDynamicTypeVariants.xxLarge.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
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.