@@ -6,55 +6,35 @@ import AVFoundation
66
77struct MediaView : View {
88 let data : UiMedia
9- let expandToFullSize : Bool
109
11- init ( data: UiMedia , expandToFullSize : Bool = false ) {
10+ init ( data: UiMedia ) {
1211 self . data = data
13- self . expandToFullSize = expandToFullSize
1412 }
1513
1614 var body : some View {
17- switch onEnum ( of: data) {
18- case . image( let image) :
19- AdaptiveSizeMediaContainerView (
20- expandToFullSize: expandToFullSize
21- ) {
22- NetworkImage ( data: image. previewUrl)
23- }
24- case . video( let video) :
25- MediaVideoView ( data: video, expandToFullSize: expandToFullSize)
26- case . gif( let gif) :
27- AdaptiveSizeMediaContainerView (
28- expandToFullSize: expandToFullSize
29- ) {
30- NetworkImage ( data: gif. url)
15+ ZStack {
16+ switch onEnum ( of: data) {
17+ case . image( let image) :
18+ Color . gray
19+ . opacity ( 0.2 )
20+ . overlay {
21+ NetworkImage ( data: image. previewUrl)
22+ . allowsHitTesting ( false )
23+ }
24+ . clipped ( )
25+ case . video( let video) :
26+ MediaVideoView ( data: video)
27+ case . gif( let gif) :
28+ Color . gray
29+ . opacity ( 0.2 )
30+ . overlay {
31+ NetworkImage ( data: gif. url)
32+ . allowsHitTesting ( false )
33+ }
34+ . clipped ( )
35+ case . audio( let audio) :
36+ EmptyView ( )
3137 }
32- case . audio( let audio) :
33- EmptyView ( )
34- }
35- }
36- }
37-
38- struct AdaptiveSizeMediaContainerView < Content: View > : View {
39- let expandToFullSize : Bool
40- @ViewBuilder let content : ( ) -> Content
41-
42- init ( expandToFullSize: Bool , @ViewBuilder content: @escaping ( ) -> Content ) {
43- self . expandToFullSize = expandToFullSize
44- self . content = content
45- }
46-
47- var body : some View {
48- if expandToFullSize {
49- content ( )
50- } else {
51- Color . gray
52- . opacity ( 0.2 )
53- . overlay {
54- content ( )
55- . allowsHitTesting ( false )
56- }
57- . clipped ( )
5838 }
5939 }
6040}
@@ -68,7 +48,6 @@ struct MediaVideoView: View {
6848 @State private var time : CMTime = . zero
6949 @State private var isAppeared : Bool = false
7050 let data : UiMediaVideo
71- let expandToFullSize : Bool
7251
7352 func canPlay( ) -> Bool {
7453 switch themeSettings. appearanceSettings. videoAutoplay {
@@ -82,11 +61,13 @@ struct MediaVideoView: View {
8261 }
8362
8463 var body : some View {
85- AdaptiveSizeMediaContainerView (
86- expandToFullSize: expandToFullSize
87- ) {
88- NetworkImage ( data: data. thumbnailUrl)
89- }
64+ Color . gray
65+ . opacity ( 0.2 )
66+ . overlay {
67+ NetworkImage ( data: data. thumbnailUrl)
68+ . allowsHitTesting ( false )
69+ }
70+ . clipped ( )
9071 . overlay {
9172 VideoPlayer ( url: . init( string: data. url) !, play: $play, time: $time)
9273 . mute ( true )
0 commit comments