Skip to content

Latest commit

 

History

History
125 lines (114 loc) · 2.49 KB

README.md

File metadata and controls

125 lines (114 loc) · 2.49 KB

FlowKit

Swift Platforms Swift Package Manager License

SwiftUI is great. But navigation isn't.

FlowKit is the ideal navigation library for SwiftUI.

Requirements

Platform Minimum Swift Version Installation
iOS 13.0+ 5.5 Swift Package Manager

Installation

Swift Package Manager

  • File -> Add Packages... And paste the repository URL.
  • Or add it to the dependencies value of your Package.swift.
dependencies: [
  .package(url: "https://github.com/Mercen-Lee/FlowKit.git", .branch("main"))
]

Usage

  • Push View
flow.push(NextView())
// or
flow.push(NextView(), animated: false)
  • Pop View
flow.pop()
flow.pop(3) // 3 Views
  • Pop View to Root
flow.popToRoot()
  • Replace Views
flow.replace([FirstView(), SecondView()])
  • Reload View
flow.reload()
  • Present Sheet
flow.sheet(SheetView())
  • Present Alert
let alert = Alert(title: "Error",
                  message: "Not Found",
                  dismissButton: .default("Ok"))
flow.alert(alert)

Example

App

import SwiftUI
import FlowKit

@main
struct SampleApp: App {
  var body: some Scene {
    WindowGroup {
      FlowPresenter(rootView: ContentView())
    }
  }
}

View

struct ContentView: View {
  @Flow var flow
  var body: some View {
    Button {
      flow.push(NextView())
    } label: {
      Text("Push")
    }
  }
}

struct NextView: View {
  @Flow var flow
  var body: some View {
    Button {
      flow.pop()
    } label: {
      Text("Pop")
    }
  }
}

TCA Example

Dependency

struct FlowDependency: DependencyKey {
  static var liveValue: FlowProvider {
    FlowProvider(rootView: ContentView())
  }
}

extension DependencyValues {
  var flow: FlowProvider {
    get { self[FlowDependency.self] }
    set { self[FlowDependency.self] = newValue }
  }
}

Reducer

struct Content: Reducer {
  @Dependency(\.flow) var flow
  ...
}