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

Commit

Permalink
chore: scrolling behaviour on course dashboard header (#1723)
Browse files Browse the repository at this point in the history
  • Loading branch information
mumer92 committed Feb 6, 2023
1 parent c1f0aa2 commit a1cf419
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 173 deletions.
22 changes: 21 additions & 1 deletion Source/CourseAnnouncementsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ private func announcementsDeserializer(response: HTTPURLResponse, json: JSON) ->
}
}

class CourseAnnouncementsViewController: OfflineSupportViewController, LoadStateViewReloadSupport, InterfaceOrientationOverriding {
class CourseAnnouncementsViewController: OfflineSupportViewController, LoadStateViewReloadSupport, InterfaceOrientationOverriding, ScrollableDelegateProvider {

typealias Environment = OEXAnalyticsProvider & OEXConfigProvider & DataManagerProvider & NetworkManagerProvider & OEXRouterProvider & OEXInterfaceProvider & ReachabilityProvider & OEXSessionProvider & OEXStylesProvider

Expand All @@ -32,6 +32,9 @@ class CourseAnnouncementsViewController: OfflineSupportViewController, LoadState
private let fontStyle = OEXTextStyle(weight : .normal, size: .base, color: OEXStyles.shared().neutralBlack())
private let switchStyle = OEXStyles.shared().standardSwitchStyle()

weak var scrollableDelegate: ScrollableDelegate?
private var scrollByDragging = false

@objc init(environment: Environment, courseID: String) {
self.courseID = courseID
self.environment = environment
Expand All @@ -54,6 +57,7 @@ class CourseAnnouncementsViewController: OfflineSupportViewController, LoadState
webView.backgroundColor = OEXStyles.shared().standardBackgroundColor()
webView.isOpaque = false
webView.navigationDelegate = self
webView.scrollView.delegate = self

loadController.setupInController(controller: self, contentView: webView)
announcementsLoader.listen(self) {[weak self] in
Expand Down Expand Up @@ -174,3 +178,19 @@ extension CourseAnnouncementsViewController: WKNavigationDelegate {
loadController.state = LoadState.failed(error: error as NSError)
}
}

extension CourseAnnouncementsViewController: UIScrollViewDelegate {
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
scrollByDragging = true
}

func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollByDragging {
scrollableDelegate?.scrollViewDidScroll(scrollView: scrollView)
}
}

func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
scrollByDragging = false
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CourseDashboardAccessErrorCell.swift
// CourseDashboardAccessErrorView.swift
// edX
//
// Created by Saeed Bashir on 12/2/22.
Expand All @@ -8,21 +8,22 @@

import Foundation

protocol CourseDashboardAccessErrorCellDelegate: AnyObject {
protocol CourseDashboardAccessErrorViewDelegate: AnyObject {
func findCourseAction()
func upgradeCourseAction(course: OEXCourse, price: String?, completion: @escaping ((Bool)->()))
func coursePrice(cell: CourseDashboardAccessErrorCell, price: String?, elapsedTime: Int)
func coursePrice(cell: CourseDashboardAccessErrorView, price: String?, elapsedTime: Int)
}

class CourseDashboardAccessErrorCell: UITableViewCell {
static let identifier = "CourseDashboardAccessErrorCell"
class CourseDashboardAccessErrorView: UIView {

typealias Environment = OEXConfigProvider & ServerConfigProvider
weak var delegate: CourseDashboardAccessErrorCellDelegate?
weak var delegate: CourseDashboardAccessErrorViewDelegate?

private lazy var infoMessagesView = ValuePropMessagesView()
private var environment: Environment?

private lazy var contentView = UIView()

private lazy var upgradeButton: CourseUpgradeButtonView = {
let upgradeButton = CourseUpgradeButtonView()
upgradeButton.tapAction = { [weak self] in
Expand All @@ -37,20 +38,20 @@ class CourseDashboardAccessErrorCell: UITableViewCell {
private var titleLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.accessibilityIdentifier = "CourseDashboardAccessErrorCell:title-label"
label.accessibilityIdentifier = "CourseDashboardAccessErrorView:title-label"
return label
}()

private var infoLabel: UILabel = {
let label = UILabel()
label.numberOfLines = 0
label.accessibilityIdentifier = "CourseDashboardAccessErrorCell:info-label"
label.accessibilityIdentifier = "CourseDashboardAccessErrorView:info-label"
return label
}()

private lazy var findCourseButton: UIButton = {
let button = UIButton(type: .system)
button.accessibilityIdentifier = "CourseDashboardAccessErrorCell:findcourse-button"
button.accessibilityIdentifier = "CourseDashboardAccessErrorView:findcourse-button"
button.oex_addAction({ [weak self] _ in
self?.delegate?.findCourseAction()
}, for: .touchUpInside)
Expand All @@ -59,16 +60,14 @@ class CourseDashboardAccessErrorCell: UITableViewCell {

private lazy var hiddenView: UIView = {
let view = UIView()
view.accessibilityIdentifier = "CourseDashboardAccessErrorCell:hidden-view"
view.accessibilityIdentifier = "CourseDashboardAccessErrorView:hidden-view"
view.backgroundColor = .clear

return view
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none
accessibilityIdentifier = "CourseDashboardAccessErrorCell:view"
init() {
super.init(frame: .zero)
}

private var course: OEXCourse?
Expand Down Expand Up @@ -100,6 +99,8 @@ class CourseDashboardAccessErrorCell: UITableViewCell {
}

private func configureViews() {
accessibilityIdentifier = "CourseDashboardAccessErrorView:view"
addSubview(contentView)
contentView.addSubview(titleLabel)
contentView.addSubview(infoLabel)
contentView.addSubview(infoMessagesView)
Expand All @@ -113,6 +114,10 @@ class CourseDashboardAccessErrorCell: UITableViewCell {
}

private func setConstraints(showValueProp: Bool, showUpgradeButton: Bool) {
contentView.snp.remakeConstraints { make in
make.edges.equalTo(self)
}

titleLabel.snp.remakeConstraints { make in
make.top.equalTo(contentView).offset(StandardVerticalMargin * 2)
make.leading.equalTo(contentView).offset(StandardHorizontalMargin)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CourseDashboardErrorViewCell.swift
// CourseDashboardErrorView.swift
// edX
//
// Created by Saeed Bashir on 11/29/22.
Expand All @@ -8,16 +8,15 @@

import Foundation

class CourseDashboardErrorViewCell: UITableViewCell {
static let identifier = "CourseDashboardErrorView"

class CourseDashboardErrorView: UIView {
var myCoursesAction: (() -> Void)?

private let contentView = UIView()
private let containerView = UIView()
private let bottomContainer = UIView()
private let errorLabel: UILabel = {
let label = UILabel()
label.accessibilityIdentifier = "CourseDashboardErrorViewCell:error-label"
label.accessibilityIdentifier = "CourseDashboardErrorView:error-label"
label.numberOfLines = 0
let style = OEXMutableTextStyle(weight: .bold, size: .xxLarge, color: OEXStyles.shared().neutralBlackT())
style.alignment = .center
Expand All @@ -29,13 +28,13 @@ class CourseDashboardErrorViewCell: UITableViewCell {
private lazy var errorImageView: UIImageView = {
guard let image = UIImage(named: "dashboard_error_image") else { return UIImageView() }
let imageView = UIImageView(image: image)
imageView.accessibilityIdentifier = "CourseDashboardErrorViewCell:error-imageView"
imageView.accessibilityIdentifier = "CourseDashboardErrorView:error-imageView"
return imageView
}()

private lazy var gotoMyCoursesButton: UIButton = {
let button = UIButton(type: .system)
button.accessibilityIdentifier = "CourseDashboardErrorViewCell:gotocourses-button"
button.accessibilityIdentifier = "CourseDashboardErrorView:gotocourses-button"
button.backgroundColor = OEXStyles.shared().secondaryBaseColor()
button.oex_addAction({ [weak self] _ in
self?.myCoursesAction?()
Expand All @@ -47,19 +46,13 @@ class CourseDashboardErrorViewCell: UITableViewCell {
return button
}()

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
selectionStyle = .none

init() {
super.init(frame: .zero)
addSubViews()
setAccessibilityIdentifiers()
setConstraints()
}

override func prepareForReuse() {
setConstraints()
}

override func layoutSubviews() {
super.layoutSubviews()
containerView.addShadow(offset: CGSize(width: 0, height: 2), color: OEXStyles.shared().primaryDarkColor(), radius: 2, opacity: 0.35, cornerRadius: 6)
Expand All @@ -76,9 +69,8 @@ class CourseDashboardErrorViewCell: UITableViewCell {

private func addSubViews() {
backgroundColor = OEXStyles.shared().neutralWhiteT()

addSubview(contentView)
contentView.addSubview(containerView)

containerView.addSubview(errorImageView)
containerView.addSubview(bottomContainer)

Expand All @@ -89,12 +81,16 @@ class CourseDashboardErrorViewCell: UITableViewCell {
}

private func setAccessibilityIdentifiers() {
accessibilityIdentifier = "CourseDashboardErrorViewCell:view"
containerView.accessibilityIdentifier = "CourseDashboardErrorViewCell:container-view"
bottomContainer.accessibilityIdentifier = "CourseDashboardErrorViewCell:bottom-container-view"
accessibilityIdentifier = "CourseDashboardErrorView:view"
containerView.accessibilityIdentifier = "CourseDashboardErrorView:container-view"
bottomContainer.accessibilityIdentifier = "CourseDashboardErrorView:bottom-container-view"
}

private func addPortraitConstraints() {
contentView.snp.remakeConstraints { make in
make.edges.equalTo(self)
}

containerView.snp.remakeConstraints { make in
make.top.equalTo(contentView).offset(StandardVerticalMargin * 2)
make.leading.equalTo(contentView).offset(StandardHorizontalMargin)
Expand Down
Loading

0 comments on commit a1cf419

Please sign in to comment.