wrap and use MediaView for message info screen
This commit is contained in:
parent
a5f12649c1
commit
d5c448edac
|
@ -470,3 +470,43 @@ public class MediaView: UIView {
|
|||
unloadBlock?()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: - SwiftUI
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct MediaView_SwiftUI: UIViewRepresentable {
|
||||
public typealias UIViewType = MediaView
|
||||
|
||||
private let mediaCache: NSCache<NSString, AnyObject>?
|
||||
public let attachment: Attachment
|
||||
private let isOutgoing: Bool
|
||||
private let cornerRadius: CGFloat
|
||||
|
||||
public init(
|
||||
mediaCache: NSCache<NSString, AnyObject>? = nil,
|
||||
attachment: Attachment,
|
||||
isOutgoing: Bool,
|
||||
cornerRadius: CGFloat
|
||||
) {
|
||||
self.mediaCache = mediaCache
|
||||
self.attachment = attachment
|
||||
self.isOutgoing = isOutgoing
|
||||
self.cornerRadius = cornerRadius
|
||||
}
|
||||
|
||||
func makeUIView(context: Context) -> MediaView {
|
||||
let mediaView = MediaView(
|
||||
mediaCache: mediaCache,
|
||||
attachment: attachment,
|
||||
isOutgoing: isOutgoing,
|
||||
cornerRadius: cornerRadius
|
||||
)
|
||||
|
||||
return mediaView
|
||||
}
|
||||
|
||||
func updateUIView(_ mediaView: MediaView, context: Context) {
|
||||
mediaView.loadMedia()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,14 +101,37 @@ struct MessageInfoView: View {
|
|||
ZStack(alignment: .bottomTrailing) {
|
||||
if attachments.count > 1 {
|
||||
// Attachment carousel view
|
||||
SessionCarouselView_SwiftUI(index: $index, contentInfos: attachments)
|
||||
.frame(
|
||||
maxWidth: .infinity,
|
||||
maxHeight: .infinity,
|
||||
alignment: .topLeading
|
||||
)
|
||||
SessionCarouselView_SwiftUI(
|
||||
index: $index,
|
||||
isOutgoing: (messageViewModel.variant == .standardOutgoing),
|
||||
contentInfos: attachments
|
||||
)
|
||||
.frame(
|
||||
maxWidth: .infinity,
|
||||
maxHeight: .infinity,
|
||||
alignment: .topLeading
|
||||
)
|
||||
} else {
|
||||
// TODO: one attachment
|
||||
MediaView_SwiftUI(
|
||||
attachment: attachments[0],
|
||||
isOutgoing: (messageViewModel.variant == .standardOutgoing),
|
||||
cornerRadius: 0
|
||||
)
|
||||
.frame(
|
||||
maxWidth: .infinity,
|
||||
maxHeight: .infinity,
|
||||
alignment: .topLeading
|
||||
)
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 15))
|
||||
.padding(
|
||||
EdgeInsets(
|
||||
top: 0,
|
||||
leading: 30,
|
||||
bottom: 0,
|
||||
trailing: 30
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
Button {
|
||||
|
@ -142,7 +165,7 @@ struct MessageInfoView: View {
|
|||
)
|
||||
|
||||
// Attachment Info
|
||||
let attachment: Attachment = attachments[index - 1]
|
||||
let attachment: Attachment = attachments[(index - 1 + attachments.count) % attachments.count]
|
||||
ZStack {
|
||||
RoundedRectangle(cornerRadius: 17)
|
||||
.fill(themeColor: .backgroundSecondary)
|
||||
|
|
|
@ -4,11 +4,13 @@ import SwiftUI
|
|||
|
||||
public struct SessionCarouselView_SwiftUI: View {
|
||||
@Binding var index: Int
|
||||
let isOutgoing: Bool
|
||||
var contentInfos: [Attachment]
|
||||
let numberOfPages: Int
|
||||
|
||||
public init(index: Binding<Int>, contentInfos: [Attachment]) {
|
||||
public init(index: Binding<Int>, isOutgoing: Bool, contentInfos: [Attachment]) {
|
||||
self._index = index
|
||||
self.isOutgoing = isOutgoing
|
||||
self.contentInfos = contentInfos
|
||||
self.numberOfPages = contentInfos.count
|
||||
|
||||
|
@ -24,9 +26,12 @@ public struct SessionCarouselView_SwiftUI: View {
|
|||
.zIndex(1)
|
||||
|
||||
PageView(index: $index, numberOfPages: self.numberOfPages) {
|
||||
ForEach(self.contentInfos, id: \.self) { color in
|
||||
Rectangle()
|
||||
.foregroundColor(color)
|
||||
ForEach(self.contentInfos) { attachment in
|
||||
MediaView_SwiftUI(
|
||||
attachment: attachment,
|
||||
isOutgoing: self.isOutgoing,
|
||||
cornerRadius: 0
|
||||
)
|
||||
}
|
||||
}
|
||||
.aspectRatio(1, contentMode: .fit)
|
||||
|
@ -66,7 +71,7 @@ struct ArrowView: View {
|
|||
} label: {
|
||||
Image(systemName: imageName)
|
||||
.font(.system(size: 20))
|
||||
.foregroundColor(.white)
|
||||
.foregroundColor(themeColor: .textPrimary)
|
||||
.frame(width: 30, height: 30)
|
||||
}
|
||||
}
|
||||
|
@ -199,7 +204,7 @@ struct SessionCarouselView_SwiftUI_Previews: PreviewProvider {
|
|||
Color.black
|
||||
}
|
||||
|
||||
SessionCarouselView_SwiftUI(index: $index, contentInfos: [.red, .orange, .blue])
|
||||
SessionCarouselView_SwiftUI(index: $index, isOutgoing: true, contentInfos: [])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue