Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/inamiy/swiftui-photopicker
iOS 14 PHPickerViewController wrapper for SwiftUI with data loader support.
https://github.com/inamiy/swiftui-photopicker
Last synced: 29 days ago
JSON representation
iOS 14 PHPickerViewController wrapper for SwiftUI with data loader support.
- Host: GitHub
- URL: https://github.com/inamiy/swiftui-photopicker
- Owner: inamiy
- License: mit
- Created: 2021-02-16T14:42:59.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2021-02-28T13:58:25.000Z (over 3 years ago)
- Last Synced: 2024-04-15T02:56:33.938Z (7 months ago)
- Language: Swift
- Size: 13.7 KB
- Stars: 19
- Watchers: 4
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SwiftUI-PhotoPicker
iOS 14 PHPickerViewController wrapper for SwiftUI with data loader support.## How to Use
```swift
struct ContentView: View
{
@State
private var datas: [PhotoPickerData?] = []@State
private var isShowingPicker = falsevar body: some View
{
VStack(spacing: 40) {
Button("Select Image") {
self.isShowingPicker = true
}ScrollView {
LazyVGrid(columns: Array(repeating: GridItem(), count: 2)) {
ForEach(datas.enumerated().map { ($0, $1) }, id: \.0) { i, data in
if let image = data?.image {
Image(uiImage: image)
.resizable()
.scaledToFit()
}
else if let videoURL = data?.video {
VideoPlayer(player: AVPlayer(url: videoURL))
.frame(width: 200, height: 200, alignment: .center)
}
else if let livePhoto = data?.livePhoto {
LivePhotoView(livePhoto: .constant(livePhoto))
}
}
}
}
}
.sheet(isPresented: $isShowingPicker) {
PhotoPicker(
datas: $datas,
configuration: pickerConfig,
pattern: pickerPattern
)
}
}
}private let pickerPattern: PickerPattern = .any(of: [.images, .videos, .livePhotos])
private let pickerConfig: PHPickerConfiguration = {
var config = PHPickerConfiguration()
config.filter = pickerPattern.filter
config.selectionLimit = 0
config.preferredAssetRepresentationMode = .current // required for video
return config
}()
```## Example
See [Examples](Examples) for more information.
## License
[MIT](LICENSE)