forXifLess / LinkNavigator

🌊 Easy & Powerful navigation library in SwiftUI
Other
395 stars 29 forks source link
deeplink-navigation ios navigationstack router swift swiftui uikit uinavigationcontroller url-router

Swift Version License

- Concept

✨ LinkNavigator is a library that helps you easily navigate between pages in SwiftUI.


- Translations

The following translations of this README have been contributed by members of the community:

If you'd like to contribute a translation, please open a PR with a link to a Gist!


- Basic Usage


- Advanced Usage


- Example

LinkNavigator provides 2 Example Apps.


- Getting Started

Step 1

Step 2

Step 3


- Installation

LinkNavigator supports Swift Package Manager.

let package = Package(
  name: "MyPackage",
  products: [
    .library(
      name: "MyPackage",
      targets: ["MyPackage"]),
  ],
  dependencies: [
    .package(url: "https://github.com/interactord/LinkNavigator.git", .upToNextMajor(from: "0.6.1"))
  ],
  targets: [
    .target(
      name: "MyPackage",
      dependencies: ["LinkNavigator"])
  ]
)


- Extra


- Q: In the view controller, I need to handle various tasks such as navigation or calling Firebase events when calling the screen. How should I handle it?

  - You can customize the WrappingController. I will provide an example code for customization.
```swift 
import SwiftUI
public final class DebugWrappingViewController<Content: View>: UIHostingController<Content>, MatchPathUsable {

  // MARK: Lifecycle

  public init(
    matchPath: String,
    trackEventUseCase: TrackEventUseCase,
    @ViewBuilder content: () -> Content)
  {
    self.matchPath = matchPath
    self.eventSubscriber = eventSubscriber
    self.trackEventUseCase = trackEventUseCase
    super.init(rootView: content())
  }

  required init?(coder _: NSCoder) {
    fatalError("init(coder:) has not been implemented")
  }

  deinit {
    print("✂️ \(matchPath) deinit...")
  }

  // MARK: Public

  public let matchPath: String

  public override func viewDidLoad() {
    super.viewDidLoad()
    view.backgroundColor = SystemColor.Background.Default.Base.getColor()
    print("🚗 \(matchPath)")
    trackEventUseCase.sendEvent(.screen(matchPath))
  }

  // MARK: Private

  private let trackEventUseCase: TrackEventUseCase
}

- License

This library is released under the MIT license. See LICENSE for details.