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

Update course info header view layout #1124

Merged
merged 3 commits into from
Feb 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Stepic.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -1054,6 +1054,7 @@
2CC16BA923875DE30000EF36 /* DiscussionsSkeletonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC16BA823875DE30000EF36 /* DiscussionsSkeletonView.swift */; };
2CC276FE23EB98CE00E88D6E /* UIBarButtonItem+StepikBarButtonItems.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC276FD23EB98CE00E88D6E /* UIBarButtonItem+StepikBarButtonItems.swift */; };
2CC2770023EB9E2200E88D6E /* SubmissionsSkeletonView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC276FF23EB9E2200E88D6E /* SubmissionsSkeletonView.swift */; };
2CC29ADB27C40F1E00D4EDD0 /* CourseInfoHeaderTitleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC29ADA27C40F1E00D4EDD0 /* CourseInfoHeaderTitleView.swift */; };
2CC3518A1F682A02004255B6 /* SocialAuthCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC351881F682A02004255B6 /* SocialAuthCollectionViewCell.swift */; };
2CC3518F1F682B6C004255B6 /* SocialAuthHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC3518E1F682B6C004255B6 /* SocialAuthHeaderView.swift */; };
2CC351911F682D47004255B6 /* SocialAuthViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2CC351901F682D47004255B6 /* SocialAuthViewController.swift */; };
Expand Down Expand Up @@ -3108,6 +3109,7 @@
2CC16BA823875DE30000EF36 /* DiscussionsSkeletonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscussionsSkeletonView.swift; sourceTree = "<group>"; };
2CC276FD23EB98CE00E88D6E /* UIBarButtonItem+StepikBarButtonItems.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIBarButtonItem+StepikBarButtonItems.swift"; sourceTree = "<group>"; };
2CC276FF23EB9E2200E88D6E /* SubmissionsSkeletonView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SubmissionsSkeletonView.swift; sourceTree = "<group>"; };
2CC29ADA27C40F1E00D4EDD0 /* CourseInfoHeaderTitleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CourseInfoHeaderTitleView.swift; sourceTree = "<group>"; };
2CC351851F6827BE004255B6 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Auth.storyboard; sourceTree = "<group>"; };
2CC351881F682A02004255B6 /* SocialAuthCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocialAuthCollectionViewCell.swift; sourceTree = "<group>"; };
2CC3518E1F682B6C004255B6 /* SocialAuthHeaderView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SocialAuthHeaderView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -9552,6 +9554,7 @@
isa = PBXGroup;
children = (
62E98382552527F92D26C681 /* CourseInfoBlurredBackgroundView.swift */,
2CC29ADA27C40F1E00D4EDD0 /* CourseInfoHeaderTitleView.swift */,
62E989A8236D0E5624DAD9ED /* CourseInfoHeaderView.swift */,
62E9825DC46191B6B299CBC2 /* CourseInfoStatsView.swift */,
2CDC9EF924E4FD0D00916BAE /* CourseInfoTryForFreeButton.swift */,
Expand Down Expand Up @@ -12481,6 +12484,7 @@
62E98DE228BB533D1A9001C8 /* SubmissionsTableViewDataSource.swift in Sources */,
62E9830597D4F90EBB4282F1 /* SubmissionsCellView.swift in Sources */,
2C89FF8624AEDEAE00168F1B /* NewProfileStreakNotificationsViewModel.swift in Sources */,
2CC29ADB27C40F1E00D4EDD0 /* CourseInfoHeaderTitleView.swift in Sources */,
62E98525A1D993E12505CDEB /* SubmissionsTableViewCell.swift in Sources */,
62E98B04BDA99434B78901BC /* WriteCommentAssembly.swift in Sources */,
2C8BCC2824869A6000DFB009 /* NewProfileSubmoduleProtocol.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import SnapKit
import UIKit

extension CourseInfoHeaderTitleView {
struct Appearance {
let coverImageViewSize = CGSize(width: 32, height: 32)
let coverImageViewCornerRadius: CGFloat = 6

let titleLabelFont = Typography.subheadlineFont
let titleLabelColor = UIColor.white

let spacing: CGFloat = 8
}
}

final class CourseInfoHeaderTitleView: UIView {
let appearance: Appearance

private lazy var coverImageView: CourseCoverImageView = {
let view = CourseCoverImageView()
view.clipsToBounds = true
view.layer.cornerRadius = self.appearance.coverImageViewCornerRadius
return view
}()

private lazy var titleLabel: UILabel = {
let label = UILabel()
label.font = self.appearance.titleLabelFont
label.numberOfLines = 2
label.lineBreakMode = .byTruncatingTail
label.textColor = self.appearance.titleLabelColor
return label
}()

private lazy var containerView = UIView()

var coverImageURL: URL? {
didSet {
self.coverImageView.loadImage(url: self.coverImageURL)
}
}

var title: String? {
didSet {
self.titleLabel.text = self.title
self.invalidateIntrinsicContentSize()
}
}

override var intrinsicContentSize: CGSize {
let height = max(self.appearance.coverImageViewSize.height, self.titleLabel.intrinsicContentSize.height)
return CGSize(width: UIView.noIntrinsicMetric, height: height)
}

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

self.setupView()
self.addSubviews()
self.makeConstraints()
}

@available(*, unavailable)
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

extension CourseInfoHeaderTitleView: ProgrammaticallyInitializableViewProtocol {
func setupView() {}

func addSubviews() {
self.containerView.addSubview(self.coverImageView)
self.containerView.addSubview(self.titleLabel)
self.addSubview(self.containerView)
}

func makeConstraints() {
self.containerView.translatesAutoresizingMaskIntoConstraints = false
self.containerView.snp.makeConstraints { make in
make.top.bottom.equalToSuperview()
make.leading.greaterThanOrEqualToSuperview()
make.trailing.lessThanOrEqualToSuperview()
make.centerX.equalToSuperview()
}

self.coverImageView.translatesAutoresizingMaskIntoConstraints = false
self.coverImageView.snp.makeConstraints { make in
make.leading.greaterThanOrEqualToSuperview()
make.centerY.equalToSuperview()
make.size.equalTo(self.appearance.coverImageViewSize)
}

self.titleLabel.translatesAutoresizingMaskIntoConstraints = false
self.titleLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
self.titleLabel.snp.makeConstraints { make in
make.top.greaterThanOrEqualToSuperview()
make.leading.equalTo(self.coverImageView.snp.trailing).offset(self.appearance.spacing)
make.bottom.trailing.lessThanOrEqualToSuperview()
make.centerY.equalToSuperview()
}
}
}
Loading