MediaViewer

0.1.3

A comfortable media viewer like the iOS standard.
jrsaruo/MediaViewer

What's New

Release 0.1.3

2024-02-13T18:26:43Z

What's Changed

🎉 New Features

  • Changed to show only media when zoomed by @jrsaruo in #97

💊 Bug Fixes

  • Fixed that the toolbar remains invisible by @jrsaruo in #94
  • Fixed assertion failure by @jrsaruo in #96
  • Fixed that bars disappear after deleting media by @jrsaruo in #98
  • Fixed the page control bar state by @jrsaruo in #99

🧰 Maintenance

Other Changes

Full Changelog: 0.1.2...0.1.3

MediaViewer

A comfortable media viewer like the iOS standard.

MediaViewerDemo MediaViewerDemo _camera

Requirements

  • iOS 16+
  • Swift 5.8+

How to use

  1. Make a type that conforms to MediaViewerDataSource protocol.

    extension YourViewController: MediaViewerDataSource {
        
        // You can specify any type that conforms to `Hashable`.
        typealias MediaIdentifier = UIImage
        
        // var images: [UIImage]
        
        func mediaIdentifiers(
            for mediaViewer: MediaViewerViewController
        ) -> [MediaIdentifier] {
            images
        }
        
        func mediaViewer(
            _ mediaViewer: MediaViewerViewController,
            mediaWith mediaIdentifier: MediaIdentifier // UIImage
        ) -> Media {
            .sync(mediaIdentifier)
            // Or you can fetch media asynchronously by `.async { ... }`
        }
        
        func mediaViewer(
            _ mediaViewer: MediaViewerViewController,
            transitionSourceViewForMediaWith mediaIdentifier: MediaIdentifier
        ) -> UIView? {
            // Return a view that is animated when the viewer opens or closes.
            imageView(for: mediaIdentifier)
        }
    }
  2. Create a MediaViewerViewController instance and push it. That's all! 🎉

    let mediaViewer = MediaViewerViewController(opening: image, dataSource: self)
    navigationController?.delegate = mediaViewer
    navigationController?.pushViewController(mediaViewer, animated: true)

See demo for more detailed usage.

Using MediaViewer in your project

To use the MediaViewer library in a SwiftPM project, add the following line to the dependencies in your Package.swift file:

.package(url: "https://github.com/jrsaruo/MediaViewer", from: "0.1.3"),

and add MediaViewer as a dependency for your target:

.target(name: "<target>", dependencies: [
    .product(name: "MediaViewer", package: "MediaViewer"),
    // other dependencies
]),

Finally, add import MediaViewer in your source code.

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Dec 02 2024 03:58:39 GMT-1000 (Hawaii-Aleutian Standard Time)