Skip to content

Commit

Permalink
refactor(): small improvements: docs(readme): added some swiftui views
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Elies committed May 4, 2021
1 parent 0d494b1 commit 526e7d7
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 23 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,14 @@ Use the `LazyVideos` wrapper if you want to fetch videos only on demand (request
- **SwiftUI only**: `video.view` (*some View*)

*Get a ready-to-use **SwiftUI** view for displaying the video in your UI*

- **PHPicker**: SwiftUI port of the `PHPickerViewController`

*Use the `PHPickerViewController` in your `SwiftUI` applications*

- **PhotosUILivePhotoView**: SwiftUI port of the `PHLivePhotoView`

*Use the `PHLivePhotoView` in your `SwiftUI` applications*

### 🚀 `@propertyWrapper`

Expand Down
13 changes: 5 additions & 8 deletions Sources/MediaSwiftUI/API/LivePhoto/LivePhoto+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,22 +95,19 @@ public extension LivePhoto {
completion(result)
} else {
DispatchQueue.global(qos: .userInitiated).async {
let loadVideos = result.map { $0.itemProvider.loadLivePhoto() }
Publishers.MergeMany(loadVideos)
let loadLivePhotos = result.map { $0.itemProvider.loadLivePhoto() }
Publishers.MergeMany(loadLivePhotos)
.collect()
.receive(on: DispatchQueue.main)
.sink { result in
switch result {
case let .failure(error):
DispatchQueue.main.async {
completion(.failure(error))
}
completion(.failure(error))
case .finished: ()
}
} receiveValue: { urls in
let browserResults = urls.map { BrowserResult<LivePhoto, PHLivePhoto>.data($0) }
DispatchQueue.main.async {
completion(.success(browserResults))
}
completion(.success(browserResults))
}
.store(in: &Garbage.cancellables)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/MediaSwiftUI/API/PHPicker/PHPicker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import PhotosUI
import SwiftUI

@available(iOS 14, macCatalyst 14, *)
/// `SwiftUI` port of the `PHPicker`.
/// `SwiftUI` port of the `PHPickerViewController`.
public struct PHPicker: UIViewControllerRepresentable {
/// The coordinator of the view. Mainly it's the delegate of the underlying `PHPickerViewController`.
public final class Coordinator: NSObject, PHPickerViewControllerDelegate {
Expand Down
13 changes: 5 additions & 8 deletions Sources/MediaSwiftUI/API/Photo/Photo+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,22 +105,19 @@ public extension Photo {
completion(result)
} else {
DispatchQueue.global(qos: .userInitiated).async {
let loadVideos = result.map { $0.itemProvider.loadImage() }
Publishers.MergeMany(loadVideos)
let loadImages = result.map { $0.itemProvider.loadImage() }
Publishers.MergeMany(loadImages)
.collect()
.receive(on: DispatchQueue.main)
.sink { result in
switch result {
case let .failure(error):
DispatchQueue.main.async {
completion(.failure(error))
}
completion(.failure(error))
case .finished: ()
}
} receiveValue: { urls in
let browserResults = urls.map { BrowserResult<Photo, UniversalImage>.data($0) }
DispatchQueue.main.async {
completion(.success(browserResults))
}
completion(.success(browserResults))
}
.store(in: &Garbage.cancellables)
}
Expand Down
9 changes: 3 additions & 6 deletions Sources/MediaSwiftUI/API/Video/Video+SwiftUI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,19 +124,16 @@ public extension Video {
let loadVideos = result.map { $0.itemProvider.loadVideo() }
Publishers.MergeMany(loadVideos)
.collect()
.receive(on: DispatchQueue.main)
.sink { result in
switch result {
case let .failure(error):
DispatchQueue.main.async {
completion(.failure(error))
}
completion(.failure(error))
case .finished: ()
}
} receiveValue: { urls in
let browserResults = urls.map { BrowserResult<Video, URL>.data($0) }
DispatchQueue.main.async {
completion(.success(browserResults))
}
completion(.success(browserResults))
}
.store(in: &Garbage.cancellables)
}
Expand Down

0 comments on commit 526e7d7

Please sign in to comment.