Swiftpack.co -  lucamegh/Portal as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
lucamegh/Portal
Simplified view controller containment.
.package(url: "https://github.com/lucamegh/Portal.git", from: "1.0.0")

Portal 🌀

ContainerViewController is a container view controller (duh!) designed to display other view controllers.

import Portal

let loadingViewController = LoadingViewController(message: "Searching...")
let containerViewController = ContainerViewController(content: loadingViewController)
Cookbook.shared.search("spaghetti") { result in
    switch result {
        case .success([]):
            containerViewController.content = EmptyViewController()
        case .success(let recipes):
            containerViewController.content = RecipesViewController(recipes: recipes)
        case .failure(let error):
            containerViewController.content = ErrorViewController(error: error)
    }
}

Installation

Portal is distributed using Swift Package Manager. To install it into a project, simply add it as a dependency within your Package.swift manifest:

let package = Package(
    ...
    dependencies: [
        .package(url: "https://github.com/lucamegh/Portal", from: "1.0.0")
    ],
    ...
)

Usage

Changing content

Set the content property to a view controller to display it:

containerViewController.content = PostViewController(post: post)

If you want to animate the view controller transition, simply call the setViewController(_:animated:) method. By default, container view controllers will transiton using a 'cross dissolve' animation.

let articleViewController = ...
containerViewController.setContent(articleViewController, animated: true)

Custom transitions

To create a custom transiton, use the ContainerViewController.Transition.custom(animator:) method. This method accepts an object conforming to the UIViewControllerAnimatedTransitioning protocol.

class SlideAnimator: NSObject, UIViewControllerAnimatedTransitioning { ... }

let slideAnimator = SlideAnimator(direction: .leftToRight)

containerViewController.preferredTransition = .custom(animator: slideAnimator)

If you're going to reuse a custom transiton across your project, you might find it useful to create a static factory method like this:

extension ContainerViewController.Transition {

    static func slide(direction: SlideAnimator.Direction) -> Self {
        let slideAnimator = SlideAnimator(direction: direction)
        return custom(animator: slideAnimator)
    }
}

containerViewController.preferredTransition = .slide(direction: .leftToRight)

Credits

This library was inspired by Dave DeLong's A Better MVC blog post series.

GitHub

link
Stars: 0
Last commit: 2 weeks ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Release Notes

Portal 1.0.0
3 weeks ago

The first release of Portal.

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