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 {
4545
4646 @State private var assetURL : URL ?
4747 @State private var compressing = false
48+ @State private var loading = false
49+ @State var requestId : PHContentEditingInputRequestID ?
4850
4951 var asset : PHAsset
5052 var onImageTap : ( AddedAsset ) -> Void
@@ -89,7 +91,7 @@ public struct PhotoAttachmentCell: View {
8991 }
9092 }
9193 . overlay (
92- compressing ? ProgressView ( ) : nil
94+ ( compressing || loading ) ? ProgressView ( ) : nil
9395 )
9496 }
9597 } else {
@@ -130,7 +132,12 @@ public struct PhotoAttachmentCell: View {
130132 return
131133 }
132134
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
134141 if asset. mediaType == . image {
135142 self . assetURL = input? . fullSizeImageURL
136143 } else if let url = ( input? . audiovisualAsset as? AVURLAsset ) ? . url {
@@ -147,5 +154,11 @@ public struct PhotoAttachmentCell: View {
147154 }
148155 }
149156 }
157+ . onDisappear ( ) {
158+ if let requestId = requestId {
159+ asset. cancelContentEditingInputRequest ( requestId)
160+ self . requestId = nil
161+ }
162+ }
150163 }
151164}
Original file line number Diff line number Diff line change 22// Copyright © 2022 Stream.io Inc. All rights reserved.
33//
44
5+ import Photos
56import SnapshotTesting
67@testable import StreamChat
78@testable import StreamChatSwiftUI
@@ -212,4 +213,25 @@ class MessageComposerView_Tests: StreamChatTestCase {
212213 assertSnapshot ( matching: viewWithSize, as: . image)
213214 XCTAssert ( coordinator. textInput. height == 100 )
214215 }
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+
215237}
You can’t perform that action at this time.
0 commit comments