Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/flow actions #14

Merged
merged 10 commits into from
Jul 24, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
176F3CB529B8BF71009C4987 /* ShapesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176F3CB429B8BF71009C4987 /* ShapesView.swift */; };
176F3CB829B8C05B009C4987 /* ShapesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176F3CB729B8C05B009C4987 /* ShapesCoordinator.swift */; };
176F3CBB29B8C162009C4987 /* ShapesRoute.swift in Sources */ = {isa = PBXBuildFile; fileRef = 176F3CBA29B8C162009C4987 /* ShapesRoute.swift */; };
17AABAED2A6D5CF400AFE8A7 /* SimpleShapesAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17AABAEC2A6D5CF400AFE8A7 /* SimpleShapesAction.swift */; };
17AABAEF2A6D5E1500AFE8A7 /* CustomShapesAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17AABAEE2A6D5E1500AFE8A7 /* CustomShapesAction.swift */; };
17AABAF12A6D5F2100AFE8A7 /* ShapesAction.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17AABAF02A6D5F2100AFE8A7 /* ShapesAction.swift */; };
17F1183529CC63B1004755DB /* SimpleShapesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F1183429CC63B1004755DB /* SimpleShapesView.swift */; };
17F1183729CC63C0004755DB /* CustomShapesView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F1183629CC63C0004755DB /* CustomShapesView.swift */; };
17F1183B29CC6678004755DB /* SimpleShapesCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17F1183A29CC6678004755DB /* SimpleShapesCoordinator.swift */; };
Expand All @@ -35,6 +38,9 @@
176F3CB429B8BF71009C4987 /* ShapesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapesView.swift; sourceTree = "<group>"; };
176F3CB729B8C05B009C4987 /* ShapesCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapesCoordinator.swift; sourceTree = "<group>"; };
176F3CBA29B8C162009C4987 /* ShapesRoute.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapesRoute.swift; sourceTree = "<group>"; };
17AABAEC2A6D5CF400AFE8A7 /* SimpleShapesAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleShapesAction.swift; sourceTree = "<group>"; };
17AABAEE2A6D5E1500AFE8A7 /* CustomShapesAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomShapesAction.swift; sourceTree = "<group>"; };
17AABAF02A6D5F2100AFE8A7 /* ShapesAction.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShapesAction.swift; sourceTree = "<group>"; };
17E1C1FF2A1BD86D00542AB9 /* SwiftUICoordinator.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = SwiftUICoordinator.xctestplan; sourceTree = "<group>"; };
17F1183429CC63B1004755DB /* SimpleShapesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SimpleShapesView.swift; sourceTree = "<group>"; };
17F1183629CC63C0004755DB /* CustomShapesView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomShapesView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -136,6 +142,7 @@
children = (
176F3CB729B8C05B009C4987 /* ShapesCoordinator.swift */,
176F3CBA29B8C162009C4987 /* ShapesRoute.swift */,
17AABAF02A6D5F2100AFE8A7 /* ShapesAction.swift */,
);
path = Shapes;
sourceTree = "<group>";
Expand All @@ -152,6 +159,7 @@
children = (
17F1183A29CC6678004755DB /* SimpleShapesCoordinator.swift */,
17F1183C29CC668F004755DB /* SimpleShapesRoute.swift */,
17AABAEC2A6D5CF400AFE8A7 /* SimpleShapesAction.swift */,
);
path = SimpleShapes;
sourceTree = "<group>";
Expand All @@ -161,6 +169,7 @@
children = (
17F1183E29CC8A57004755DB /* CustomShapesCoordinator.swift */,
17F1184029CC8A84004755DB /* CustomShapesRoute.swift */,
17AABAEE2A6D5E1500AFE8A7 /* CustomShapesAction.swift */,
);
path = CustomShapes;
sourceTree = "<group>";
Expand Down Expand Up @@ -246,18 +255,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
17AABAEF2A6D5E1500AFE8A7 /* CustomShapesAction.swift in Sources */,
17F1183729CC63C0004755DB /* CustomShapesView.swift in Sources */,
17F1183B29CC6678004755DB /* SimpleShapesCoordinator.swift in Sources */,
17F1184729CC8F1A004755DB /* Tower.swift in Sources */,
17F1184329CC8BA6004755DB /* Triangle.swift in Sources */,
1732C9FC29A6607500C2BC1F /* SwiftUICoordinatorExampleApp.swift in Sources */,
17F1184529CC8CF6004755DB /* Star.swift in Sources */,
17AABAF12A6D5F2100AFE8A7 /* ShapesAction.swift in Sources */,
176F3CB829B8C05B009C4987 /* ShapesCoordinator.swift in Sources */,
176F3CB529B8BF71009C4987 /* ShapesView.swift in Sources */,
17360A412A1275D600DB2296 /* FadeTransition.swift in Sources */,
17F1183D29CC668F004755DB /* SimpleShapesRoute.swift in Sources */,
17F1183529CC63B1004755DB /* SimpleShapesView.swift in Sources */,
176F3CBB29B8C162009C4987 /* ShapesRoute.swift in Sources */,
17AABAED2A6D5CF400AFE8A7 /* SimpleShapesAction.swift in Sources */,
17F1183F29CC8A57004755DB /* CustomShapesCoordinator.swift in Sources */,
17F1184129CC8A84004755DB /* CustomShapesRoute.swift in Sources */,
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// CustomShapesAction.swift
// SwiftUICoordinatorExample
//
// Created by Erik Drobne on 23/07/2023.
//

import Foundation
import SwiftUICoordinator

enum CustomShapesAction: CoordinatorAction {
case triangle
case star
case tower
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import SwiftUI
import SwiftUI
import SwiftUICoordinator

class CustomShapesCoordinator: NSObject, Coordinator, Navigator {

class CustomShapesCoordinator: Routing {
// MARK: - Internal properties

weak var parent: Coordinator? = nil
Expand All @@ -25,15 +25,19 @@ class CustomShapesCoordinator: NSObject, Coordinator, Navigator {
self.parent = parent
self.navigationController = navigationController
self.startRoute = startRoute
super.init()
}

func navigate(to route: NavigationRoute) {
guard let route = route as? CustomShapesRoute else {
return
func handle(_ action: CoordinatorAction) {
switch action {
case CustomShapesAction.triangle:
try? show(route: .triangle)
case CustomShapesAction.star:
try? show(route: .star)
case CustomShapesAction.tower:
try? show(route: .tower)
default:
parent?.handle(action)
}

try? show(route: route)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ShapesAction.swift
// SwiftUICoordinatorExample
//
// Created by Erik Drobne on 23/07/2023.
//

import Foundation
import SwiftUICoordinator

enum ShapesAction: CoordinatorAction {
case simpleShapes
case customShapes
case featuredShape(NavigationRoute)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import SwiftUICoordinator

class ShapesCoordinator: NSObject, Coordinator, Navigator {
class ShapesCoordinator: Routing {

// MARK: - Internal properties

Expand All @@ -23,32 +23,31 @@ class ShapesCoordinator: NSObject, Coordinator, Navigator {
init(startRoute: ShapesRoute) {
self.navigationController = NavigationController()
self.startRoute = startRoute
super.init()

setup()
}

func navigate(to route: NavigationRoute) {
switch route {
case ShapesRoute.simpleShapes:
func handle(_ action: CoordinatorAction) {
switch action {
case ShapesAction.simpleShapes:
let coordinator = makeSimpleShapesCoordinator()
try? coordinator.start()
case ShapesRoute.customShapes:
case ShapesAction.customShapes:
let coordinator = makeCustomShapesCoordinator()
try? coordinator.start()
case ShapesRoute.featuredShape(let route):
case let ShapesAction.featuredShape(route):
switch route {
case let shapeRoute as SimpleShapesRoute:
case let shapeRoute as SimpleShapesRoute where shapeRoute != .simpleShapes:
let coordinator = makeSimpleShapesCoordinator()
coordinator.append(routes: [.simpleShapes, shapeRoute])
case let shapeRoute as CustomShapesRoute:
case let shapeRoute as CustomShapesRoute where shapeRoute != .customShapes:
let coordinator = makeCustomShapesCoordinator()
coordinator.append(routes: [.customShapes, shapeRoute])
default:
return
}
default:
return
break
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum ShapesRoute: NavigationRoute {
case shapes
case simpleShapes
case customShapes
case featuredShape(NavigationRoute)
case featuredShape

var title: String? {
switch self {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// SimpleShapesAction.swift
// SwiftUICoordinatorExample
//
// Created by Erik Drobne on 23/07/2023.
//

import Foundation
import SwiftUICoordinator

enum SimpleShapesAction: CoordinatorAction {
case rect
case roundedRect
case capsule
case ellipse
case circle
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import SwiftUI
import SwiftUICoordinator

class SimpleShapesCoordinator: NSObject, Coordinator, Navigator {
class SimpleShapesCoordinator: Routing {

// MARK: - Internal properties

Expand All @@ -23,7 +23,6 @@ class SimpleShapesCoordinator: NSObject, Coordinator, Navigator {
self.parent = parent
self.navigationController = navigationController
self.startRoute = startRoute
super.init()
}

func presentRoot() {
Expand All @@ -35,12 +34,21 @@ class SimpleShapesCoordinator: NSObject, Coordinator, Navigator {
routing.childCoordinators.removeAll()
}

func navigate(to route: NavigationRoute) {
guard let route = route as? SimpleShapesRoute else {
return
func handle(_ action: CoordinatorAction) {
switch action {
case SimpleShapesAction.rect:
try? show(route: .rect)
case SimpleShapesAction.roundedRect:
try? show(route: .roundedRect)
case SimpleShapesAction.capsule:
try? show(route: .capsule)
case SimpleShapesAction.ellipse:
try? show(route: .ellipse)
case SimpleShapesAction.circle:
try? show(route: .circle)
default:
parent?.handle(action)
}

try? show(route: route)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ extension CustomShapesView {
var coordinator: Coordinator?

func didTapTriangle() {
coordinator?.navigate(to: CustomShapesRoute.triangle)
coordinator?.handle(CustomShapesAction.triangle)
}

func didTapStar() {
coordinator?.navigate(to: CustomShapesRoute.star)
coordinator?.handle(CustomShapesAction.star)
}

func didTapTower() {
coordinator?.navigate(to: CustomShapesRoute.tower)
coordinator?.handle(CustomShapesAction.tower)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ extension ShapesView {
var coordinator: Coordinator?

func didTapBuiltIn() {
coordinator?.navigate(to: ShapesRoute.simpleShapes)
coordinator?.handle(ShapesAction.simpleShapes)
}

func didTapCustom() {
coordinator?.navigate(to: ShapesRoute.customShapes)
coordinator?.handle(ShapesAction.customShapes)
}

func didTapFeatured() {
Expand All @@ -60,7 +60,7 @@ extension ShapesView {
return
}

coordinator?.navigate(to: ShapesRoute.featuredShape(route))
coordinator?.handle(ShapesAction.featuredShape(route))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,23 @@ extension SimpleShapesView {
var coordinator: Coordinator?

func didTapRectangle() {
coordinator?.navigate(to: SimpleShapesRoute.rect)
coordinator?.handle(SimpleShapesAction.rect)
}

func didTapRoundedRectangle() {
coordinator?.navigate(to: SimpleShapesRoute.roundedRect)
coordinator?.handle(SimpleShapesAction.roundedRect)
}

func didTapCapsule() {
coordinator?.navigate(to: SimpleShapesRoute.capsule)
coordinator?.handle(SimpleShapesAction.capsule)
}

func didTapEllipse() {
coordinator?.navigate(to: SimpleShapesRoute.ellipse)
coordinator?.handle(SimpleShapesAction.ellipse)
}

func didTapCircle() {
coordinator?.navigate(to: SimpleShapesRoute.circle)
coordinator?.handle(SimpleShapesAction.circle)
}
}
}
Expand Down
Loading