Remove capture mode for images (#996)

* Remove capture mode for images

* Simplify how processor is created in StatusRowMediaPreviewView

* Optimize StatusViewId further
This commit is contained in:
Alex Grebenyuk 2023-02-22 01:09:56 -05:00 committed by GitHub
parent 678f6f0cdd
commit 37a69650ef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 26 additions and 49 deletions

View file

@ -4,7 +4,6 @@ import Shimmer
import SwiftUI import SwiftUI
public struct AvatarView: View { public struct AvatarView: View {
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@Environment(\.redactionReasons) private var reasons @Environment(\.redactionReasons) private var reasons
@EnvironmentObject private var theme: Theme @EnvironmentObject private var theme: Theme
@ -56,24 +55,17 @@ public struct AvatarView: View {
.fill(.gray) .fill(.gray)
.frame(width: size.size.width, height: size.size.height) .frame(width: size.size.width, height: size.size.height)
} else { } else {
if isInCaptureMode, let url = url, let image = Nuke.ImagePipeline.shared.cache.cachedImage(for: makeImageRequest(for: url))?.image { LazyImage(request: url.map(makeImageRequest)) { state in
Image(uiImage: image) if let image = state.image {
.resizable() image
.aspectRatio(contentMode: .fit) .resizable()
.frame(width: size.size.width, height: size.size.height) .aspectRatio(contentMode: .fit)
} else { } else {
LazyImage(request: url.map(makeImageRequest)) { state in AvatarPlaceholderView(size: size)
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fit)
} else {
AvatarPlaceholderView(size: size)
}
} }
.animation(nil)
.frame(width: size.size.width, height: size.size.height)
} }
.animation(nil)
.frame(width: size.size.width, height: size.size.height)
} }
} }
.clipShape(clipShape) .clipShape(clipShape)

View file

@ -57,12 +57,12 @@ public protocol AnyStatus {
public struct StatusViewId: Hashable { public struct StatusViewId: Hashable {
let id: String let id: String
let editedAt: ServerDate? let editedAt: Date?
} }
public extension AnyStatus { public extension AnyStatus {
var viewId: StatusViewId { var viewId: StatusViewId {
StatusViewId(id: id, editedAt: editedAt) StatusViewId(id: id, editedAt: editedAt?.asDate)
} }
} }

View file

@ -21,7 +21,6 @@ public struct StatusRowMediaPreviewView: View {
public let isNotifications: Bool public let isNotifications: Bool
@State private var isQuickLookLoading: Bool = false @State private var isQuickLookLoading: Bool = false
@State private var width: CGFloat = 0
@State private var altTextDisplayed: String? @State private var altTextDisplayed: String?
@State private var isAltAlertDisplayed: Bool = false @State private var isAltAlertDisplayed: Bool = false
@State private var isHidingMedia: Bool = false @State private var isHidingMedia: Bool = false
@ -155,39 +154,25 @@ public struct StatusRowMediaPreviewView: View {
private func makeFeaturedImagePreview(attachment: MediaAttachment) -> some View { private func makeFeaturedImagePreview(attachment: MediaAttachment) -> some View {
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
let size: CGSize = size(for: attachment) ?? .init(width: imageMaxHeight, height: imageMaxHeight) let size: CGSize = size(for: attachment) ?? .init(width: imageMaxHeight, height: imageMaxHeight)
let newSize = imageSize(from: size, let newSize = imageSize(from: size, newWidth: availableWidth - appLayoutWidth)
newWidth: availableWidth - appLayoutWidth)
let processors: [ImageProcessing] = [.resize(size: .init(width: newSize.width, height: newSize.height))]
switch attachment.supportedType { switch attachment.supportedType {
case .image: case .image:
if isInCaptureMode, LazyImage(url: attachment.url) { state in
let image = Nuke.ImagePipeline.shared.cache.cachedImage(for: .init(url: attachment.url, if let image = state.image {
processors: processors))?.image image
{ .resizable()
Image(uiImage: image) .aspectRatio(contentMode: .fill)
.resizable() .frame(width: newSize.width, height: newSize.height)
.aspectRatio(contentMode: .fill) .clipped()
.frame(width: newSize.width, height: newSize.height) .cornerRadius(4)
.clipped() } else {
.cornerRadius(4) RoundedRectangle(cornerRadius: 4)
} else { .fill(Color.gray)
LazyImage(url: attachment.url) { state in .frame(width: newSize.width, height: newSize.height)
if let image = state.image {
image
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: newSize.width, height: newSize.height)
.clipped()
.cornerRadius(4)
} else {
RoundedRectangle(cornerRadius: 4)
.fill(Color.gray)
.frame(width: newSize.width, height: newSize.height)
}
} }
.processors([.resize(size: .init(width: newSize.width, height: newSize.height))])
.frame(width: newSize.width, height: newSize.height)
} }
.processors([.resize(size: newSize)])
.frame(width: newSize.width, height: newSize.height)
case .gifv, .video, .audio: case .gifv, .video, .audio:
if let url = attachment.url { if let url = attachment.url {