Swiftpack.co - Abedalkareem/Nami as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Abedalkareem.
Abedalkareem/Nami 0.0.2
A SwiftUI navigator.
⭐️ 3
🕓 3 years ago
iOS tvOS
.package(url: "https://github.com/Abedalkareem/Nami.git", from: "0.0.2")

Nami.. a SwiftUI Navigator
Nami... A SwiftUI navigator.

How to use

Root

To set the root view controller in AppDelegate.

let rootView = initRoot(with: AnyView(MainScreenView()))
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: rootView)
self.window = window
window.makeKeyAndVisible()

To replace the root view with animation.

replaceRoot(with: MainScreenView()) { view in
  view.transform = CGAffineTransform(scaleX: 2, y: 2)
  view.alpha = 0
}

Present and dismiss

To present a new view.

present(with: MainScreenView()) { view in
  view.transform = CGAffineTransform(scaleX: 2, y: 2)
  view.alpha = 0
}

To dismiss the top stack with animation.

dismiss() { view in
  view.transform = CGAffineTransform(scaleX: 2, y: 2)
  view.alpha = 0
}

Push and pop

To push a new view to the top stack.

push(with: MainScreenView())

To pop the top view from the top stack.

pop()

Example

struct MainScreenView: View {
  var body: some View {
    ZStack {
      Button(action: {
        push(with: MyNameScreenView())
      }) {
        Text("Say my name")
      }
    }
  }
}

struct MyNameScreenView: View {
  var body: some View {
    VStack {
      Text("Abedalkareem")
      Button(action: {
        pop()
      }) {
        Text("Back")
      }
    }
  }
}

License

The MIT License (MIT)

Copyright (c) 2020 Abedalkareem

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

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