Skip to content

Commit

Permalink
Make tab bar controller as a root controller (#354)
Browse files Browse the repository at this point in the history
* Make tab bar controller application root view controller

* Hides tab bar on push
  • Loading branch information
ivan-magda authored Aug 28, 2018
1 parent 4238e2e commit 8354d95
Show file tree
Hide file tree
Showing 18 changed files with 131 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "learning-tab-bar-selected.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "learning-tab-bar-selected@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "learning-tab-bar-selected@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "training-tab-bar-selected.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "training-tab-bar-selected@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "training-tab-bar-selected@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,68 @@ final class ApplicationAssemblyImpl: BaseAssembly, ApplicationAssembly {
return savedModule
}

let navigationController = UINavigationController()
let controller = assemblyFactory.topicsAssembly.module(navigationController: navigationController)
navigationController.setViewControllers([controller], animated: false)
let tabBarController = UITabBarController()
// Hides dark shadow on navigation bar during transition.
tabBarController.view.backgroundColor = .white

let learningNavigationController = makeLearningController()
let trainingNavigationController = makeTrainingController()

tabBarController.setViewControllers(
[learningNavigationController, trainingNavigationController],
animated: false
)
tabBarController.selectedIndex = 0

let router = AppRouter(
assemblyFactory: assemblyFactory,
navigationController: navigationController
tabBarController: tabBarController,
navigationController: learningNavigationController,
assemblyFactory: assemblyFactory
)
let applicationModule = ApplicationModule(router: router)

ApplicationModuleHolder.instance.applicationModule = applicationModule

return applicationModule
}

private func makeLearningController() -> UINavigationController {
let navigationController = UINavigationController()
guard let controller = assemblyFactory.topicsAssembly.module(
navigationController: navigationController
) as? TopicsTableViewController else {
fatalError("TopicsTableViewController expected")
}

controller.title = NSLocalizedString("LearningTabTitle", comment: "")
controller.tabBarItem = UITabBarItem(
title: controller.title,
image: UIImage(named: "learning-tab-bar"),
tag: 0
)
controller.presenter.selectSegment(at: 0)
navigationController.setViewControllers([controller], animated: false)

return navigationController
}

private func makeTrainingController() -> UINavigationController {
let navigationController = UINavigationController()
guard let controller = assemblyFactory.topicsAssembly.module(
navigationController: navigationController
) as? TopicsTableViewController else {
fatalError("TopicsTableViewController expected")
}

controller.title = NSLocalizedString("TrainingTabTitle", comment: "")
controller.tabBarItem = UITabBarItem(
title: controller.title,
image: UIImage(named: "training-tab-bar"),
tag: 1
)
controller.presenter.selectSegment(at: 1)
navigationController.setViewControllers([controller], animated: false)

return navigationController
}
}
15 changes: 14 additions & 1 deletion ExamEGERussian/Sources/ApplicationLayer/Router/AppRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@ import UIKit

final class AppRouter: BaseRouter {
private(set) weak var window: UIWindow?
private(set) weak var tabBarController: UITabBarController?

override var navigationController: UINavigationController? {
return tabBarController?.selectedViewController as? UINavigationController
}

init(tabBarController: UITabBarController,
navigationController: UINavigationController,
assemblyFactory: AssemblyFactory
) {
self.tabBarController = tabBarController
super.init(assemblyFactory: assemblyFactory, navigationController: navigationController)
}

func start(_ window: UIWindow) {
self.window = window
window.rootViewController = navigationController
window.rootViewController = tabBarController
window.makeKeyAndVisible()
}

Expand Down
2 changes: 1 addition & 1 deletion ExamEGERussian/Sources/Common/Router/BaseRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class BaseRouter: RouterNavigational {
typealias DeriveViewControllerClosure = (UINavigationController) -> UIViewController

let assemblyFactory: AssemblyFactory
weak var navigationController: UINavigationController?
private(set) weak var navigationController: UINavigationController?

// MARK: Init

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class LessonsAssemblyImpl: BaseAssembly, LessonsAssembly {
)
controller.presenter = presenter
controller.title = knowledgeGraph[topicId]?.key.title
controller.hidesBottomBarWhenPushed = true

return controller
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ final class AdaptiveStepsAssembly: BaseAssembly, AdaptiveStepsAssemblyProtocol {
viewsService: serviceFactory.viewsService
)
controller.presenter = presenter
controller.hidesBottomBarWhenPushed = true

return controller
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ final class StandartStepsAssembly: BaseAssembly, StandartStepsAssemblyProtocol {
stepsService: serviceFactory.stepsService
)
controller.presenter = presenter
controller.hidesBottomBarWhenPushed = true
dataSource.stepPresenterDelegate = presenter

return controller
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,12 @@ final class TopicsTableViewController: UITableViewController {

private func setupView() {
tableView.registerNib(for: TopicTableViewCell.self)
title = NSLocalizedString("Topics", comment: "")

if #available(iOS 10.0, *) {
tableView.refreshControl = topicsRefreshControl
} else {
tableView.addSubview(topicsRefreshControl)
}

navigationItem.leftBarButtonItem = UIBarButtonItem(
title: NSLocalizedString("Logout", comment: ""),
style: .plain,
target: self,
action: #selector(onLogoutClick(_:))
)

navigationItem.rightBarButtonItem = UIBarButtonItem(
title: NSLocalizedString("SignIn", comment: ""),
style: .plain,
target: self,
action: #selector(onSignInClick(_:))
)

navigationItem.titleView = segmentedControl
}
}

Expand Down
3 changes: 3 additions & 0 deletions Stepic/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -568,3 +568,6 @@ PersonalDeadlineWidgetSuggestionText = "Constant learning is a key to success. W
"EmptyAuthViewTitle" = "It's You!";
"EmptyAuthViewSubtitle" = "Complete auth to study with comfort";
"EmptyAuthViewDescription" = "Authorized account allows you to sync progress";

"LearningTabTitle" = "Learning";
"TrainingTabTitle" = "Training";
3 changes: 3 additions & 0 deletions Stepic/ru.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,6 @@ PersonalDeadlineWidgetSuggestionText = "Постоянное обучение -
"EmptyAuthViewTitle" = "Это Вы!";
"EmptyAuthViewSubtitle" = "Пройдите авторизацию для более удобного обучения";
"EmptyAuthViewDescription" = "Авторизованный аккаунт позволит синхронизировать прогресс с другими устройствами";

"LearningTabTitle" = "Обучение";
"TrainingTabTitle" = "Тренировка";

0 comments on commit 8354d95

Please sign in to comment.