Skip to content

Commit

Permalink
refactor tabbar into navigation folder from scene delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
grenos committed Apr 10, 2020
1 parent 996511f commit 0311ec9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 30 deletions.
12 changes: 12 additions & 0 deletions GHFollowers.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
7DB7350B2438AD9000E7B09B /* String+Ext.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350A2438AD9000E7B09B /* String+Ext.swift */; };
7DB7350D243F523700E7B09B /* PersistanceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350C243F523700E7B09B /* PersistanceManager.swift */; };
7DB7350F243F8AC100E7B09B /* FavoriteCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */; };
7DB7351224409BFE00E7B09B /* GFTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DB7351124409BFE00E7B09B /* GFTabBarController.swift */; };
7DFAC88A242A86D200F5780C /* GFAlertContainerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */; };
/* End PBXBuildFile section */

Expand Down Expand Up @@ -79,6 +80,7 @@
7DB7350A2438AD9000E7B09B /* String+Ext.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Ext.swift"; sourceTree = "<group>"; };
7DB7350C243F523700E7B09B /* PersistanceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PersistanceManager.swift; sourceTree = "<group>"; };
7DB7350E243F8AC100E7B09B /* FavoriteCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FavoriteCell.swift; sourceTree = "<group>"; };
7DB7351124409BFE00E7B09B /* GFTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFTabBarController.swift; sourceTree = "<group>"; };
7DFAC889242A86D200F5780C /* GFAlertContainerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GFAlertContainerView.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -123,6 +125,7 @@
isa = PBXGroup;
children = (
7D98BB352428FE75006C53E9 /* Info.plist */,
7DB7351024409BBD00E7B09B /* Navigation */,
7DA45F6A242BAEBC00AB426F /* Utilities */,
7DA45F67242B82F900AB426F /* Managers */,
7DA45F62242B73BD00AB426F /* Model */,
Expand Down Expand Up @@ -271,6 +274,14 @@
path = ViewControllers;
sourceTree = "<group>";
};
7DB7351024409BBD00E7B09B /* Navigation */ = {
isa = PBXGroup;
children = (
7DB7351124409BFE00E7B09B /* GFTabBarController.swift */,
);
path = Navigation;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -373,6 +384,7 @@
7D7C665224388F0900733687 /* GFItemInfoView.swift in Sources */,
7D98BB2A2428FE73006C53E9 /* SceneDelegate.swift in Sources */,
7DA45F832433F4FC00AB426F /* Constants.swift in Sources */,
7DB7351224409BFE00E7B09B /* GFTabBarController.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Binary file not shown.
36 changes: 36 additions & 0 deletions GHFollowers/Navigation/GFTabBarController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// GFTabBarController.swift
// GHFollowers
//
// Created by Vasileios Gkreen on 10/04/2020.
// Copyright © 2020 Vasileios Gkreen. All rights reserved.
//

import UIKit

class GFTabBarController: UITabBarController {

override func viewDidLoad() {
super.viewDidLoad()

UITabBar.appearance().tintColor = .systemGreen
// put NAvigation Controllers inside the tab bar controller
viewControllers = [createSearchNC(), createFavoritesNC()]
}

func createSearchNC() -> UINavigationController {
let searchVC = SearchVC()
searchVC.title = "Search"
searchVC.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0)

return UINavigationController(rootViewController: searchVC)
}

func createFavoritesNC() -> UINavigationController {
let favoritesVC = FavoriteListVC()
favoritesVC.title = "Favorites"
favoritesVC.tabBarItem = UITabBarItem(tabBarSystemItem: .favorites, tag: 1)

return UINavigationController(rootViewController: favoritesVC)
}
}
32 changes: 2 additions & 30 deletions GHFollowers/Support/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.



// MARK: Set root view controller after deletion of storyboard
guard let myWindowScene = (scene as? UIWindowScene) else { return }

//init a new ui window with the scenre we created above that fills the entire screen
window = UIWindow(frame: myWindowScene.coordinateSpace.bounds)
window?.windowScene = myWindowScene
// we need to set a root VC for our windowScene
window?.rootViewController = createTabBar()
// we need to set a root VC for our windowScene and initialize the navigation class
window?.rootViewController = GFTabBarController()
// to show the window
window?.makeKeyAndVisible()

Expand All @@ -35,33 +34,6 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
}


// MARK: Initialize navigation
// init navigation controllers
func createSearchNC() -> UINavigationController {
let searchVC = SearchVC()
searchVC.title = "Search"
searchVC.tabBarItem = UITabBarItem(tabBarSystemItem: .search, tag: 0)

return UINavigationController(rootViewController: searchVC)
}

func createFavoritesNC() -> UINavigationController {
let favoritesVC = FavoriteListVC()
favoritesVC.title = "Favorites"
favoritesVC.tabBarItem = UITabBarItem(tabBarSystemItem: .favorites, tag: 1)

return UINavigationController(rootViewController: favoritesVC)
}
// put them inside the tab bar controller
func createTabBar() -> UITabBarController {
let tabbar = UITabBarController()
UITabBar.appearance().tintColor = .systemGreen
tabbar.viewControllers = [createSearchNC(), createFavoritesNC()]

return tabbar
}


// MARK: Global nav styles
func configureNavigationBar () {
UINavigationBar.appearance().tintColor = .systemGreen
Expand Down

0 comments on commit 0311ec9

Please sign in to comment.