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

Commit

Permalink
chore: address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
mumer92 committed Jul 5, 2023
1 parent 49c2acd commit 7ec4757
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
5 changes: 5 additions & 0 deletions Source/CourseDashboardHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ protocol CourseDashboardHeaderViewDelegate: AnyObject {
}

enum HeaderViewState {
case initial
case animating
case expanded
case collapsed
Expand All @@ -37,6 +38,8 @@ class CourseDashboardHeaderView: UIView {
private lazy var datesBannerView = NewCourseDateBannerView()
private var bannerInfo: DatesBannerInfo? = nil

var state: HeaderViewState = .initial

private lazy var orgLabel: UILabel = {
let label = UILabel()
label.accessibilityIdentifier = "CourseDashboardHeaderView:org-label"
Expand Down Expand Up @@ -245,6 +248,8 @@ class CourseDashboardHeaderView: UIView {
make.trailing.equalTo(closeButton.snp.leading).offset(-StandardHorizontalMargin)
}

if state == .collapsed { return }

courseInfoContainerView.snp.remakeConstraints { make in
make.top.equalTo(closeButton.snp.bottom)
make.leading.equalTo(containerView).offset(StandardHorizontalMargin)
Expand Down
45 changes: 39 additions & 6 deletions Source/NewCourseContentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi

private var courseContentViewController: CourseContentPageViewController?
private var headerViewState: HeaderViewState = .expanded
private var statusBarTag = 999999

private var currentBlock: CourseBlock? {
willSet {
Expand Down Expand Up @@ -100,7 +101,6 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
override func viewDidLoad() {
super.viewDidLoad()

setStatusBar(color: environment.styles.primaryLightColor())
addSubViews()
setupComponentView()
setupCompletedBlocksView()
Expand All @@ -109,6 +109,14 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
navigationController?.setNavigationBarHidden(true, animated: false)
updateStatusBarVisibility()
}

override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
DispatchQueue.main.asyncAfter(deadline: .now() + 0.4) { [weak self] in
self?.removeStatusBarView()
}
}

private func addSubViews() {
Expand Down Expand Up @@ -220,10 +228,8 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi

override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {

if currentOrientation() == .portrait {
setStatusBar(color: environment.styles.primaryLightColor())
} else {
removeStatusBar()
coordinator.animate { [weak self] _ in
self?.updateStatusBarVisibility()
}

if headerViewState == .collapsed {
Expand All @@ -232,6 +238,26 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
expandHeaderView()
}
}

private func removeStatusBarView() {
if let statusBar = UIApplication.shared.windows.filter({ $0.isKeyWindow }).first?.viewWithTag(statusBarTag) {
statusBar.removeFromSuperview()
}
}

private func updateStatusBarVisibility() {
let window = UIApplication.shared.windows.first
let topPadding = window?.safeAreaInsets.top

if currentOrientation() == .portrait {
let statusBar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: topPadding ?? 0.0))
statusBar.backgroundColor = environment.styles.primaryLightColor()
statusBar.tag = statusBarTag
UIApplication.shared.windows.filter { $0.isKeyWindow }.first?.addSubview(statusBar)
} else {
removeStatusBarView()
}
}
}

extension NewCourseContentController: CourseContentPageViewControllerDelegate {
Expand All @@ -244,7 +270,14 @@ extension NewCourseContentController: CourseContentPageViewControllerDelegate {

if let controller = controller.viewControllers?.first as? VideoBlockViewController {
controller.orientationDelegate = self
changeOrientation(orientation: currentOrientation())

if currentOrientation() != .portrait {
collapseHeaderView()
} else if headerViewState == .collapsed {
collapseHeaderView()
} else if headerViewState == .expanded {
expandHeaderView()
}
}
}
}
Expand Down
14 changes: 12 additions & 2 deletions Source/NewCourseDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv
private var error: NSError?
private var courseAccessHelper: CourseAccessHelper?
private var selectedTabbarItem: TabBarItem?
private var headerViewState: HeaderViewState = .expanded

private var headerViewState: HeaderViewState = .expanded {
didSet {
headerView.state = headerViewState
}
}
private var tabBarItems: [TabBarItem] = []
private var isModalDismissable = true
private let courseStream: BackedStream<UserCourseEnrollment>
Expand Down Expand Up @@ -105,7 +110,12 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
expandHeaderView()

if headerViewState == .collapsed {
collapseHeaderView()
} else if headerViewState == .expanded {
expandHeaderView()
}
}

override func viewWillDisappear(_ animated: Bool) {
Expand Down

0 comments on commit 7ec4757

Please sign in to comment.