Skip to content

Commit

Permalink
Add a context menu to the uploads screen
Browse files Browse the repository at this point in the history
  • Loading branch information
kean committed Apr 26, 2024
1 parent c684f29 commit 1541b73
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import UIKit
import Gifu
import AVKit
import SwiftUI

struct SiteMediaPreviewView: UIViewControllerRepresentable {
let media: Media

func makeUIViewController(context: Context) -> SiteMediaPreviewViewController {
SiteMediaPreviewViewController(media: media)
}

func updateUIViewController(_ vc: SiteMediaPreviewViewController, context: Context) {
// Do nothing
}
}

final class SiteMediaPreviewViewController: UIViewController {
private let imageView = GIFImageView()
Expand Down
51 changes: 38 additions & 13 deletions WordPress/Classes/ViewRelated/Post/PostMediaUploadsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ private struct PostMediaUploadItemView: View {
@ObservedObject var viewModel: PostMediaUploadItemViewModel

var body: some View {
HStack(alignment: .center, spacing: 0) {
let view = HStack(alignment: .center, spacing: 0) {
MediaThubmnailImageView(image: viewModel.thumbnail)
.aspectRatio(viewModel.thumbnailAspectRatio, contentMode: .fit)
.frame(maxHeight: viewModel.thumbnailMaxHeight)
Expand All @@ -67,26 +67,55 @@ private struct PostMediaUploadItemView: View {
case .uploading:
MediaUploadProgressView(progress: viewModel.fractionCompleted)
.padding(.trailing, 4) // To align with the exlamation mark
makeMenu(for: viewModel)
menu
case .failed:
Image(systemName: "exclamationmark.circle.fill")
.foregroundStyle(.red)
makeMenu(for: viewModel)
menu
case .uploaded:
Image(systemName: "checkmark.circle.fill")
.foregroundStyle(.secondary.opacity(0.33))
}
}
}
.task {
await viewModel.loadThumbnail()
.task {
await viewModel.loadThumbnail()
}
if #available(iOS 16, *) {
view.contextMenu {
menuItems
} preview: {
SiteMediaPreviewView(media: viewModel.media)
}
} else {
view
}
}
}

@ViewBuilder
private func makeMenu(for viewModel: PostMediaUploadItemViewModel) -> some View {
Menu {
struct HostDetailsView: UIViewControllerRepresentable {
let media: Media

func makeUIViewController(context: Context) -> MediaItemViewController {
MediaItemViewController(media: media)
}

func updateUIViewController(_ uiViewController: MediaItemViewController, context: Context) {
// Do nothing
}
}

private var menu: some View {
Menu {
menuItems
} label: {
Image(systemName: "ellipsis")
.font(.subheadline)
.tint(.secondary)
}
}

@ViewBuilder
private var menuItems: some View {
if viewModel.error != nil {
Button(action: viewModel.buttonRetryTapped) {
Label(Strings.retryUpload, systemImage: "arrow.clockwise")
Expand All @@ -95,10 +124,6 @@ private func makeMenu(for viewModel: PostMediaUploadItemViewModel) -> some View
Button(role: .destructive, action: viewModel.buttonCancelTapped) {
Label(Strings.cancelUpload, systemImage: "trash")
}
} label: {
Image(systemName: "ellipsis")
.font(.subheadline)
.tint(.secondary)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ final class PostMediaUploadsViewModel: ObservableObject {
final class PostMediaUploadItemViewModel: ObservableObject, Identifiable {
@Published private(set) var state: State = .uploading

private let media: Media
let media: Media
private let coordinator: MediaCoordinator

private var completed: Int64 = 0
Expand Down

0 comments on commit 1541b73

Please sign in to comment.