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

Improves leaderboard layout #529

Open
wants to merge 5 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion HackIllinois/UI/HILabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// This file is part of the Hackillinois iOS App.
// The Hackillinois iOS App is open source software, released under the University of
// Illinois/NCSA Open Source License. You should have received a copy of
// this license in a file with the distribution.
// this license in a file with the distribution.
//

import Foundation
Expand Down Expand Up @@ -307,6 +307,7 @@ class HILabel: UILabel {
case .leaderboardName:
textHIColor = \.leaderboardText
backgroundHIColor = \.clear
lineBreakMode = .byTruncatingTail
if UIDevice.current.userInterfaceIdiom == .pad {
font = HIAppearance.Font.leaderboardNamePad
} else {
Expand Down
52 changes: 39 additions & 13 deletions HackIllinois/UI/TableView/Cells/HILeaderboardCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@ class HILeaderboardCell: UITableViewCell {
let nameLabel = HILabel(style: .leaderboardName)
let rankLabel = HILabel(style: .leaderboardRank)
let pointsLabel = HILabel(style: .leaderboardPoints)

// iOS 16 TableView did not respect separator inset for
// first and last rows, add managed equivalent
let separatorView: UIView = {
let separatorView = UIView()
separatorView.backgroundColor = #colorLiteral(red: 0.04009541315, green: 0.1307413591, blue: 0.3802352191, alpha: 1)
separatorView.translatesAutoresizingMaskIntoConstraints = false
return separatorView
}()

var cellView = HIView {
$0.clipsToBounds = true
Expand All @@ -33,27 +42,44 @@ class HILeaderboardCell: UITableViewCell {
selectionStyle = .none
backgroundColor = UIColor.clear
contentView.addSubview(cellView)
cellView.constrain(to: safeAreaLayoutGuide, topInset: 0, trailingInset: 0, bottomInset: 0, leadingInset: 0)

cellView.constrain(
to: safeAreaLayoutGuide,
topInset: 0,
trailingInset: -HILeaderboardCell.padding.right,
bottomInset: 0,
leadingInset: HILeaderboardCell.padding.left
)

cellView.addSubview(rankLabel)
cellView.addSubview(pointsLabel)
cellView.addSubview(nameLabel)
cellView.addSubview(separatorView)
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) should not be used.")
}
}

// MARK: - Padding
extension HILeaderboardCell {
static var padding: UIEdgeInsets {
let pad = (UIScreen.main.bounds.width * 0.15) / 2.0
return UIEdgeInsets(top: 0, left: pad, bottom: 0, right: pad)
}
}

// MARK: - Population
extension HILeaderboardCell {
static func heightForCell(with group: LeaderboardProfile, width: CGFloat) -> CGFloat {
return 60
}

static func <- (lhs: HILeaderboardCell, rhs: LeaderboardProfile) {
var padConstant = 1.0
var padConstant = 25.0
if UIDevice.current.userInterfaceIdiom == .pad {
padConstant = 2.0
padConstant = 50.0
}
lhs.rankLabel.textAlignment = .center
lhs.pointsLabel.textAlignment = .center
Expand All @@ -67,23 +93,23 @@ extension HILeaderboardCell {
lhs.nameLabel.textAlignment = .left

lhs.rankLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true
lhs.rankLabel.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor, constant: 25 * padConstant).isActive = true
lhs.rankLabel.setContentHuggingPriority(.defaultHigh, for: .horizontal)

lhs.rankLabel.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor, constant: padConstant).isActive = true
lhs.rankLabel.widthAnchor.constraint(equalToConstant: 30).isActive = true
lhs.pointsLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true
lhs.pointsLabel.widthAnchor.constraint(equalTo: lhs.cellView.widthAnchor, multiplier: 0.24).isActive = true
lhs.pointsLabel.trailingAnchor.constraint(equalTo: lhs.cellView.trailingAnchor, constant: -25).isActive = true
lhs.pointsLabel.heightAnchor.constraint(equalTo: lhs.cellView.heightAnchor, multiplier: 0.38).isActive = true

lhs.nameLabel.centerYAnchor.constraint(equalTo: lhs.cellView.centerYAnchor).isActive = true
lhs.nameLabel.leadingAnchor.constraint(equalTo: lhs.rankLabel.leadingAnchor, constant: 50 * padConstant).isActive = true
lhs.nameLabel.leadingAnchor.constraint(equalTo: lhs.rankLabel.trailingAnchor, constant: padConstant).isActive = true
lhs.nameLabel.trailingAnchor.constraint(equalTo: lhs.pointsLabel.leadingAnchor, constant: -10).isActive = true
lhs.nameLabel.numberOfLines = 1

if UIDevice.current.userInterfaceIdiom == .pad {
lhs.nameLabel.constrain(width: lhs.contentView.frame.width, height: 40.0)
} else {
lhs.nameLabel.constrain(width: lhs.contentView.frame.width - 185, height: 20.0)
lhs.nameLabel.numberOfLines = 1
}
lhs.separatorView.leadingAnchor.constraint(equalTo: lhs.cellView.leadingAnchor).isActive = true
lhs.separatorView.trailingAnchor.constraint(equalTo: lhs.cellView.trailingAnchor).isActive = true
lhs.separatorView.bottomAnchor.constraint(equalTo: lhs.cellView.bottomAnchor).isActive = true
lhs.separatorView.heightAnchor.constraint(equalToConstant: 1/UIScreen.main.scale).isActive = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import HIAPI
import APIManager

class HILeaderboardListViewController: HIBaseViewController {

}

// MARK: - UITableView Setup
Expand All @@ -24,6 +25,7 @@ extension HILeaderboardListViewController {
if let tableView = tableView {
tableView.register(HILeaderboardCell.self, forCellReuseIdentifier: HILeaderboardCell.identifier)
}

super.setupTableView()
}
}
Expand All @@ -36,19 +38,22 @@ extension HILeaderboardListViewController {
cell <- leaderboardProfile
cell.indexPath = indexPath
cell.rankLabel.text = "\((indexPath.row) + 1)"
cell.backgroundColor = #colorLiteral(red: 0.7882352941, green: 0.8235294118, blue: 0.8980392157, alpha: 1)
tableView.separatorStyle = .singleLine
tableView.separatorInset = UIEdgeInsets()
tableView.separatorColor = #colorLiteral(red: 0.04009541315, green: 0.1307413591, blue: 0.3802352191, alpha: 1)
cell.backgroundColor = .clear

cell.cellView.backgroundColor = #colorLiteral(red: 0.7882352941, green: 0.8235294118, blue: 0.8980392157, alpha: 1)

// Round certain corners based on row
if indexPath.row == 0 {
cell.layer.cornerRadius = 20
cell.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
cell.cellView.layer.cornerRadius = 20
cell.cellView.layer.maskedCorners = [.layerMinXMinYCorner, .layerMaxXMinYCorner]
cell.separatorView.isHidden = false
} else if indexPath.row == 9 {
cell.layer.cornerRadius = 20
cell.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
cell.cellView.layer.cornerRadius = 20
cell.cellView.layer.maskedCorners = [.layerMinXMaxYCorner, .layerMaxXMaxYCorner]
cell.separatorView.isHidden = true
} else {
cell.layer.cornerRadius = 0
cell.cellView.layer.cornerRadius = 0
cell.separatorView.isHidden = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ extension HILeaderboardViewController {
tableView.layer.cornerRadius = 8
tableView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 15 * padConstant).isActive = true
tableView.heightAnchor.constraint(equalTo: view.safeAreaLayoutGuide.heightAnchor, multiplier: 0.90).isActive = true
tableView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor, multiplier: 0.85).isActive = true
tableView.widthAnchor.constraint(equalTo: view.safeAreaLayoutGuide.widthAnchor, multiplier: 1).isActive = true
tableView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor).isActive = true
self.tableView = tableView
}
Expand Down