Swiftpack.co - eure/AssetsPicker as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by eure.
eure/AssetsPicker 1.3.4
🏞The UI library to pick PHAsset
⭐️ 14
πŸ•“ 1 year ago
iOS
.package(url: "https://github.com/eure/AssetsPicker.git", from: "1.3.4")

πŸ“Έ MosaiqueAssetsPicker

Your customizable asset picker.

Overview

Whimsical AssetPicker

πŸ”Ά Requirements

iOS 10.0+ Xcode 10.1+ Swift 4.2+

πŸ“± Features

  • β˜‘ Load camera rolls and others albums
  • β˜‘ Customize cells
  • β˜‘ Customize style and localization
  • β˜‘ Custom header
  • β˜‘ Photo on the cloud
  • β˜‘ Permissions handling
  • β˜‘ Other asset ( LivePhoto, Video, Gif, .. )
  • β˜‘ Background downloading
  • ☐ Selection counter ( badge ? )

πŸ‘¨πŸ»β€πŸ’» Usage

Default value

let photoPicker = MosaiqueAssetPickerViewController()
photoPicker.pickerDelegate = self

present(photoPicker, animated: true, completion: nil)

Customization

Use Custom Cell classes

let cellRegistrator = AssetPickerCellRegistrator()
cellRegistrator.register(cellClass: Demo2AssetCell.self, forCellType: .asset)
cellRegistrator.register(cellClass: Demo2AssetCollectionCell.self, forCellType: .assetCollection)

let photoPicker = MosaiqueAssetPickerViewController()
                    .setCellRegistrator(cellRegistrator)

photoPicker.pickerDelegate = self

present(photoPicker, animated: true, completion: nil)

Use Custom Nib classes

let assetNib = UINib(nibName: String(describing: Demo3AssetNib.self), bundle: nil)
let assetCollectionNib = UINib(nibName: String(describing: Demo3AssetCollectionNib.self), bundle: nil)

let cellRegistrator = AssetPickerCellRegistrator()
cellRegistrator.register(nib: assetNib, forCellType: .asset)
cellRegistrator.register(nib: assetCollectionNib, forCellType: .assetCollection)

let photoPicker = MosaiqueAssetPickerViewController()
                    .setCellRegistrator(cellRegistrator)

photoPicker.pickerDelegate = self

present(photoPicker, animated: true, completion: nil)

Add header view

let headerView = UIView()
headerView.backgroundColor = .orange
headerView.translatesAutoresizingMaskIntoConstraints = false
headerView.heightAnchor.constraint(equalToConstant: 120).isActive = true

let photoPicker = MosaiqueAssetPickerViewController()
                    .setHeaderView(headerView, isHeaderFloating: true)

photoPicker.pickerDelegate = self

present(photoPicker, animated: true, completion: nil)

Other customization

func setSelectionMode(_ selectionMode: SelectionMode)
func setSelectionMode(_ selectionColor: UIColor)
func setSelectionColor(_ tintColor: UIColor)
func setNumberOfItemsPerRow(_ numberOfItemsPerRow: Int)
func setHeaderView(_ headerView: UIView, isHeaderFloating: Bool)
func setCellRegistrator(_ cellRegistrator: AssetPickerCellRegistrator)
func setMediaTypes(_ supportOnlyMediaType: [PHAssetMediaType])
func disableOnLibraryScrollAnimation()
func localize(_ localize: LocalizedStrings)

public enum SelectionMode {
    case single
    case multiple(limit: Int)
}

public struct LocalizedStrings {
    public var done: String = "Done"
    public var next: String = "Next"
    public var dismiss: String = "Dismiss"
    public var collections: String = "Collections"
    public var changePermissions: String = "Change your Photo Library permissions"
}

AssetFuture usage

AssetFuture can be used to dismiss the view controller once the asset is selected but before the asset is ready/downloaded. It can be optained through the delegate:

func photoPicker(_ pickerController: UIViewController, didPickAssets assets: [AssetFuture])

You can retreive asynchronously a thumbnail with onThumbnailCompletion: ((Result<UIImage, NSError>) -> Void)? And the final image with finalImageResult: Result<UIImage, NSError>?

As long as the AssetFuture is retained by you or the MosaiqueAssetPickerViewController, the asset will be fetched, using the network if needed, even if the app enters background. The fetch request is cancelled on release.

iOS14

The new iOS version introduce lots of improvements on the traditional image picker. You can default to it if the user runs iOS 14 by using the new API:

   MosaiqueAssetPickerPresenter.controller(delegate: self)

Installation

CocoaPods

pod 'MosaiqueAssetsPicker'

SPM:

dependencies: [
    .package(url: "https://github.com/eure/AssetsPicker.git", .upToNextMajor(from: "1.3.0"))
]

What's using MosaiqueAssetsPicker

  • Pairs Engage

Contributing

Feel free to contribute. You can format your code using swiftformat:

swiftformat .

Install it with

brew install swiftformat

Authors

License

AssetsPicker is released under the MIT license.

GitHub

link
Stars: 14
Last commit: 36 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.3.4
1 year ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics