diff --git a/Source/CourseDashboardHeaderView.swift b/Source/CourseDashboardHeaderView.swift index 7994d082c..789b82839 100644 --- a/Source/CourseDashboardHeaderView.swift +++ b/Source/CourseDashboardHeaderView.swift @@ -16,6 +16,7 @@ protocol CourseDashboardHeaderViewDelegate: AnyObject { } enum HeaderViewState { + case initial case animating case expanded case collapsed @@ -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" @@ -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) diff --git a/Source/NewCourseContentController.swift b/Source/NewCourseContentController.swift index 79eeb8e53..36c442598 100644 --- a/Source/NewCourseContentController.swift +++ b/Source/NewCourseContentController.swift @@ -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 { @@ -100,7 +101,6 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi override func viewDidLoad() { super.viewDidLoad() - setStatusBar(color: environment.styles.primaryLightColor()) addSubViews() setupComponentView() setupCompletedBlocksView() @@ -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() { @@ -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 { @@ -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 { @@ -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() + } } } } diff --git a/Source/NewCourseDashboardViewController.swift b/Source/NewCourseDashboardViewController.swift index 1a539483d..37cbc800d 100644 --- a/Source/NewCourseDashboardViewController.swift +++ b/Source/NewCourseDashboardViewController.swift @@ -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 @@ -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) {