Skip to content

Commit

Permalink
Update homeScreenWithStep view action handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-magda committed Oct 11, 2023
1 parent 41cf925 commit ef9e5cd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1432,6 +1432,7 @@
2C1860FB2923C540007D4EBF /* AppFeatureStateKsExtensions.swift */,
2C93C2D7292EBBB5004D1861 /* AuthSocialFeatureStateKsExtensions.swift */,
2C8CD9AD2994EFC5008DC09D /* DebugFeatureViewStateKsExtensions.swift */,
E9A1DA6F2ACFF86B006A9D4B /* FirstProblemOnboardingFeatureViewStateKsExtensions.swift */,
2CC7833D295DAE3E00A867CD /* OnboardingFeatureStateKsExtensions.swift */,
E9B55A5429C8A03E0066900E /* ProblemsLimitFeatureViewStateKsExtensions.swift */,
2C0DFB992923BB4300D30921 /* ProfileFeatureStateKsExtensions.swift */,
Expand All @@ -1445,7 +1446,6 @@
E9AD65A9292DC0BE00E574F0 /* TopicsRepetitionsFeatureStateKsExtensions.swift */,
2C54E4212A1F6672003406B9 /* TrackSelectionDetailsFeatureViewStateKsExtensions.swift */,
2C0EB9532A151C2B006DC84B /* TrackSelectionListFeatureViewStateKsExtensions.swift */,
E9A1DA6F2ACFF86B006A9D4B /* FirstProblemOnboardingFeatureViewStateKsExtensions.swift */,
);
path = Extensions;
sourceTree = "<group>";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,31 @@ extension AppViewController: AppViewControllerProtocol {
switch viewAction {
case .onboardingScreen:
return UIHostingController(rootView: OnboardingAssembly(output: viewModel).makeModule())
case .homeScreen, .studyPlan, .homeScreenWithStep:
// TODO: We will implement navigation to study plan in ALTAPPS-1004
let controller = AppTabBarController()
controller.appTabBarControllerDelegate = viewModel
return controller
case .homeScreen:
return AppTabBarController(initialTab: .home, appTabBarControllerDelegate: viewModel)
case .studyPlan:
return AppTabBarController(initialTab: .studyPlan, appTabBarControllerDelegate: viewModel)
case .homeScreenWithStep(let navigateToHomeScreenWithStepViewAction):
let tabBarController = AppTabBarController(
initialTab: .home,
appTabBarControllerDelegate: viewModel
)

if !tabBarController.isViewLoaded {
_ = tabBarController.view
}

DispatchQueue.main.async {
let index = tabBarController.selectedIndex
guard let navigationController = tabBarController.children[index] as? UINavigationController else {
return assertionFailure("Expected UINavigationController")
}

let stepAssembly = StepAssembly(stepRoute: navigateToHomeScreenWithStepViewAction.stepRoute)
navigationController.pushViewController(stepAssembly.makeModule(), animated: false)
}

return tabBarController
case .authScreen(let data):
let assembly = AuthSocialAssembly(isInSignUpMode: data.isInSignUpMode, output: viewModel)
return UIHostingController(rootView: assembly.makeModule())
Expand Down Expand Up @@ -136,21 +156,6 @@ extension AppViewController: AppViewControllerProtocol {
assert(children.count <= 2)

swapRootViewController(from: fromViewController, to: viewControllerToPresent)

if case .homeScreenWithStep(let navigateToHomeScreenWithStepAction) = viewAction {
guard let tabBarController = viewControllerToPresent as? AppTabBarController else {
return
}

guard let navigationController = tabBarController.viewControllers?.first as? UINavigationController else {
return
}

navigationController.pushViewController(
StepAssembly(stepRoute: navigateToHomeScreenWithStepAction.stepRoute).makeModule(),
animated: true
)
}
}

private func handleStreakRecoveryViewAction(_ viewAction: StreakRecoveryFeatureActionViewActionKs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,36 @@ protocol AppTabBarControllerDelegate: AnyObject {
}

final class AppTabBarController: UITabBarController {
weak var appTabBarControllerDelegate: AppTabBarControllerDelegate?
private weak var appTabBarControllerDelegate: AppTabBarControllerDelegate?

private var currentTabItem = AppTabItem.home

init(
initialTab: AppTabItem = .home,
appTabBarControllerDelegate: AppTabBarControllerDelegate?
) {
self.currentTabItem = initialTab
self.appTabBarControllerDelegate = appTabBarControllerDelegate
super.init(nibName: nil, bundle: nil)
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

override func viewDidLoad() {
super.viewDidLoad()
delegate = self

setViewControllers()

if let initialTabIndex = AppTabItem.availableItems.firstIndex(of: currentTabItem) {
selectedIndex = initialTabIndex
} else {
selectedIndex = 0
}

delegate = self
}

private func setViewControllers() {
Expand Down

0 comments on commit ef9e5cd

Please sign in to comment.