Created
June 11, 2020 10:42
-
-
Save czars/fc7b77d6967654dcc4f2859126f4ac6b to your computer and use it in GitHub Desktop.
NavigationFlow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// FlowControllerView.swift | |
// NavigationFlow | |
// | |
// Created by Nick McConnell on 6/7/20. | |
// Copyright © 2020 Nick McConnell. All rights reserved. | |
// | |
import SwiftUI | |
protocol FlowControllerViewDelegate: class { | |
func didTapNext(to: FlowControllerView.NavigateTo) | |
} | |
struct FlowControllerView: View { | |
weak var modelDelegate: FlowControllerViewDelegate! | |
private let navigateTo2 = FlowState() | |
private let navigateTo3 = FlowState() | |
private let navigateTo4 = FlowState() | |
private let navigateToFinalFrom3 = FlowState() | |
private let navigateToFinalFrom4 = FlowState() | |
enum NavigateTo { | |
case screen1 | |
case screen2 | |
case screen3 | |
case screen4 | |
case finalFrom3 | |
case finalFrom4 | |
} | |
init(modelDelegate: FlowControllerViewDelegate) { | |
self.modelDelegate = modelDelegate | |
} | |
func navigate(to navigateTo: NavigateTo) { | |
switch navigateTo { | |
case .screen1: | |
break | |
case .screen2: | |
navigateTo2.next = true | |
case .screen3: | |
navigateTo3.next = true | |
case .screen4: | |
navigateTo4.next = true | |
case .finalFrom3: | |
navigateToFinalFrom3 .next = true | |
case .finalFrom4: | |
navigateToFinalFrom4.next = true | |
} | |
} | |
var body: some View { | |
NavigationView { | |
VStack() { | |
Screen(title: "Screen 1", didTapNext: { self.modelDelegate.didTapNext(to: .screen2) }) | |
Flow(state: navigateTo2) { | |
Screen(title: "Screen 2", didTapNext: { self.modelDelegate.didTapNext(to: .screen3) }) | |
Flow(state: navigateTo3) { | |
BranchedScreen( | |
title: "Screen 3", | |
didTapNextA: { self.modelDelegate.didTapNext(to: .finalFrom3) }, | |
didTapNextB: { self.modelDelegate.didTapNext(to: .screen4) } | |
) | |
Flow(state: navigateTo4) { | |
Screen(title: "Screen 4", didTapNext: { self.modelDelegate.didTapNext(to: .finalFrom4) }) | |
Flow(state: navigateToFinalFrom4) { | |
FinalScreen() | |
} | |
} | |
Flow(state: navigateToFinalFrom3) { | |
FinalScreen() | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment