Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Course info: container UI & header #404

Merged
merged 18 commits into from
Nov 30, 2018
2 changes: 1 addition & 1 deletion Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def shared_pods
pod 'SVGKit', :git => 'https://github.com/SVGKit/SVGKit.git', :branch => '2.x'
pod 'Fabric', '1.7.11'
pod 'Crashlytics', '3.10.7'
pod 'DeviceKit', '1.7.0'
pod 'DeviceKit', '1.10.0'
pod 'PromiseKit', '6.3.4'
pod 'SwiftLint', '0.27.0'
end
Expand Down
8 changes: 4 additions & 4 deletions Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ PODS:
- Crashlytics (3.10.7):
- Fabric (~> 1.7.11)
- CRToast (0.0.9)
- DeviceKit (1.7.0)
- DeviceKit (1.10.0)
- DownloadButton (0.1.0)
- EasyTipView (1.1.0)
- Fabric (1.7.11)
Expand Down Expand Up @@ -163,7 +163,7 @@ DEPENDENCIES:
- Charts (= 3.1.1)
- Crashlytics (= 3.10.7)
- CRToast (= 0.0.9)
- DeviceKit (= 1.7.0)
- DeviceKit (= 1.10.0)
- DownloadButton (= 0.1.0)
- EasyTipView (from `https://github.com/igorkislyuk/EasyTipView.git`)
- Fabric (= 1.7.11)
Expand Down Expand Up @@ -301,7 +301,7 @@ SPEC CHECKSUMS:
CocoaLumberjack: db7cc9e464771f12054c22ff6947c5a58d43a0fd
Crashlytics: ccaac42660eb9351b9960c0d66106b0bcf99f4fa
CRToast: 5a78c22b921c5ed3487488af605bc403a9c92fed
DeviceKit: 6a5bdeb103c03757bb94aef1ccb01e08bc8ef4ee
DeviceKit: 2a6cf0d1ec05e2ac7f9b24cdfdb3cb358900a247
DownloadButton: 49a21a89e0d7d1b42d9134f79aaa40e727cd57c3
EasyTipView: 236dda1a58f9a15bd39f11d84347e6b8643a744c
Fabric: f233c9492b3bbc1f04e3882986740f7988a58edb
Expand Down Expand Up @@ -349,6 +349,6 @@ SPEC CHECKSUMS:
VK-ios-sdk: 7fd48bc5aaa6b96c3197c1987eb6593f2ea67331
YandexMobileMetrica: f18374ee6977a4cd1d0a86298a0df4ad7baf4135

PODFILE CHECKSUM: a97928fdf81fc88b600ec1549a07164cd218bf9a
PODFILE CHECKSUM: 3f20d9376b4c62a872b087e27e6847796587ddf3

COCOAPODS: 1.5.3
72 changes: 70 additions & 2 deletions Stepic.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Stepic/AdaptiveStatsPagerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class AdaptiveStatsPagerViewController: PagerController {
override func viewDidLoad() {
super.viewDidLoad()

edgesForExtendedLayout = []
kvld marked this conversation as resolved.
Show resolved Hide resolved

title = NSLocalizedString("AdaptiveStats", comment: "")

self.dataSource = self
Expand Down
2 changes: 2 additions & 0 deletions Stepic/CodeEditorSettingsViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class CodeEditorSettingsViewController: MenuViewController, CodeEditorSettingsVi
override func viewDidLoad() {
super.viewDidLoad()

edgesForExtendedLayout = []
kvld marked this conversation as resolved.
Show resolved Hide resolved

previewView = CodeEditorPreviewView()
previewView.delegate = self
tableView.tableHeaderView = previewView
Expand Down
85 changes: 61 additions & 24 deletions Stepic/ContinueActionButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,45 @@ import UIKit

extension ContinueActionButton {
struct Appearance {
let cornerRadius: CGFloat = 33.0
let titleFont = UIFont.systemFont(ofSize: 16)
let titleColor = UIColor.mainDark

let backgroundColor = UIColor.white
var cornerRadius: CGFloat = 33.0
var titleFont = UIFont.systemFont(ofSize: 16)
let titleInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)

let shadowColor = UIColor(hex: 0xa0a0a0, alpha: 0.5)
let shadowOffset = CGSize(width: 0, height: 1.3)
let shadowOpacity: Float = 1.0
let shadowRadius: CGFloat = 6.7

let titleInsets = UIEdgeInsets(top: 0, left: 16, bottom: 0, right: 16)
let defaultBackgroundColor = UIColor.white
let defaultTitleColor = UIColor.mainDark
let defaultShadowColor = UIColor(hex: 0xa0a0a0, alpha: 0.5)

let callToActionBackgroundColor = UIColor.stepicGreen
let callToActionTitleColor = UIColor.white
let callToActionShadowColor = UIColor(hex: 0xa0a0a0, alpha: 0.5)
}
}

final class ContinueActionButton: BounceButton {
let appearance: Appearance

private lazy var shadowLayer: CAShapeLayer = {
let shadowLayer = CAShapeLayer()
shadowLayer.fillColor = self.appearance.backgroundColor.cgColor

shadowLayer.shadowColor = self.appearance.shadowColor.cgColor
shadowLayer.shadowOffset = self.appearance.shadowOffset
shadowLayer.shadowOpacity = self.appearance.shadowOpacity
shadowLayer.shadowRadius = self.appearance.shadowRadius
private var shadowLayer: CAShapeLayer?

return shadowLayer
}()
var mode: Mode {
didSet {
self.updateAppearance()
}
}

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(
frame: CGRect = .zero,
mode: Mode = .default,
appearance: Appearance = Appearance()
) {
self.mode = mode
self.appearance = appearance
super.init(frame: frame)

self.titleLabel?.font = self.appearance.titleFont
self.setTitleColor(self.appearance.titleColor, for: .normal)
self.titleEdgeInsets = self.appearance.titleInsets
self.layer.insertSublayer(self.shadowLayer, at: 0)
self.updateAppearance()
}

required init?(coder aDecoder: NSCoder) {
Expand All @@ -57,10 +58,46 @@ final class ContinueActionButton: BounceButton {
override func layoutSubviews() {
super.layoutSubviews()

self.shadowLayer.path = UIBezierPath(
let path = UIBezierPath(
roundedRect: self.bounds,
cornerRadius: self.appearance.cornerRadius
).cgPath
self.shadowLayer.shadowPath = self.shadowLayer.path
self.shadowLayer?.path = path
self.shadowLayer?.shadowPath = path
}

private func updateAppearance() {
self.titleLabel?.font = self.appearance.titleFont
self.titleEdgeInsets = self.appearance.titleInsets

self.shadowLayer?.removeFromSuperlayer()

let shadowLayer = CAShapeLayer()
shadowLayer.shadowOffset = self.appearance.shadowOffset
shadowLayer.shadowOpacity = self.appearance.shadowOpacity
shadowLayer.shadowRadius = self.appearance.shadowRadius

switch self.mode {
case .default:
self.setTitleColor(self.appearance.defaultTitleColor, for: .normal)

shadowLayer.fillColor = self.appearance.defaultBackgroundColor.cgColor
shadowLayer.shadowColor = self.appearance.defaultShadowColor.cgColor
case .callToAction:
self.setTitleColor(self.appearance.callToActionTitleColor, for: .normal)

shadowLayer.fillColor = self.appearance.callToActionBackgroundColor.cgColor
shadowLayer.shadowColor = self.appearance.callToActionShadowColor.cgColor
}

self.layer.insertSublayer(shadowLayer, at: 0)
self.shadowLayer = shadowLayer
}

enum Mode {
/// Classic white button
case `default`
/// Green button
case callToAction
}
}
2 changes: 1 addition & 1 deletion Stepic/ContinueCourseSkeletonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class ContinueCourseSkeletonView: UIView {

private lazy var largeView = UIView()

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)

Expand Down
6 changes: 3 additions & 3 deletions Stepic/ContinueLastStepView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ final class ContinueLastStepView: UIView {
let appearance: Appearance

lazy var continueButton: UIButton = {
let button = ContinueActionButton(frame: .zero)
let button = ContinueActionButton(mode: .default)
button.setTitle(NSLocalizedString("ContinueLearningWidgetButtonTitle", comment: ""), for: .normal)
button.addTarget(self, action: #selector(self.continueButtonClicked), for: .touchUpInside)
return button
Expand Down Expand Up @@ -88,7 +88,7 @@ final class ContinueLastStepView: UIView {
}()

private lazy var coverImageView: CourseCoverImageView = {
let view = CourseCoverImageView(frame: .zero)
let view = CourseCoverImageView()
view.clipsToBounds = true
view.layer.cornerRadius = self.appearance.coverCornerRadius
return view
Expand Down Expand Up @@ -147,7 +147,7 @@ final class ContinueLastStepView: UIView {

var onContinueButtonClick: (() -> Void)?

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)

Expand Down
2 changes: 1 addition & 1 deletion Stepic/CourseListView/CourseListCollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CourseListCollectionViewCell: UICollectionViewCell, Reusable {
private var configurationViewModel: CourseWidgetViewModel?

private lazy var widgetView: CourseWidgetView = {
let widget = CourseWidgetView(frame: .zero, colorMode: self.colorMode)
let widget = CourseWidgetView(colorMode: self.colorMode)
// Pass clicks from widget view to collection view delegate
widget.onPrimaryButtonClick = { [weak self] in
guard let strongSelf = self else {
Expand Down
4 changes: 2 additions & 2 deletions Stepic/CourseListView/CourseListView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CourseListView: UIView {
}

init(
frame: CGRect,
frame: CGRect = .zero,
colorMode: CourseListColorMode = .default,
viewDelegate: CourseListViewDelegate,
appearance: Appearance = Appearance()
Expand Down Expand Up @@ -111,7 +111,7 @@ class CourseListView: UIView {

func showLoading() {
self.collectionView.skeleton.viewBuilder = {
CourseWidgetSkeletonView(frame: .zero)
CourseWidgetSkeletonView()
}
self.collectionView.skeleton.show()
}
Expand Down
3 changes: 0 additions & 3 deletions Stepic/CourseListView/Widget/CourseCoverImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,5 @@ final class CourseCoverImageView: UIImageView {
extension CourseCoverImageView: ProgrammaticallyInitializableViewProtocol {
func setupView() {
self.image = nil

self.layer.cornerRadius = self.appearance.cornerRadius
self.clipsToBounds = true
}
}
4 changes: 2 additions & 2 deletions Stepic/CourseListView/Widget/CourseWidgetCoverView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ extension CourseWidgetCoverView {
final class CourseWidgetCoverView: UIView {
let appearance: Appearance

private lazy var coverImageView: CourseCoverImageView = CourseCoverImageView(frame: .zero)
private lazy var coverImageView = CourseCoverImageView()

private lazy var adaptiveMarkLabel: UILabel = {
let label = PaddingLabel(padding: self.appearance.adaptiveMarkLabelInsets)
Expand Down Expand Up @@ -56,7 +56,7 @@ final class CourseWidgetCoverView: UIView {
}
}

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)

Expand Down
2 changes: 1 addition & 1 deletion Stepic/CourseListView/Widget/CourseWidgetLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extension CourseWidgetLabel {
final class CourseWidgetLabel: UILabel {
let appearance: Appearance

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)
setupView()
Expand Down
8 changes: 4 additions & 4 deletions Stepic/CourseListView/Widget/CourseWidgetStatsItemView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ import SnapKit

extension CourseWidgetStatsItemView {
struct Appearance {
let iconSpacing: CGFloat = 3.0
var iconSpacing: CGFloat = 3.0
var imageViewSize = CGSize(width: 12, height: 12)
var imageTintColor = UIColor.black

let font = UIFont.systemFont(ofSize: 16, weight: .light)
var font = UIFont.systemFont(ofSize: 16, weight: .light)
var textColor = UIColor.white
}
}
Expand All @@ -30,7 +30,7 @@ final class CourseWidgetStatsItemView: UIView {
appearance.font = self.appearance.font
appearance.textColor = self.appearance.textColor
appearance.maxLinesCount = 1
let label = CourseWidgetLabel(frame: .zero, appearance: appearance)
let label = CourseWidgetLabel(appearance: appearance)
return label
}()

Expand All @@ -46,7 +46,7 @@ final class CourseWidgetStatsItemView: UIView {
}
}

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)

Expand Down
44 changes: 16 additions & 28 deletions Stepic/CourseListView/Widget/CourseWidgetStatsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,31 @@ final class CourseWidgetStatsView: UIView {
}

private lazy var learnersView: CourseWidgetStatsItemView = {
let appearance = CourseWidgetStatsItemView.Appearance(
imageViewSize: self.appearance.learnersViewImageViewSize,
imageTintColor: self.appearance.itemImageTintColor,
textColor: self.appearance.itemTextColor
)
let view = CourseWidgetStatsItemView(
frame: .zero,
appearance: appearance
)
var appearance = CourseWidgetStatsItemView.Appearance()
appearance.imageViewSize = self.appearance.learnersViewImageViewSize
appearance.imageTintColor = self.appearance.itemImageTintColor
appearance.textColor = self.appearance.itemTextColor
let view = CourseWidgetStatsItemView(appearance: appearance)
view.image = UIImage(named: "course-widget-user")!.withRenderingMode(.alwaysTemplate)
return view
}()

private lazy var ratingView: CourseWidgetStatsItemView = {
let appearance = CourseWidgetStatsItemView.Appearance(
imageViewSize: self.appearance.ratingViewImageViewSize,
imageTintColor: self.appearance.itemImageTintColor,
textColor: self.appearance.itemTextColor
)
let view = CourseWidgetStatsItemView(
frame: .zero,
appearance: appearance
)
var appearance = CourseWidgetStatsItemView.Appearance()
appearance.imageViewSize = self.appearance.ratingViewImageViewSize
appearance.imageTintColor = self.appearance.itemImageTintColor
appearance.textColor = self.appearance.itemTextColor
let view = CourseWidgetStatsItemView(appearance: appearance)
view.image = UIImage(named: "course-widget-rating")!.withRenderingMode(.alwaysTemplate)
return view
}()

private lazy var progressView: CourseWidgetStatsItemView = {
let appearance = CourseWidgetStatsItemView.Appearance(
imageViewSize: self.appearance.progressViewImageViewSize,
imageTintColor: .clear,
textColor: self.appearance.itemTextColor
)
let view = CourseWidgetStatsItemView(
frame: .zero,
appearance: appearance
)
var appearance = CourseWidgetStatsItemView.Appearance()
appearance.imageViewSize = self.appearance.progressViewImageViewSize
appearance.imageTintColor = .clear
appearance.textColor = self.appearance.itemTextColor
let view = CourseWidgetStatsItemView(appearance: appearance)
return view
}()

Expand All @@ -103,7 +91,7 @@ final class CourseWidgetStatsView: UIView {
return stackView
}()

init(frame: CGRect, appearance: Appearance = Appearance()) {
init(frame: CGRect = .zero, appearance: Appearance = Appearance()) {
self.appearance = appearance
super.init(frame: frame)

Expand Down
Loading