Skip to content

MediaViewer is customizable preview library

License

Notifications You must be signed in to change notification settings

noppefoxwolf/MediaViewer

Repository files navigation

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?

Apps Using

If you use a MediaViewer, add your app via Pull Request.

About

MediaViewer is customizable preview library

Topics

Resources

License

Stars

Watchers

Forks

Languages