Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

Commit

Permalink
chore: update shift dates banner on component screen (#1786)
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Umer committed Aug 16, 2023
1 parent 9da5e41 commit 5b93cd8
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Source/CourseDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions Source/CourseDateBannerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
31 changes: 23 additions & 8 deletions Source/HTMLBlockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<CourseBlock>()
Expand Down Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions Source/OEXRouter+Swift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 5b93cd8

Please sign in to comment.