MediaViewer
Features
- No dependencies
- Playback video
- Morphing transition
- Waiting for preview with thumbnail
- Custom preview
- Lazy load asset
- Landscape
Installation
dependencies: [
.package(url: "https://github.com/noppefoxwolf/MediaViewer", from: "x.x.x")
],
Usage
PreviewItem
The PreviewItem
is a protocol that provides the behavior necessary for previewing.
UIImage
and AVPlayer
have built-in implementations.
It can also be customized.
extension String: PreviewItem {
func makeViewController() async -> UIViewController {
UIHostingController(rootView: Text(self))
}
func makeThumbnailViewController() -> UIViewController? {
nil
}
}
PreviewController
PreviewItem
are displayed using PreviewController
.
PreviewController
uses a PreviewControllerDataSource
to retrieve PreviewItem
.
let vc = PreviewController()
vc.delegate = self
vc.dataSource = self
present(vc, animated: true)
PreviewControllerDataSource
func numberOfPreviewItems(in controller: PreviewController) -> Int
func previewController(_ controller: PreviewController, previewItemAt index: Int) -> any PreviewItem
PreviewControllerDelegate
PreviewControllerDelegate
supports animations on transitions.
func previewController(_ controller: PreviewController, transitionViewFor item: any PreviewItem) -> UIView?