Skip to content

Commit af959bf

Browse files
Added loading view when getting photo album assets
1 parent e79688b commit af959bf

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

Sources/StreamChatSwiftUI/ChatChannel/Composer/AttachmentPickerView.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,17 @@ public struct AttachmentPickerView<Factory: ViewFactory>: View {
3838
if selectedPickerState == .photos {
3939
if let assets = photoLibraryAssets,
4040
let collection = PHFetchResultCollection(fetchResult: assets) {
41-
viewFactory.makePhotoAttachmentPickerView(
42-
assets: collection,
43-
onAssetTap: onAssetTap,
44-
isAssetSelected: isAssetSelected
45-
)
41+
if !collection.isEmpty {
42+
viewFactory.makePhotoAttachmentPickerView(
43+
assets: collection,
44+
onAssetTap: onAssetTap,
45+
isAssetSelected: isAssetSelected
46+
)
47+
} else {
48+
viewFactory.makeAssetsAccessPermissionView()
49+
}
4650
} else {
47-
viewFactory.makeAssetsAccessPermissionView()
51+
LoadingView()
4852
}
4953

5054
} else if selectedPickerState == .files {

Sources/StreamChatSwiftUI/ChatChannel/Composer/MessageComposerViewModel.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,12 +383,15 @@ open class MessageComposerViewModel: ObservableObject {
383383
log.debug("Access to photos granted.")
384384
let fetchOptions = PHFetchOptions()
385385
fetchOptions.sortDescriptors = [NSSortDescriptor(key: "creationDate", ascending: false)]
386-
DispatchQueue.main.async { [unowned self] in
387-
self.imageAssets = PHAsset.fetchAssets(with: fetchOptions)
386+
let assets = PHAsset.fetchAssets(with: fetchOptions)
387+
DispatchQueue.main.asyncAfter(deadline: .now() + 0.25) { [weak self] in
388+
self?.imageAssets = assets
388389
}
389390
case .denied, .restricted:
391+
self.imageAssets = PHFetchResult<PHAsset>()
390392
log.debug("Access to photos is denied, showing the no permissions screen.")
391393
case .notDetermined:
394+
self.imageAssets = PHFetchResult<PHAsset>()
392395
log.debug("Access to photos is still not determined.")
393396
@unknown default:
394397
log.debug("Unknown authorization status.")

0 commit comments

Comments
 (0)