Cleanup / fixes

This commit is contained in:
Thomas Ricouard 2023-03-03 12:41:38 +01:00
parent 82179e5f6f
commit 42c444fb03
4 changed files with 14 additions and 13 deletions

View file

@ -134,7 +134,7 @@ public class StatusEditorViewModel: NSObject, ObservableObject {
func setInitialLanguageSelection(preference: String?) { func setInitialLanguageSelection(preference: String?) {
switch mode { switch mode {
case let .edit(status), let .replyTo(status), let .quote(status): case let .edit(status), let .quote(status):
selectedLanguage = status.language selectedLanguage = status.language
default: default:
break break

View file

@ -39,8 +39,7 @@ struct StatusRowContentView: View {
if !viewModel.finalStatus.mediaAttachments.isEmpty { if !viewModel.finalStatus.mediaAttachments.isEmpty {
HStack { HStack {
StatusRowMediaPreviewView(attachments: viewModel.finalStatus.mediaAttachments, StatusRowMediaPreviewView(attachments: viewModel.finalStatus.mediaAttachments,
sensitive: viewModel.finalStatus.sensitive, sensitive: viewModel.finalStatus.sensitive)
isNotifications: isCompact)
if theme.statusDisplayStyle == .compact { if theme.statusDisplayStyle == .compact {
Spacer() Spacer()
} }

View file

@ -9,6 +9,7 @@ public struct StatusRowMediaPreviewView: View {
@Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool @Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool
@Environment(\.extraLeadingInset) private var extraLeadingInset: CGFloat @Environment(\.extraLeadingInset) private var extraLeadingInset: CGFloat
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool @Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@Environment(\.isCompact) private var isCompact: Bool
@EnvironmentObject var sceneDelegate: SceneDelegate @EnvironmentObject var sceneDelegate: SceneDelegate
@EnvironmentObject private var preferences: UserPreferences @EnvironmentObject private var preferences: UserPreferences
@ -17,7 +18,6 @@ public struct StatusRowMediaPreviewView: View {
public let attachments: [MediaAttachment] public let attachments: [MediaAttachment]
public let sensitive: Bool public let sensitive: Bool
public let isNotifications: Bool
@State private var isQuickLookLoading: Bool = false @State private var isQuickLookLoading: Bool = false
@State private var altTextDisplayed: String? @State private var altTextDisplayed: String?
@ -48,7 +48,7 @@ public struct StatusRowMediaPreviewView: View {
} }
private var imageMaxHeight: CGFloat { private var imageMaxHeight: CGFloat {
if isNotifications { if isCompact {
return 50 return 50
} }
if theme.statusDisplayStyle == .compact { if theme.statusDisplayStyle == .compact {
@ -73,7 +73,7 @@ public struct StatusRowMediaPreviewView: View {
} }
private func imageSize(from: CGSize, newWidth: CGFloat) -> CGSize { private func imageSize(from: CGSize, newWidth: CGFloat) -> CGSize {
if isNotifications || theme.statusDisplayStyle == .compact || isSecondaryColumn { if isCompact || theme.statusDisplayStyle == .compact || isSecondaryColumn {
return .init(width: imageMaxHeight, height: imageMaxHeight) return .init(width: imageMaxHeight, height: imageMaxHeight)
} }
let ratio = newWidth / from.width let ratio = newWidth / from.width
@ -91,7 +91,7 @@ public struct StatusRowMediaPreviewView: View {
} }
} }
} else { } else {
if isNotifications || theme.statusDisplayStyle == .compact { if isCompact || theme.statusDisplayStyle == .compact {
HStack { HStack {
makeAttachmentView(for: 0) makeAttachmentView(for: 0)
makeAttachmentView(for: 1) makeAttachmentView(for: 1)
@ -182,7 +182,7 @@ public struct StatusRowMediaPreviewView: View {
if !isInCaptureMode, sensitive { if !isInCaptureMode, sensitive {
cornerSensitiveButton cornerSensitiveButton
} }
if !isInCaptureMode, let alt = attachment.description, !alt.isEmpty, !isNotifications, preferences.showAltTextForMedia { if !isInCaptureMode, let alt = attachment.description, !alt.isEmpty, !isCompact, preferences.showAltTextForMedia {
Group { Group {
Button { Button {
altTextDisplayed = alt altTextDisplayed = alt
@ -208,7 +208,7 @@ public struct StatusRowMediaPreviewView: View {
GeometryReader { proxy in GeometryReader { proxy in
switch type { switch type {
case .image: case .image:
let width = isNotifications ? imageMaxHeight : proxy.frame(in: .local).width let width = isCompact ? imageMaxHeight : proxy.frame(in: .local).width
let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageMaxHeight))] let processors: [ImageProcessing] = [.resize(size: .init(width: width, height: imageMaxHeight))]
ZStack(alignment: .bottomTrailing) { ZStack(alignment: .bottomTrailing) {
LazyImage(url: attachment.previewUrl ?? attachment.url) { state in LazyImage(url: attachment.previewUrl ?? attachment.url) { state in
@ -234,7 +234,7 @@ public struct StatusRowMediaPreviewView: View {
if !isInCaptureMode, if !isInCaptureMode,
let alt = attachment.description, let alt = attachment.description,
!alt.isEmpty, !alt.isEmpty,
!isNotifications, !isCompact,
preferences.showAltTextForMedia preferences.showAltTextForMedia
{ {
Button { Button {
@ -253,12 +253,12 @@ public struct StatusRowMediaPreviewView: View {
case .gifv, .video, .audio: case .gifv, .video, .audio:
if let url = attachment.url { if let url = attachment.url {
VideoPlayerView(viewModel: .init(url: url)) VideoPlayerView(viewModel: .init(url: url))
.frame(width: isNotifications ? imageMaxHeight : proxy.frame(in: .local).width) .frame(width: isCompact ? imageMaxHeight : proxy.frame(in: .local).width)
.frame(height: imageMaxHeight) .frame(height: imageMaxHeight)
} }
} }
} }
.frame(maxWidth: isNotifications ? imageMaxHeight : nil) .frame(maxWidth: isCompact ? imageMaxHeight : nil)
.frame(height: imageMaxHeight) .frame(height: imageMaxHeight)
} }
// #965: do not create overlapping tappable areas, when multiple images are shown // #965: do not create overlapping tappable areas, when multiple images are shown
@ -291,7 +291,7 @@ public struct StatusRowMediaPreviewView: View {
Rectangle() Rectangle()
.foregroundColor(.clear) .foregroundColor(.clear)
.background(.ultraThinMaterial) .background(.ultraThinMaterial)
if !isNotifications { if !isCompact {
Button { Button {
withAnimation { withAnimation {
isHidingMedia = false isHidingMedia = false

View file

@ -5,6 +5,7 @@ import SwiftUI
struct StatusRowTranslateView: View { struct StatusRowTranslateView: View {
@Environment(\.isInCaptureMode) private var isInCaptureMode: Bool @Environment(\.isInCaptureMode) private var isInCaptureMode: Bool
@Environment(\.isCompact) private var isCompact: Bool
@EnvironmentObject private var preferences: UserPreferences @EnvironmentObject private var preferences: UserPreferences
@ -35,6 +36,7 @@ struct StatusRowTranslateView: View {
var body: some View { var body: some View {
if !isInCaptureMode, if !isInCaptureMode,
!isCompact,
let userLang = preferences.serverPreferences?.postLanguage, let userLang = preferences.serverPreferences?.postLanguage,
shouldShowTranslateButton shouldShowTranslateButton
{ {