-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from erikdrobne/feature/tabbar
Feature: Tab bar coordinator
- Loading branch information
Showing
15 changed files
with
263 additions
and
22 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
63 changes: 63 additions & 0 deletions
63
...iftUICoordinatorExample/SwiftUICoordinatorExample/Coordinators/Tabs/TabsCoordinator.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// TabsCoordinator.swift | ||
// SwiftUICoordinatorExample | ||
// | ||
// Created by Erik Drobne on 11. 6. 24. | ||
// | ||
|
||
import Foundation | ||
|
||
import SwiftUI | ||
import SwiftUICoordinator | ||
|
||
class TabsCoordinator: TabBarRouting { | ||
let navigationController: NavigationController | ||
let tabBarController = UITabBarController() | ||
let tabs: [TabsCoordinatorRoute] | ||
|
||
// MARK: - Internal properties | ||
|
||
weak var parent: Coordinator? | ||
var childCoordinators = [WeakCoordinator]() | ||
|
||
// MARK: - Initialization | ||
|
||
init(parent: Coordinator?, navigationController: NavigationController) { | ||
self.parent = parent | ||
self.navigationController = navigationController | ||
self.tabs = [.red, .green, .blue] | ||
} | ||
|
||
func handle(_ action: CoordinatorAction) { | ||
parent?.handle(action) | ||
} | ||
} | ||
|
||
// MARK: - RouterViewFactory | ||
|
||
extension TabsCoordinator: RouterViewFactory { | ||
|
||
@ViewBuilder | ||
public func view(for route: TabsCoordinatorRoute) -> some View { | ||
switch route { | ||
case .red: | ||
VStack { | ||
Circle() | ||
.foregroundStyle(.red) | ||
} | ||
.padding(16) | ||
case .green: | ||
VStack { | ||
Circle() | ||
.foregroundStyle(.green) | ||
} | ||
.padding(16) | ||
case .blue: | ||
VStack { | ||
Circle() | ||
.foregroundStyle(.blue) | ||
} | ||
.padding(16) | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...CoordinatorExample/SwiftUICoordinatorExample/Coordinators/Tabs/TabsCoordinatorRoute.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// | ||
// TabsCoordinatorRoute.swift | ||
// SwiftUICoordinatorExample | ||
// | ||
// Created by Erik Drobne on 14. 6. 24. | ||
// | ||
|
||
import UIKit | ||
import SwiftUICoordinator | ||
|
||
enum TabsCoordinatorRoute: TabBarNavigationRoute { | ||
case red | ||
case green | ||
case blue | ||
|
||
var tabBarItem: UITabBarItem { | ||
switch self { | ||
case .red: | ||
UITabBarItem( | ||
title: "Red", | ||
image: UIImage(systemName: "pencil.tip"), | ||
tag: 0 | ||
) | ||
case .green: | ||
UITabBarItem( | ||
title: "Green", | ||
image: UIImage(systemName: "pencil"), | ||
tag: 1 | ||
) | ||
case .blue: | ||
UITabBarItem( | ||
title: "Blue", | ||
image: UIImage(systemName: "pencil.and.scribble"), | ||
tag: 2 | ||
) | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
13 changes: 13 additions & 0 deletions
13
Sources/SwiftUICoordinator/Routing/Route/TabBarNavigationRoute.swift
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// TabBarNavigationRoute.swift | ||
// | ||
// | ||
// Created by Erik Drobne on 24. 6. 24. | ||
// | ||
|
||
import UIKit | ||
|
||
@MainActor | ||
public protocol TabBarNavigationRoute: NavigationRoute, Hashable { | ||
var tabBarItem: UITabBarItem { get } | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.