Small images cropping text (#137)

* Fixes for #136, small images cropping text / videos missing re-hide button

* Accidentally unlocalised some text.
This commit is contained in:
Gareth Simpson 2023-01-20 05:41:47 +00:00 committed by GitHub
parent c399b0c677
commit 0f45a8d1ff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -134,18 +134,19 @@ public struct StatusMediaPreviewView: View {
@ViewBuilder @ViewBuilder
private func makeFeaturedImagePreview(attachment: MediaAttachment) -> some View { private func makeFeaturedImagePreview(attachment: MediaAttachment) -> some View {
switch attachment.supportedType { ZStack(alignment: .bottomTrailing) {
case .image: switch attachment.supportedType {
if theme.statusDisplayStyle == .large, case .image:
let size = size(for: attachment), if theme.statusDisplayStyle == .large,
UIDevice.current.userInterfaceIdiom != .pad, let size = size(for: attachment),
UIDevice.current.userInterfaceIdiom != .mac UIDevice.current.userInterfaceIdiom != .pad,
{ UIDevice.current.userInterfaceIdiom != .mac
let avatarColumnWidth = theme.avatarPosition == .leading ? AvatarView.Size.status.size.width + .statusColumnsSpacing : 0 {
let availableWidth = UIScreen.main.bounds.width - (.layoutPadding * 2) - avatarColumnWidth let avatarColumnWidth = theme.avatarPosition == .leading ? AvatarView.Size.status.size.width + .statusColumnsSpacing : 0
let newSize = imageSize(from: size, let availableWidth = UIScreen.main.bounds.width - (.layoutPadding * 2) - avatarColumnWidth
newWidth: availableWidth) let newSize = imageSize(from: size,
ZStack(alignment: .bottomTrailing) { newWidth: availableWidth)
LazyImage(url: attachment.url) { state in LazyImage(url: attachment.url) { state in
if let image = state.image { if let image = state.image {
image image
@ -159,46 +160,51 @@ public struct StatusMediaPreviewView: View {
.shimmering() .shimmering()
} }
} }
if sensitive { } else {
cornerSensitiveButton AsyncImage(
} url: attachment.url,
if let alt = attachment.description, !alt.isEmpty, !isNotifications { content: { image in
Button { image
altTextDisplayed = alt .resizable()
isAltAlertDisplayed = true .aspectRatio(contentMode: .fit)
} label: { .frame(maxHeight: isNotifications ? imageMaxHeight : nil)
Text("status.image.alt-text.abbreviation") .cornerRadius(4)
},
placeholder: {
RoundedRectangle(cornerRadius: 4)
.fill(Color.gray)
.frame(maxHeight: isNotifications ? imageMaxHeight : nil)
.shimmering()
} }
.padding(8) )
.background(.thinMaterial)
.cornerRadius(4)
}
} }
} else { case .gifv, .video, .audio:
AsyncImage( if let url = attachment.url {
url: attachment.url, VideoPlayerView(viewModel: .init(url: url))
content: { image in .frame(height: imageMaxHeight)
image }
.resizable() case .none:
.aspectRatio(contentMode: .fit) EmptyView()
.frame(maxHeight: isNotifications ? imageMaxHeight : nil) }
.cornerRadius(4) if sensitive {
}, cornerSensitiveButton
placeholder: { }
RoundedRectangle(cornerRadius: 4) if let alt = attachment.description, !alt.isEmpty, !isNotifications {
.fill(Color.gray) Group {
.frame(height: imageMaxHeight) Button {
.shimmering() altTextDisplayed = alt
isAltAlertDisplayed = true
} label: {
Text("ALT")
} }
) .padding(8)
.background(.thinMaterial)
.cornerRadius(4)
}
.padding(10)
} }
case .gifv, .video, .audio:
if let url = attachment.url {
VideoPlayerView(viewModel: .init(url: url))
.frame(height: imageMaxHeight)
}
case .none:
EmptyView()
} }
} }
@ -279,36 +285,41 @@ public struct StatusMediaPreviewView: View {
} }
private var sensitiveMediaOverlay: some View { private var sensitiveMediaOverlay: some View {
Rectangle() ZStack {
.background(.ultraThinMaterial) Rectangle()
.overlay { .background(.ultraThinMaterial)
if !isNotifications { if !isNotifications {
Button { Button {
withAnimation { withAnimation {
isHidingMedia = false isHidingMedia = false
} }
} label: { } label: {
if sensitive { if sensitive {
Label("status.media.sensitive.show", systemImage: "eye") Label("status.media.sensitive.show", systemImage: "eye")
} else { } else {
Label("status.media.content.show", systemImage: "eye") Label("status.media.content.show", systemImage: "eye")
}
} }
.buttonStyle(.borderedProminent)
} }
.buttonStyle(.borderedProminent)
} }
}
} }
private var cornerSensitiveButton: some View { private var cornerSensitiveButton: some View {
Button { HStack{
withAnimation { Button {
isHidingMedia = true withAnimation {
isHidingMedia = true
}
} label: {
Image(systemName: "eye.slash")
.frame(minHeight:21) // Match the alt button in case it is also present
} }
} label: { .padding(10)
Image(systemName: "eye.slash") .buttonStyle(.borderedProminent)
Spacer()
} }
.position(x: 30, y: 30)
.buttonStyle(.borderedProminent)
} }
@ViewBuilder @ViewBuilder