@@ -48,13 +48,13 @@ struct SVGRepresentation: Transferable {
4848
4949struct ImageViewer : View {
5050 var delegate : SheetDismisserProtocol
51- let info : MLFiletransferInfo
51+ @ ObservedObject var info : ObservableKVOWrapper < MLFiletransferInfo >
5252 @State private var previewImage : UIImage ?
5353 @State private var controlsVisible = false
5454 @StateObject private var customPlayer = CustomAVPlayer ( )
5555 @State private var isPlayerReady = false
5656
57- init ( delegate: SheetDismisserProtocol , info: MLFiletransferInfo ) throws {
57+ init ( delegate: SheetDismisserProtocol , info: ObservableKVOWrapper < MLFiletransferInfo > ) throws {
5858 self . delegate = delegate
5959 self . info = info
6060 DDLogDebug ( " Loading image for info: \( String ( describing: self . info) ) " )
@@ -68,15 +68,15 @@ struct ImageViewer: View {
6868 if info. isSVGImage {
6969 VStack {
7070 ZoomableContainer ( maxScale: 8.0 , doubleTapScale: 4.0 ) {
71- SVGView ( contentsOf: info. fileURL! )
71+ SVGView ( contentsOf: info. fileURL as URL )
7272 }
7373 }
7474 } else if info. isImage {
75- if let image = UIImage ( contentsOfFile: info. cacheFilePath! ) {
75+ if let image = UIImage ( contentsOfFile: info. cacheFilePath as String ) {
7676 VStack {
7777 ZoomableContainer ( maxScale: 8.0 , doubleTapScale: 4.0 ) {
78- if info. mimeType! . hasPrefix ( " image/gif " ) {
79- GIFViewer ( data: Binding ( get: { try ! NSData ( contentsOfFile: info. cacheFilePath! ) as Data } , set: { _ in } ) )
78+ if ( info. mimeType as String ) . hasPrefix ( " image/gif " ) {
79+ GIFViewer ( data: Binding ( get: { try ! NSData ( contentsOfFile: info. cacheFilePath as String ) as Data } , set: { _ in } ) )
8080 . scaledToFit ( )
8181 } else {
8282 Image ( uiImage: image)
@@ -116,11 +116,11 @@ struct ImageViewer: View {
116116
117117 private func loadPreviewAndConfigurePlayer( ) async {
118118 if info. isSVGImage {
119- previewImage = await HelperTools . renderUIImage ( fromSVGURL: info. fileURL! ) . toTypedGuarantee ( ) . asyncOnMainActor ( )
119+ previewImage = await HelperTools . renderUIImage ( fromSVGURL: info. fileURL as URL ) . toTypedGuarantee ( ) . asyncOnMainActor ( )
120120 } else if info. isImage {
121- previewImage = UIImage ( contentsOfFile: info. cacheFilePath! )
121+ previewImage = UIImage ( contentsOfFile: info. cacheFilePath as String )
122122 } else if info. isVideo {
123- if let filePath = info. cacheFilePath, let mimeType = info. mimeType {
123+ if let filePath = info. cacheFilePath as String ? , let mimeType = info. mimeType as String ? {
124124 customPlayer. configurePlayer ( filePath: filePath, mimeType: mimeType)
125125 isPlayerReady = true
126126 }
@@ -182,56 +182,71 @@ struct InvalidFileView: View {
182182}
183183
184184struct ControlsOverlay : View {
185- let info : MLFiletransferInfo
185+ @ ObservedObject var info : ObservableKVOWrapper < MLFiletransferInfo >
186186 @Binding var previewImage : UIImage ?
187187 let dismiss : ( ) -> Void
188-
188+
189+ init ( info: ObservableKVOWrapper < MLFiletransferInfo > , previewImage: Binding < UIImage ? > , dismiss: @escaping ( ) -> Void ) {
190+ self . info = info
191+ _previewImage = previewImage
192+ self . dismiss = dismiss
193+ }
194+
189195 var body : some View {
190196 VStack {
191197 Color . background
192198 . ignoresSafeArea ( )
193199 . overlay (
194200 HStack {
195201 Spacer ( ) . frame ( width: 20 )
196- Text ( info. filename) . foregroundColor ( . primary)
202+ Text ( info. filename as String ) . foregroundColor ( . primary)
197203 Spacer ( )
198-
204+
199205 if let image = previewImage {
200206 if info. isSVGImage {
201207 ShareLink (
202208 item: SVGRepresentation ( getData: {
203- try ! NSData ( contentsOfFile: info. cacheFilePath! ) as Data
209+ try ! NSData ( contentsOfFile: info. cacheFilePath as String ) as Data
204210 } ) , preview: SharePreview ( " Share image " , image: Image ( uiImage: image) )
205211 )
206212 . labelStyle ( . iconOnly)
207213 . foregroundColor ( . primary)
208- } else if info. mimeType! . hasPrefix ( " image/gif " ) {
214+ } else if ( info. mimeType as String ) . hasPrefix ( " image/gif " ) {
209215 ShareLink (
210216 item: GifRepresentation ( getData: {
211- try ! NSData ( contentsOfFile: info. cacheFilePath! ) as Data
217+ try ! NSData ( contentsOfFile: info. cacheFilePath as String ) as Data
212218 } ) , preview: SharePreview ( " Share image " , image: Image ( uiImage: image) )
213219 )
214220 . labelStyle ( . iconOnly)
215221 . foregroundColor ( . primary)
216222 } else if info. isVideo {
217- if let fileURL = info. fileURL {
218- let mediaItem = MediaItem ( fileInfo: info)
219- ShareLink ( item: fileURL, preview: SharePreview ( " Share video " , image: Image ( uiImage: mediaItem. thumbnail ?? UIImage ( systemName: " video " ) !) ) )
220- . labelStyle ( . iconOnly)
221- . foregroundColor ( . primary)
223+ if let fileURL = info. fileURL as URL ? {
224+ ShareLink (
225+ item: fileURL,
226+ preview: SharePreview (
227+ " Share video " ,
228+ image: Image (
229+ uiImage: info. thumbnailURL
230+ ? UIImage ( contentsOfFile: ( info. thumbnailURL as URL ) . path) !
231+ : UIImage ( systemName: " video " ) !
232+ )
233+ )
234+ )
235+ . labelStyle ( . iconOnly)
236+ . foregroundColor ( . primary)
222237 }
223238 } else {
224239 ShareLink (
225240 item: JpegRepresentation ( getData: {
226- try ! NSData ( contentsOfFile: info. cacheFilePath! ) as Data
241+ try ! NSData ( contentsOfFile: info. cacheFilePath as String ) as Data
227242 } ) , preview: SharePreview ( " Share image " , image: Image ( uiImage: image) )
228243 )
229244 . labelStyle ( . iconOnly)
230245 . foregroundColor ( . primary)
231246 }
232247 Spacer ( ) . frame ( width: 20 )
233248 }
234-
249+
235250 Button ( action: dismiss, label: {
236251 Image ( systemName: " xmark " )
237252 . foregroundColor ( . primary)
0 commit comments