Go to file
Leif a68682508d Add Package.resolved 2023-03-11 14:24:13 -07:00
.github/workflows Update CI.yml 2023-03-07 18:02:52 -07:00
Sources/OpenBytesNavigation init 2023-03-07 17:47:53 -07:00
Tests/OpenBytesNavigationTests init 2023-03-07 17:47:53 -07:00
.gitignore init 2023-03-07 17:47:53 -07:00
LICENSE Create LICENSE 2023-03-07 17:52:23 -07:00
Package.resolved Add Package.resolved 2023-03-11 14:24:13 -07:00
Package.swift init 2023-03-07 17:47:53 -07:00
README.md Update README.md 2023-03-07 18:42:35 -07:00

README.md

OpenBytesNavigation

OpenBytesNavigation is a SwiftUI library that provides a flexible and easy-to-use navigation system for your SwiftUI apps. It allows you to navigate between views, show modal views, display alerts and action sheets, and show toast notifications.

Usage

To use OpenBytesNavigation, you need to create an instance of OpenBytesNavigationPath, which keeps track of the navigation state. You can then use the OpenBytesNavigationView view to display your content and provide navigation functionality.

import OpenBytesNavigation
import SwiftUI

struct ContentView: View {
    @ObservedObject private var path = OpenBytesNavigationPath(id: "path_id")

    var body: some View {
        OpenBytesNavigationView(path: path) {
            // your content here
        }
    }
}

Navigation Examples

SwiftUI Previews

Call the preview function on OpenBytesNavigationView to create a preview of your navigation stack. This is useful for SwiftUI previews as the path won't be able to save.

struct ExampleView_Previews: PreviewProvider {
    static var previews: some View {
        OpenBytesNavigationView.preview {
            // your content here
        }
    }
}

Action Sheet

path.actionSheet(
    title: "Delete Item?",
    actions: {
        Button("Delete", role: .destructive) {
            // Delete item
        }
    },
    message: {
        Text("Are you sure you want to delete this item?")
    }
)

Alert

path.alert(
    title: Text("Error"),
    message: Text("An error occurred. Please try again."),
    primaryButton: .default(Text("OK")),
    secondaryButton: .cancel()
)

Modal

path.modal(
    body: {
        Text("Modal body")
    }
)

Toast

path.toast(
    title: "Success",
    message: "Item saved successfully",
    style: .success
)

Push

.navigationDestination(for: Date.self, destination: { DateView(date: $0) })
...
path.push(Date())

Pop

path.pop()

Save and Load

let id = "test"
let path = OpenBytesNavigationPath(id: id, isPreview: false)

XCTAssertEqual(path.navigation.count, 0)

path.push("Value")

XCTAssertEqual(path.navigation.count, 1)

path.save()

let loadedPath = OpenBytesNavigationPath.load(id: id)

XCTAssertEqual(loadedPath.navigation.count, path.navigation.count)