https://github.com/inamiy/swiftui-photopicker
iOS 14 PHPickerViewController wrapper for SwiftUI with data loader support.
https://github.com/inamiy/swiftui-photopicker
Last synced: 8 months 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 (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2021-02-28T13:58:25.000Z (almost 5 years ago)
- Last Synced: 2025-03-27T02:43:19.851Z (9 months ago)
- Language: Swift
- Size: 13.7 KB
- Stars: 20
- Watchers: 3
- 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 = false
var 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)