Skip to content

Instantly share code, notes, and snippets.

@MoussaHellal
Created June 25, 2023 11:25
Show Gist options
  • Save MoussaHellal/17a045610c4d7c7f67dbf260309d6d96 to your computer and use it in GitHub Desktop.
Save MoussaHellal/17a045610c4d7c7f67dbf260309d6d96 to your computer and use it in GitHub Desktop.
DrinkyFlow.swift Our main flow object that will handle navigation, holding passable data and Back to root and previous view
//
// DrinkyFlow.swift
// CompleteNavigationSwiftUI
//
// Created by Moussa on 25/6/2023.
//
import Foundation
import SwiftUI
class DrinkyFlow: ObservableObject {
static let shared = DrinkyFlow()
@Published var path = NavigationPath()
@Published var selectedDrink: Drink = Drink(name: "", image: "", shortDescription: "", longDescription: "", ingredients: [])
func clear() {
path = .init()
}
func navigateBackToRoot() {
path.removeLast(path.count)
}
func backToPrevious() {
path.removeLast()
}
func navigateToDrinkyDetailView() {
path.append(DrinkyNavigation.drinkyDetails)
}
func navigateToDrinkyIngredientsView() {
path.append(DrinkyNavigation.drinkyIngredients)
}
func done() {
path = .init()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment