File tree Expand file tree Collapse file tree 2 files changed +37
-2
lines changed
Sources/StreamChatSwiftUI/ChatChannel/Composer
StreamChatSwiftUITests/Tests/ChatChannel Expand file tree Collapse file tree 2 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,8 @@ public struct PhotoAttachmentCell: View {
45
45
46
46
@State private var assetURL : URL ?
47
47
@State private var compressing = false
48
+ @State private var loading = false
49
+ @State var requestId : PHContentEditingInputRequestID ?
48
50
49
51
var asset : PHAsset
50
52
var onImageTap : ( AddedAsset ) -> Void
@@ -89,7 +91,7 @@ public struct PhotoAttachmentCell: View {
89
91
}
90
92
}
91
93
. overlay (
92
- compressing ? ProgressView ( ) : nil
94
+ ( compressing || loading ) ? ProgressView ( ) : nil
93
95
)
94
96
}
95
97
} else {
@@ -130,7 +132,12 @@ public struct PhotoAttachmentCell: View {
130
132
return
131
133
}
132
134
133
- asset. requestContentEditingInput ( with: nil ) { input, _ in
135
+ let options = PHContentEditingInputRequestOptions ( )
136
+ options. isNetworkAccessAllowed = true
137
+ self . loading = true
138
+
139
+ self . requestId = asset. requestContentEditingInput ( with: options) { input, _ in
140
+ self . loading = false
134
141
if asset. mediaType == . image {
135
142
self . assetURL = input? . fullSizeImageURL
136
143
} else if let url = ( input? . audiovisualAsset as? AVURLAsset ) ? . url {
@@ -147,5 +154,11 @@ public struct PhotoAttachmentCell: View {
147
154
}
148
155
}
149
156
}
157
+ . onDisappear ( ) {
158
+ if let requestId = requestId {
159
+ asset. cancelContentEditingInputRequest ( requestId)
160
+ self . requestId = nil
161
+ }
162
+ }
150
163
}
151
164
}
Original file line number Diff line number Diff line change 2
2
// Copyright © 2022 Stream.io Inc. All rights reserved.
3
3
//
4
4
5
+ import Photos
5
6
import SnapshotTesting
6
7
@testable import StreamChat
7
8
@testable import StreamChatSwiftUI
@@ -212,4 +213,25 @@ class MessageComposerView_Tests: StreamChatTestCase {
212
213
assertSnapshot ( matching: viewWithSize, as: . image)
213
214
XCTAssert ( coordinator. textInput. height == 100 )
214
215
}
216
+
217
+ func test_photoAttachmentCell_loadingResource( ) {
218
+ // Given
219
+ let asset = PHAsset ( )
220
+ let loader = PhotoAssetLoader ( )
221
+ let cell = PhotoAttachmentCell (
222
+ assetLoader: loader,
223
+ asset: asset,
224
+ onImageTap: { _ in } ,
225
+ imageSelected: { _ in return false }
226
+ )
227
+
228
+ // When
229
+ _ = cell. onAppear ( )
230
+ _ = cell. onDisappear ( )
231
+ let newRequestId = cell. requestId
232
+
233
+ // Then
234
+ XCTAssert ( newRequestId == nil )
235
+ }
236
+
215
237
}
You can’t perform that action at this time.
0 commit comments