Skip to content

Commit 526e7d7

Browse files
author
Christian Elies
committed
refactor(): small improvements: docs(readme): added some swiftui views
1 parent 0d494b1 commit 526e7d7

File tree

5 files changed

+22
-23
lines changed

5 files changed

+22
-23
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,14 @@ Use the `LazyVideos` wrapper if you want to fetch videos only on demand (request
406406
- **SwiftUI only**: `video.view` (*some View*)
407407

408408
*Get a ready-to-use **SwiftUI** view for displaying the video in your UI*
409+
410+
- **PHPicker**: SwiftUI port of the `PHPickerViewController`
411+
412+
*Use the `PHPickerViewController` in your `SwiftUI` applications*
413+
414+
- **PhotosUILivePhotoView**: SwiftUI port of the `PHLivePhotoView`
415+
416+
*Use the `PHLivePhotoView` in your `SwiftUI` applications*
409417

410418
### 🚀 `@propertyWrapper`
411419

Sources/MediaSwiftUI/API/LivePhoto/LivePhoto+SwiftUI.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,22 +95,19 @@ public extension LivePhoto {
9595
completion(result)
9696
} else {
9797
DispatchQueue.global(qos: .userInitiated).async {
98-
let loadVideos = result.map { $0.itemProvider.loadLivePhoto() }
99-
Publishers.MergeMany(loadVideos)
98+
let loadLivePhotos = result.map { $0.itemProvider.loadLivePhoto() }
99+
Publishers.MergeMany(loadLivePhotos)
100100
.collect()
101+
.receive(on: DispatchQueue.main)
101102
.sink { result in
102103
switch result {
103104
case let .failure(error):
104-
DispatchQueue.main.async {
105-
completion(.failure(error))
106-
}
105+
completion(.failure(error))
107106
case .finished: ()
108107
}
109108
} receiveValue: { urls in
110109
let browserResults = urls.map { BrowserResult<LivePhoto, PHLivePhoto>.data($0) }
111-
DispatchQueue.main.async {
112-
completion(.success(browserResults))
113-
}
110+
completion(.success(browserResults))
114111
}
115112
.store(in: &Garbage.cancellables)
116113
}

Sources/MediaSwiftUI/API/PHPicker/PHPicker.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import PhotosUI
1111
import SwiftUI
1212

1313
@available(iOS 14, macCatalyst 14, *)
14-
/// `SwiftUI` port of the `PHPicker`.
14+
/// `SwiftUI` port of the `PHPickerViewController`.
1515
public struct PHPicker: UIViewControllerRepresentable {
1616
/// The coordinator of the view. Mainly it's the delegate of the underlying `PHPickerViewController`.
1717
public final class Coordinator: NSObject, PHPickerViewControllerDelegate {

Sources/MediaSwiftUI/API/Photo/Photo+SwiftUI.swift

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -105,22 +105,19 @@ public extension Photo {
105105
completion(result)
106106
} else {
107107
DispatchQueue.global(qos: .userInitiated).async {
108-
let loadVideos = result.map { $0.itemProvider.loadImage() }
109-
Publishers.MergeMany(loadVideos)
108+
let loadImages = result.map { $0.itemProvider.loadImage() }
109+
Publishers.MergeMany(loadImages)
110110
.collect()
111+
.receive(on: DispatchQueue.main)
111112
.sink { result in
112113
switch result {
113114
case let .failure(error):
114-
DispatchQueue.main.async {
115-
completion(.failure(error))
116-
}
115+
completion(.failure(error))
117116
case .finished: ()
118117
}
119118
} receiveValue: { urls in
120119
let browserResults = urls.map { BrowserResult<Photo, UniversalImage>.data($0) }
121-
DispatchQueue.main.async {
122-
completion(.success(browserResults))
123-
}
120+
completion(.success(browserResults))
124121
}
125122
.store(in: &Garbage.cancellables)
126123
}

Sources/MediaSwiftUI/API/Video/Video+SwiftUI.swift

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -124,19 +124,16 @@ public extension Video {
124124
let loadVideos = result.map { $0.itemProvider.loadVideo() }
125125
Publishers.MergeMany(loadVideos)
126126
.collect()
127+
.receive(on: DispatchQueue.main)
127128
.sink { result in
128129
switch result {
129130
case let .failure(error):
130-
DispatchQueue.main.async {
131-
completion(.failure(error))
132-
}
131+
completion(.failure(error))
133132
case .finished: ()
134133
}
135134
} receiveValue: { urls in
136135
let browserResults = urls.map { BrowserResult<Video, URL>.data($0) }
137-
DispatchQueue.main.async {
138-
completion(.success(browserResults))
139-
}
136+
completion(.success(browserResults))
140137
}
141138
.store(in: &Garbage.cancellables)
142139
}

0 commit comments

Comments
 (0)