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 7, 2023
1 parent eb7d946 commit 85466f5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 66 deletions.
30 changes: 2 additions & 28 deletions Source/NewCourseContentController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,20 +222,10 @@ class NewCourseContentController: UIViewController, InterfaceOrientationOverridi
override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
coordinator.animate { [weak self] _ in
guard let weakSelf = self else { return }
if weakSelf.currentOrientation() == .portrait {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
weakSelf.setStatusBar(color: weakSelf.environment.styles.primaryLightColor())
}
} else {
weakSelf.removeStatusBar()
DispatchQueue.main.async {
weakSelf.setStatusBar(color: weakSelf.environment.styles.primaryLightColor())
}
}

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

Expand All @@ -256,8 +246,6 @@ extension NewCourseContentController: CourseContentPageViewControllerDelegate {

private func updateHeaderState(with controller: CourseContentPageViewController) {
if let controller = controller.viewControllers?.first as? VideoBlockViewController {
controller.orientationDelegate = self

if currentOrientation() != .portrait {
collapseHeaderView()
} else if headerViewState == .collapsed {
Expand Down Expand Up @@ -330,20 +318,6 @@ extension NewCourseContentController {
}
}

extension NewCourseContentController: VideoBlockViewControllerOrientationDelegate {
func changeOrientation(orientation: UIInterfaceOrientation) {
if orientation == .portrait {
if headerViewState == .collapsed {
headerViewState = .animating
expandHeaderView()
}
} else if headerViewState == .expanded {
headerViewState = .animating
collapseHeaderView()
}
}
}

fileprivate extension UIStackView {
func addArrangedSubviews(_ views: [UIView]) {
views.forEach { addArrangedSubview($0) }
Expand Down
47 changes: 19 additions & 28 deletions Source/NewCourseDashboardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -271,13 +271,8 @@ class NewCourseDashboardViewController: UIViewController, InterfaceOrientationOv

coordinator.animate { [weak self] _ in
guard let weakSelf = self else { return }

if weakSelf.currentOrientation() == .portrait {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
weakSelf.setStatusBar(color: weakSelf.environment.styles.primaryLightColor())
}
} else {
weakSelf.removeStatusBar()
DispatchQueue.main.async {
weakSelf.setStatusBar(color: weakSelf.environment.styles.primaryLightColor())
}
}

Expand Down Expand Up @@ -616,31 +611,27 @@ extension NewCourseDashboardViewController: NewCourseDashboardViewControllerDele

public extension UIViewController {
func setStatusBar(color: UIColor) {
DispatchQueue.main.async { [weak self] in
let tag = 123454321
let overView: UIView
if let taggedView = self?.view.viewWithTag(tag) {
overView = taggedView
}
else {
overView = UIView()
overView.tag = tag
self?.view.addSubview(overView)
}

let height = UIApplication.shared.window?.windowScene?.windows.first?.safeAreaInsets.top ?? 0
let frame = UIApplication.shared.window?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
overView.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: height)
overView.backgroundColor = color
let tag = 123454321
let overView: UIView
if let taggedView = view.viewWithTag(tag) {
overView = taggedView
}
else {
overView = UIView()
overView.tag = tag
view.addSubview(overView)
}

let height = UIApplication.shared.window?.windowScene?.windows.first?.safeAreaInsets.top ?? 0
let frame = UIApplication.shared.window?.windowScene?.statusBarManager?.statusBarFrame ?? .zero
overView.frame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.size.width, height: height)
overView.backgroundColor = color
}

func removeStatusBar() {
DispatchQueue.main.async { [weak self] in
let tag = 123454321
if let taggedView = self?.view.viewWithTag(tag) {
taggedView.removeFromSuperview()
}
let tag = 123454321
if let taggedView = view.viewWithTag(tag) {
taggedView.removeFromSuperview()
}
}
}
12 changes: 2 additions & 10 deletions Source/VideoBlockViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import Foundation
import MediaPlayer
import UIKit

protocol VideoBlockViewControllerOrientationDelegate {
func changeOrientation(orientation: UIInterfaceOrientation)
}

class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewController, StatusBarOverriding, InterfaceOrientationOverriding, VideoTranscriptDelegate, RatingViewControllerDelegate, VideoPlayerDelegate {

typealias Environment = DataManagerProvider & OEXInterfaceProvider & ReachabilityProvider & OEXConfigProvider & OEXRouterProvider & OEXAnalyticsProvider & OEXStylesProvider & OEXSessionProvider & NetworkManagerProvider
Expand All @@ -35,9 +31,7 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo
private var playOverlayButton: UIButton?
private var overlayLabel: UILabel?
var shouldCelebrationAppear: Bool

var orientationDelegate: VideoBlockViewControllerOrientationDelegate?


init(environment : Environment, blockID : CourseBlockID?, courseID: String, shouldCelebrationAppear: Bool = false) {
self.blockID = blockID
self.environment = environment
Expand Down Expand Up @@ -448,9 +442,7 @@ class VideoBlockViewController : OfflineSupportViewController, CourseBlockViewCo
}
}

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
orientationDelegate?.changeOrientation(orientation: currentOrientation())

override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
if UIDevice.current.userInterfaceIdiom == .pad {
if videoPlayer.isFullScreen {
videoPlayer.setFullscreen(fullscreen: !UIDevice.current.orientation.isPortrait, animated: true, with: currentOrientation(), forceRotate: false)
Expand Down

0 comments on commit 85466f5

Please sign in to comment.