Latest 0.1.1
Homepage https://github.com/AlexanderKaran/NavigationLayers
License MIT
Platforms ios 11.0
Authors

CI Status
Version
License
Platform

Getting Started

The way we build apps are changing; UIViewController’s are becoming less cluttered and should only be dealing with user interaction and layout. I often find when building a service I might want to show an alert no matter where the user is in the app so instead of trying to find the top UIViewController why not load it into a new window?

Have a lot of view stacking in your app? Why not take some of the screen flows and present them in a new window.

NavigationLayers give you the power to present any UIViewController in a new UIWindow which I call a NavigationLayer. The best part is once you dismiss the first UIViewController loaded into the NavigationLayer the new UIWindow and its root view get dismissed from memory.

Let see an example of showing a standard UIAlertViewController in a new NavigationLayer (UIWindow).

Here we use the default function create that uses the default options which do three things. First is to allow only one new NavigationLayer at a time, any new NavigationLayer added does not show as you don’t want to end up stacking endless alert views. The second and third options are for isStatusBarHidden and UIStatusBarStyle for the new NavigationLayer which take the current setting used for the visible UIViewController that is visible when the NavigationLayer presents the new Layer.

// Here we create the alert
let alert = UIAlertController(title: "New Window", message: "Alert in a new window or NavigationLayer", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default) { (_) in
    alert.dismiss(animated: true, completion: nil)
}
alert.addAction(action)

// Here we use the default function create that uses the default NavigationLayerOptions()
NavigationLayer.create(with: alert, animated: false, completion: nil)

Once you dismiss the UIAlertViewController, the system drops the NavigationLayer from memory.

Advance Usage

If you want to have more control you can use the create with options function which can be configured to allow multi NavigationLayer stacking and change the UIStatusBarStytle and isStatusBarHidden options for the new NavigationLayer.

// Here we create the alert
let alert = UIAlertController(title: "New Window", message: "Alert in a new window or NavigationLayer", preferredStyle: .alert)
let action = UIAlertAction(title: "Ok", style: .default) { (_) in
    alert.dismiss(animated: true, completion: nil)
}

// Here we use the create function with options that uses a custom NavigationLayerOptions()
let options = NavigationLayerOptions(allowWindowStacking: true)
NavigationLayer.create(with: options, and: alertOne, animated: false, completion: nil)

Each parameter in the NavigationLayerOptions has a default value so you can edit the value you’re interested in instead of all three.

NavigationLayerOptions(allowWindowStacking: <#T##Bool#>, prefersStatusBarHidden: <#T##Bool#>, statusBarStyle: <#T##UIStatusBarStyle#>)

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Requirements

iOS 11.00 and above

Installation

NavigationLayers is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod 'NavigationLayers'

Author

Alexander Karan, [email protected]

License

NavigationLayers is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "NavigationLayers",
    "version": "0.1.1",
    "swift_version": "4.2",
    "summary": "A navigation layer can be created anywhere even outside a UIViewController, creating a brand new navigation stack in a new window.",
    "description": "Apps are becoming more complex so why not make navigation 3d to help with building them. A navigation layer can be created anywhere even outside a UIViewController, creating a brand new navigation stack in a new window. The Navigation Layer is removed from memory as soon as you dismiss the first view controller. Create more complex navigation flows that are easier to control and dismiss with ease. Allow stacking of multiple Navigation Layers or play it safe by using the default settings, so you do not need to bother tracking your layers.",
    "homepage": "https://github.com/AlexanderKaran/NavigationLayers",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Alexander Karan": "[email protected]"
    },
    "source": {
        "git": "https://github.com/AlexanderKaran/NavigationLayers.git",
        "tag": "0.1.1"
    },
    "platforms": {
        "ios": "11.0"
    },
    "source_files": "NavigationLayers/Classes/**/*"
}

Pin It on Pinterest

Share This