2022-04-19 12:29:03 +04:00
|
|
|
//
|
|
|
|
// CIImageView.swift
|
|
|
|
// SimpleX
|
|
|
|
//
|
|
|
|
// Created by JRoberts on 12/04/2022.
|
|
|
|
// Copyright © 2022 SimpleX Chat. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2022-05-31 07:55:13 +01:00
|
|
|
import SimpleXChat
|
2022-04-19 12:29:03 +04:00
|
|
|
|
|
|
|
struct CIImageView: View {
|
2023-10-31 09:44:57 +00:00
|
|
|
@EnvironmentObject var m: ChatModel
|
2022-10-10 10:40:30 +01:00
|
|
|
let chatItem: ChatItem
|
2025-02-18 01:21:40 +07:00
|
|
|
var scrollToItemId: ((ChatItem.ID) -> Void)? = nil
|
2024-07-03 10:24:26 +01:00
|
|
|
var preview: UIImage?
|
2022-04-19 12:29:03 +04:00
|
|
|
let maxWidth: CGFloat
|
2024-07-03 10:24:26 +01:00
|
|
|
var imgWidth: CGFloat?
|
2024-07-24 00:11:42 +07:00
|
|
|
var smallView: Bool = false
|
|
|
|
@Binding var showFullScreenImage: Bool
|
2024-07-26 14:38:22 +07:00
|
|
|
@State private var blurred: Bool = UserDefaults.standard.integer(forKey: DEFAULT_PRIVACY_MEDIA_BLUR_RADIUS) > 0
|
2022-04-19 12:29:03 +04:00
|
|
|
|
|
|
|
var body: some View {
|
2022-10-10 10:40:30 +01:00
|
|
|
let file = chatItem.file
|
2022-04-19 12:29:03 +04:00
|
|
|
VStack(alignment: .center, spacing: 6) {
|
2022-05-07 16:25:04 +04:00
|
|
|
if let uiImage = getLoadedImage(file) {
|
2024-07-24 00:11:42 +07:00
|
|
|
Group { if smallView { smallViewImageView(uiImage) } else { imageView(uiImage) } }
|
2022-04-19 12:29:03 +04:00
|
|
|
.fullScreenCover(isPresented: $showFullScreenImage) {
|
2025-02-18 01:21:40 +07:00
|
|
|
FullScreenMediaView(chatItem: chatItem, scrollToItemId: scrollToItemId, image: uiImage, showView: $showFullScreenImage)
|
2022-04-19 12:29:03 +04:00
|
|
|
}
|
2024-07-26 14:38:22 +07:00
|
|
|
.if(!smallView) { view in
|
|
|
|
view.modifier(PrivacyBlur(blurred: $blurred))
|
|
|
|
}
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
.simultaneousGesture(TapGesture().onEnded { showFullScreenImage = true })
|
2024-02-13 22:04:42 +07:00
|
|
|
.onChange(of: m.activeCallViewIsCollapsed) { _ in
|
|
|
|
showFullScreenImage = false
|
|
|
|
}
|
2024-07-03 10:24:26 +01:00
|
|
|
} else if let preview {
|
2024-07-26 14:38:22 +07:00
|
|
|
Group {
|
|
|
|
if smallView {
|
|
|
|
smallViewImageView(preview)
|
|
|
|
} else {
|
|
|
|
imageView(preview).modifier(PrivacyBlur(blurred: $blurred))
|
|
|
|
}
|
|
|
|
}
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
.simultaneousGesture(TapGesture().onEnded {
|
2022-05-30 08:59:04 +01:00
|
|
|
if let file = file {
|
|
|
|
switch file.fileStatus {
|
2024-05-20 17:49:19 +04:00
|
|
|
case .rcvInvitation, .rcvAborted:
|
2022-05-30 08:59:04 +01:00
|
|
|
Task {
|
2023-10-31 09:44:57 +00:00
|
|
|
if let user = m.currentUser {
|
2024-01-16 18:49:44 +07:00
|
|
|
await receiveFile(user: user, fileId: file.fileId)
|
2023-02-02 16:09:36 +00:00
|
|
|
}
|
2022-05-30 08:59:04 +01:00
|
|
|
}
|
|
|
|
case .rcvAccepted:
|
2023-03-29 15:48:00 +04:00
|
|
|
switch file.fileProtocol {
|
|
|
|
case .xftp:
|
|
|
|
AlertManager.shared.showAlertMsg(
|
|
|
|
title: "Waiting for image",
|
|
|
|
message: "Image will be received when your contact completes uploading it."
|
|
|
|
)
|
|
|
|
case .smp:
|
2023-03-28 22:20:06 +04:00
|
|
|
AlertManager.shared.showAlertMsg(
|
|
|
|
title: "Waiting for image",
|
|
|
|
message: "Image will be received when your contact is online, please wait or check later!"
|
|
|
|
)
|
2024-01-18 22:57:14 +07:00
|
|
|
case .local: ()
|
2023-03-28 22:20:06 +04:00
|
|
|
}
|
2022-05-30 08:59:04 +01:00
|
|
|
case .rcvTransfer: () // ?
|
|
|
|
case .rcvComplete: () // ?
|
|
|
|
case .rcvCancelled: () // TODO
|
2024-06-05 21:03:05 +04:00
|
|
|
case let .rcvError(rcvFileError):
|
2025-01-12 21:25:25 +00:00
|
|
|
showFileErrorAlert(rcvFileError)
|
2024-06-05 21:03:05 +04:00
|
|
|
case let .rcvWarning(rcvFileError):
|
2025-01-12 21:25:25 +00:00
|
|
|
showFileErrorAlert(rcvFileError, temporary: true)
|
2024-06-05 21:03:05 +04:00
|
|
|
case let .sndError(sndFileError):
|
2025-01-12 21:25:25 +00:00
|
|
|
showFileErrorAlert(sndFileError)
|
2024-06-05 21:03:05 +04:00
|
|
|
case let .sndWarning(sndFileError):
|
2025-01-12 21:25:25 +00:00
|
|
|
showFileErrorAlert(sndFileError, temporary: true)
|
2022-05-30 08:59:04 +01:00
|
|
|
default: ()
|
|
|
|
}
|
2022-05-04 09:10:36 +04:00
|
|
|
}
|
ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap (#5880)
* ios: fix XCode 16 regressions (tap not working on files, quotes, images, voice messages, etc.), open link previews on tap
* fix voice recording
* fix video, accepting calls from chat, preference toggles in chat
* WIP message and meta
* handle links in attributed strings
* custom attribute for links to prevent race conditions with default tap handler
2025-05-10 14:37:45 +01:00
|
|
|
})
|
2022-04-19 12:29:03 +04:00
|
|
|
}
|
|
|
|
}
|
2024-07-24 00:11:42 +07:00
|
|
|
.onDisappear {
|
|
|
|
showFullScreenImage = false
|
|
|
|
}
|
2022-04-19 12:29:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
private func imageView(_ img: UIImage) -> some View {
|
2024-04-02 23:00:24 +07:00
|
|
|
let w = img.size.width <= img.size.height ? maxWidth * 0.75 : maxWidth
|
2022-05-04 09:10:36 +04:00
|
|
|
return ZStack(alignment: .topTrailing) {
|
2022-12-24 00:22:12 +03:00
|
|
|
if img.imageData == nil {
|
|
|
|
Image(uiImage: img)
|
|
|
|
.resizable()
|
|
|
|
.scaledToFit()
|
2024-04-02 23:00:24 +07:00
|
|
|
.frame(width: w)
|
2022-12-24 00:22:12 +03:00
|
|
|
} else {
|
|
|
|
SwiftyGif(image: img)
|
|
|
|
.frame(width: w, height: w * img.size.height / img.size.width)
|
|
|
|
.scaledToFit()
|
|
|
|
}
|
2024-07-26 14:38:22 +07:00
|
|
|
if !blurred || !showDownloadButton(chatItem.file?.fileStatus) {
|
|
|
|
loadingIndicator()
|
|
|
|
}
|
2022-05-04 09:10:36 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-24 00:11:42 +07:00
|
|
|
private func smallViewImageView(_ img: UIImage) -> some View {
|
|
|
|
ZStack(alignment: .topTrailing) {
|
|
|
|
if img.imageData == nil {
|
|
|
|
Image(uiImage: img)
|
|
|
|
.resizable()
|
|
|
|
.aspectRatio(contentMode: .fill)
|
|
|
|
.frame(width: maxWidth, height: maxWidth)
|
|
|
|
} else {
|
|
|
|
SwiftyGif(image: img, contentMode: .scaleAspectFill)
|
|
|
|
.frame(width: maxWidth, height: maxWidth)
|
|
|
|
}
|
|
|
|
if chatItem.file?.showStatusIconInSmallView == true {
|
|
|
|
loadingIndicator()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-04 09:10:36 +04:00
|
|
|
@ViewBuilder private func loadingIndicator() -> some View {
|
2022-10-10 10:40:30 +01:00
|
|
|
if let file = chatItem.file {
|
2022-05-04 09:10:36 +04:00
|
|
|
switch file.fileStatus {
|
2023-03-29 15:48:00 +04:00
|
|
|
case .sndStored:
|
|
|
|
switch file.fileProtocol {
|
|
|
|
case .xftp: progressView()
|
|
|
|
case .smp: EmptyView()
|
2024-01-18 22:57:14 +07:00
|
|
|
case .local: EmptyView()
|
2023-03-29 15:48:00 +04:00
|
|
|
}
|
2023-03-31 19:15:37 +04:00
|
|
|
case .sndTransfer: progressView()
|
|
|
|
case .sndComplete: fileIcon("checkmark", 10, 13)
|
|
|
|
case .sndCancelled: fileIcon("xmark", 10, 13)
|
2023-04-18 12:48:36 +04:00
|
|
|
case .sndError: fileIcon("xmark", 10, 13)
|
2024-06-05 21:03:05 +04:00
|
|
|
case .sndWarning: fileIcon("exclamationmark.triangle.fill", 10, 13)
|
2023-03-31 19:15:37 +04:00
|
|
|
case .rcvInvitation: fileIcon("arrow.down", 10, 13)
|
|
|
|
case .rcvAccepted: fileIcon("ellipsis", 14, 11)
|
|
|
|
case .rcvTransfer: progressView()
|
2024-05-20 17:49:19 +04:00
|
|
|
case .rcvAborted: fileIcon("exclamationmark.arrow.circlepath", 14, 11)
|
2024-06-05 21:03:05 +04:00
|
|
|
case .rcvComplete: EmptyView()
|
2023-03-31 19:15:37 +04:00
|
|
|
case .rcvCancelled: fileIcon("xmark", 10, 13)
|
2023-04-18 12:48:36 +04:00
|
|
|
case .rcvError: fileIcon("xmark", 10, 13)
|
2024-06-05 21:03:05 +04:00
|
|
|
case .rcvWarning: fileIcon("exclamationmark.triangle.fill", 10, 13)
|
2023-07-31 11:54:39 +04:00
|
|
|
case .invalid: fileIcon("questionmark", 10, 13)
|
2022-05-04 09:10:36 +04:00
|
|
|
}
|
|
|
|
}
|
2022-04-19 12:29:03 +04:00
|
|
|
}
|
2023-03-28 22:20:06 +04:00
|
|
|
|
2023-03-31 19:15:37 +04:00
|
|
|
private func fileIcon(_ icon: String, _ size: CGFloat, _ padding: CGFloat) -> some View {
|
|
|
|
Image(systemName: icon)
|
|
|
|
.resizable()
|
2024-09-06 14:36:54 +03:00
|
|
|
.invertedForegroundStyle()
|
2023-03-31 19:15:37 +04:00
|
|
|
.aspectRatio(contentMode: .fit)
|
|
|
|
.frame(width: size, height: size)
|
|
|
|
.padding(padding)
|
|
|
|
}
|
|
|
|
|
2023-03-28 22:20:06 +04:00
|
|
|
private func progressView() -> some View {
|
|
|
|
ProgressView()
|
|
|
|
.progressViewStyle(.circular)
|
|
|
|
.frame(width: 20, height: 20)
|
|
|
|
.tint(.white)
|
|
|
|
.padding(8)
|
|
|
|
}
|
2024-07-26 14:38:22 +07:00
|
|
|
|
|
|
|
private func showDownloadButton(_ fileStatus: CIFileStatus?) -> Bool {
|
|
|
|
switch fileStatus {
|
|
|
|
case .rcvInvitation: true
|
|
|
|
case .rcvAborted: true
|
|
|
|
default: false
|
|
|
|
}
|
|
|
|
}
|
2022-04-19 12:29:03 +04:00
|
|
|
}
|