@@ -21,20 +21,14 @@ extension StatusEditor {
2121
2222 var body : some View {
2323 ScrollView ( . horizontal, showsIndicators: showsScrollIndicators) {
24- switch count {
25- case 1 : mediaLayout
26- case 2 : mediaLayout
27- case 3 : mediaLayout
28- case 4 : mediaLayout
29- default : mediaLayout
30- }
24+ mediaLayout
3125 }
3226 . scrollPosition ( id: $scrollID, anchor: . trailing)
3327 . scrollClipDisabled ( )
3428 . padding ( . horizontal, . layoutPadding)
35- . frame ( height: count > 0 ? containerHeight : 0 )
36- . animation ( . spring( duration: 0.3 ) , value: count)
37- . onChange ( of: count) { oldValue, newValue in
29+ . frame ( height: viewModel . mediaContainers . count > 0 ? containerHeight : 0 )
30+ . animation ( . spring( duration: 0.3 ) , value: viewModel . mediaContainers . count)
31+ . onChange ( of: viewModel . mediaPickers . count) { oldValue, newValue in
3832 if oldValue < newValue {
3933 Task {
4034 try ? await Task . sleep ( for: . seconds( 0.5 ) )
@@ -46,7 +40,6 @@ extension StatusEditor {
4640 }
4741 }
4842
49- private var count : Int { viewModel. mediaContainers. count }
5043 private var containers : [ MediaContainer ] { viewModel. mediaContainers }
5144 private let containerHeight : CGFloat = 300
5245 private var containerWidth : CGFloat { containerHeight / 1.5 }
@@ -64,35 +57,22 @@ extension StatusEditor {
6457 _editingMediaContainer = editingMediaContainer
6558 }
6659
67- private func pixel( at index: Int ) -> some View {
68- Rectangle ( ) . frame ( width: 0 , height: 0 )
69- . matchedGeometryEffect ( id: index, in: mediaSpace, anchor: . leading)
70- }
71-
7260 private var mediaLayout : some View {
73- HStack ( alignment: . center, spacing: count > 1 ? 8 : 0 ) {
74- if count > 0 {
75- if count == 1 {
76- makeMediaItem ( at: 0 )
77- . containerRelativeFrame ( . horizontal, alignment: . leading)
78- } else {
79- makeMediaItem ( at: 0 )
80- }
81- } else {
82- pixel ( at: 0 )
61+ HStack ( alignment: . center, spacing: 8 ) {
62+ ForEach ( Array ( viewModel. mediaContainers. enumerated ( ) ) , id: \. offset) { index, container in
63+ makeMediaItem ( container)
64+ . containerRelativeFrame ( . horizontal,
65+ count: viewModel. mediaContainers. count == 1 ? 1 : 2 ,
66+ span: 1 ,
67+ spacing: 0 ,
68+ alignment: . leading)
8369 }
84- if count > 1 { makeMediaItem ( at: 1 ) } else { pixel ( at: 1 ) }
85- if count > 2 { makeMediaItem ( at: 2 ) } else { pixel ( at: 2 ) }
86- if count > 3 { makeMediaItem ( at: 3 ) } else { pixel ( at: 3 ) }
8770 }
8871 . padding ( . bottom, scrollBottomPadding)
8972 . scrollTargetLayout ( )
9073 }
9174
92- @ViewBuilder
93- private func makeMediaItem( at index: Int ) -> some View {
94- let container = viewModel. mediaContainers [ index]
95-
75+ private func makeMediaItem( _ container: MediaContainer ) -> some View {
9676 RoundedRectangle ( cornerRadius: 8 )
9777 . fill ( . clear)
9878 . overlay {
@@ -107,6 +87,7 @@ extension StatusEditor {
10787 makeErrorView ( content: content, error: error)
10888 }
10989 }
90+ . contentShape ( Rectangle ( ) )
11091 . contextMenu {
11192 makeImageMenu ( container: container)
11293 }
@@ -122,10 +103,7 @@ extension StatusEditor {
122103 makeDiscardMarker ( container: container)
123104 }
124105 . clipShape ( RoundedRectangle ( cornerRadius: 8 ) )
125- . frame ( minWidth: count == 1 ? nil : containerWidth, maxWidth: 600 )
126106 . id ( container. id)
127- . matchedGeometryEffect ( id: container. id, in: mediaSpace, anchor: . leading)
128- . matchedGeometryEffect ( id: index, in: mediaSpace, anchor: . leading)
129107 }
130108
131109 private func makeLocalMediaView( content: MediaContainer . MediaContent ) -> some View {
@@ -185,6 +163,8 @@ extension StatusEditor {
185163 image
186164 . resizable ( )
187165 . scaledToFill ( )
166+ . clipped ( )
167+ . allowsHitTesting ( false )
188168 } else {
189169 placeholderView
190170 }
0 commit comments