diff --git a/Source/CourseDashboardViewController.swift b/Source/CourseDashboardViewController.swift index a1d9d09d3..969eae184 100644 --- a/Source/CourseDashboardViewController.swift +++ b/Source/CourseDashboardViewController.swift @@ -357,6 +357,8 @@ extension UITabBarController { if let viewController = viewController as? CourseOutlineViewController, viewController.courseOutlineMode == courseOutlineMode { return index + } else { + return index } } else if let forwardingNavigationController = viewController as? ForwardingNavigationController, let rootViewController = forwardingNavigationController.viewControllers.first, diff --git a/Source/CourseDateBannerView.swift b/Source/CourseDateBannerView.swift index 9e9a7981d..d3874d702 100644 --- a/Source/CourseDateBannerView.swift +++ b/Source/CourseDateBannerView.swift @@ -10,6 +10,16 @@ import UIKit private let cornerRadius: CGFloat = 0 +protocol BannerView { + var delegate: CourseShiftDatesDelegate? { get set } + var bannerInfo: DatesBannerInfo? { get set } + func setupView() +} + +extension CourseDateBannerView: BannerView {} +extension NewCourseDateBannerView: BannerView {} + + protocol CourseShiftDatesDelegate: AnyObject { func courseShiftDateButtonAction() } diff --git a/Source/HTMLBlockViewController.swift b/Source/HTMLBlockViewController.swift index 2b42f792d..d379416d5 100644 --- a/Source/HTMLBlockViewController.swift +++ b/Source/HTMLBlockViewController.swift @@ -22,7 +22,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel private let environment: Environment private let subkind: CourseHTMLBlockSubkind - private lazy var courseDateBannerView = CourseDateBannerView(frame: .zero) + private lazy var courseDateBannerViewContainer = UIView() private let webController: AuthenticatedWebViewController private let loader = BackedStream() @@ -65,8 +65,8 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel } private func setupViews() { - view.addSubview(courseDateBannerView) - courseDateBannerView.snp.makeConstraints { make in + view.addSubview(courseDateBannerViewContainer) + courseDateBannerViewContainer.snp.makeConstraints { make in make.trailing.equalTo(view) make.leading.equalTo(view) make.top.equalTo(view) @@ -86,7 +86,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel webController.view.snp.remakeConstraints { make in make.trailing.equalTo(view) make.leading.equalTo(view) - make.top.equalTo(courseDateBannerView.snp.bottom) + make.top.equalTo(courseDateBannerViewContainer.snp.bottom) make.bottom.equalTo(view) } } @@ -101,7 +101,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel webController.view.snp.remakeConstraints { make in make.trailing.equalTo(view) make.leading.equalTo(view) - make.top.equalTo(courseDateBannerView.snp.bottom) + make.top.equalTo(courseDateBannerViewContainer.snp.bottom) } openInBrowserView.snp.remakeConstraints { make in @@ -158,16 +158,31 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel } else { guard let status = bannerModel.bannerInfo.status else { return } + var courseDateBannerView: BannerView + + if environment.config.isNewComponentNavigationEnabled { + courseDateBannerView = NewCourseDateBannerView() + } else { + courseDateBannerView = CourseDateBannerView() + } + + if let courseDateBannerView = courseDateBannerView as? UIView { + courseDateBannerViewContainer.addSubview(courseDateBannerView) + courseDateBannerView.snp.remakeConstraints { make in + make.edges.equalTo(courseDateBannerViewContainer) + } + } + if status == .resetDatesBanner { courseDateBannerView.delegate = self courseDateBannerView.bannerInfo = bannerModel.bannerInfo courseDateBannerView.setupView() + height = StandardVerticalMargin * 16 trackDateBannerAppearanceEvent(bannerModel: bannerModel) - height = courseDateBannerView.heightForView(width: view.frame.size.width) } } - courseDateBannerView.snp.remakeConstraints { make in + courseDateBannerViewContainer.snp.remakeConstraints { make in make.trailing.equalTo(view) make.leading.equalTo(view) make.top.equalTo(view) @@ -180,7 +195,7 @@ class HTMLBlockViewController: UIViewController, CourseBlockViewController, Prel } private func hideCourseBannerView() { - courseDateBannerView.snp.remakeConstraints { make in + courseDateBannerViewContainer.snp.remakeConstraints { make in make.trailing.equalTo(view) make.leading.equalTo(view) make.top.equalTo(view) diff --git a/Source/OEXRouter+Swift.swift b/Source/OEXRouter+Swift.swift index e74f44b43..6312c7f24 100644 --- a/Source/OEXRouter+Swift.swift +++ b/Source/OEXRouter+Swift.swift @@ -235,16 +235,15 @@ extension OEXRouter { func showDatesTabController(controller: UIViewController) { if environment.config.isNewDashboardEnabled { - if let dashboardController = controller.navigationController?.viewControllers.first as? NewCourseDashboardViewController { + if let dashboardController = controller.findParentViewController(type: NewCourseContentController.self)?.navigationController?.viewControllers.first as? NewCourseDashboardViewController { popToRoot(controller: dashboardController) { dashboardController.switchTab(with: .courseDates) } - } - else if let dashboardController = UIApplication.shared.topMostController() as? NewCourseDashboardViewController { + } else if let dashboardController = UIApplication.shared.topMostController() as? NewCourseDashboardViewController { dashboardController.switchTab(with: .courseDates) } } else { - if let dashboardController = controller as? CourseDashboardViewController { + if let dashboardController = controller.findParentViewController(type: CourseDashboardViewController.self) { dashboardController.switchTab(with: .courseDates) } else if let dashboardController = controller.navigationController?.viewControllers.first(where: { $0 is CourseDashboardViewController}) as? CourseDashboardViewController { controller.navigationController?.popToViewController(dashboardController, animated: false)