Skip to content

Commit

Permalink
Merge pull request #64 from PB-Digital/develop
Browse files Browse the repository at this point in the history
RELEASE: 1.5.3
  • Loading branch information
muradtries authored Sep 13, 2024
2 parents 93832c2 + 6c77e1e commit 91ca242
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 88 deletions.
4 changes: 2 additions & 2 deletions Config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"version": "1.5.2",
"release_notes": "Imported `SpreadsheetView` library into codebase"
"version": "1.5.3",
"release_notes": "- Made minor improvements on the codebase"
}
44 changes: 44 additions & 0 deletions Sources/PashaKit/Extensions/Cell+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
//
// File.swift
//
//
// Created by Murad on 13.09.24.
//

import UIKit

extension UITableView {
public func register(_ type: UITableViewCell.Type) {
self.register(type, forCellReuseIdentifier: type.identifier)
}

public func dequeueReusableCell<T: UITableViewCell>(withType type: T.Type) -> T? {
return self.dequeueReusableCell(withIdentifier: type.identifier) as? T
}

public func dequeueReusableCell<T: UITableViewCell>(withType type: T.Type, for indexPath: IndexPath) -> T? {
return self.dequeueReusableCell(withIdentifier: type.identifier, for: indexPath) as? T
}
}

extension UICollectionView {
public func register(_ type: UICollectionViewCell.Type) {
self.register(type, forCellWithReuseIdentifier: type.identifier)
}

public func dequeueReusableCell<T: UICollectionViewCell>(withType type: T.Type, for indexPath: IndexPath) -> T? {
return self.dequeueReusableCell(withReuseIdentifier: type.identifier, for: indexPath) as? T
}
}

extension UITableViewCell {
public static var identifier: String {
return String(describing: self)
}
}

extension UICollectionViewCell {
public static var identifier: String {
return String(describing: self)
}
}
15 changes: 15 additions & 0 deletions Sources/PashaKit/Extensions/UIView+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -222,3 +222,18 @@ public extension UIView {
view.layer.mask = maskLayer
}
}

public extension UIView {
func set(cornerRadius: CGFloat, cornerCurve: CALayerCornerCurve = .continuous) {
self.layer.cornerCurve = cornerCurve
self.layer.cornerRadius = cornerRadius
}

func set(borderColor: UIColor) {
self.layer.borderColor = borderColor.cgColor
}

func set(borderWidth: CGFloat) {
self.layer.borderWidth = borderWidth
}
}
32 changes: 12 additions & 20 deletions Sources/PashaKit/Flow Layouts/PBSnappingLayout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,14 @@ public class PBSnappingLayout: UICollectionViewFlowLayout {
}

var offsetAdjusment = CGFloat.greatestFiniteMagnitude
let horizontalPosition: CGFloat

switch snapPosition {
let horizontalPosition = switch snapPosition {
case .left:
horizontalPosition = proposedContentOffset.x + collectionView.contentInset.left + sectionInset.left
proposedContentOffset.x + collectionView.contentInset.left + sectionInset.left
case .center:
horizontalPosition = proposedContentOffset.x + (collectionView.bounds.width * 0.5)
proposedContentOffset.x + (collectionView.bounds.width * 0.5)
case .right:
horizontalPosition = proposedContentOffset.x + collectionView.bounds.width - sectionInset.right
proposedContentOffset.x + collectionView.bounds.width - sectionInset.right
}

let targetRect = CGRect(
Expand All @@ -75,29 +74,22 @@ public class PBSnappingLayout: UICollectionViewFlowLayout {
let layoutAttributesArray = super.layoutAttributesForElements(in: targetRect)

layoutAttributesArray?.forEach { layoutAttributes in
let itemHorizontalPosition: CGFloat

switch snapPosition {
let itemHorizontalPosition = switch snapPosition {
case .left:
itemHorizontalPosition = layoutAttributes.frame.minX - collectionView.contentInset.left
layoutAttributes.frame.minX
case .center:
itemHorizontalPosition = layoutAttributes.center.x
layoutAttributes.center.x
case .right:
itemHorizontalPosition = layoutAttributes.frame.maxX + collectionView.contentInset.right
layoutAttributes.frame.maxX
}

if abs(itemHorizontalPosition - horizontalPosition) < abs(offsetAdjusment) {

if abs(velocity.x) < self.minimumSnapVelocity {
offsetAdjusment = itemHorizontalPosition - horizontalPosition
}

else if velocity.x > 0 {
offsetAdjusment = itemHorizontalPosition - horizontalPosition + (layoutAttributes.bounds.width + self.minimumLineSpacing)
}

else {
offsetAdjusment = itemHorizontalPosition - horizontalPosition - (layoutAttributes.bounds.width + self.minimumLineSpacing)
} else if velocity.x > 0 {
offsetAdjusment = itemHorizontalPosition - horizontalPosition + (layoutAttributes.bounds.width + minimumLineSpacing)
} else {
offsetAdjusment = itemHorizontalPosition - horizontalPosition - (layoutAttributes.bounds.width + minimumLineSpacing)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/PashaKit/PBCardInputView/PBCardInputView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ open class PBCardInputView: UIView {
}

private func setupViews() {
self.layer.cornerRadius = self.cornerRadius
self.set(cornerRadius: self.cornerRadius)
self.layer.masksToBounds = true

self.setTheme()
self.setupConstraints()
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/PashaKit/PBCardRowView/PBCardRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ open class PBCardRowView: UIView, PBSkeletonable {

view.translatesAutoresizingMaskIntoConstraints = false

view.layer.cornerRadius = 6.0
view.set(cornerRadius: 6.0)
view.layer.masksToBounds = true

view.heightAnchor.constraint(equalToConstant: 36.0).isActive = true
Expand Down
4 changes: 2 additions & 2 deletions Sources/PashaKit/PBContactRowView/PBContactRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ open class PBContactRowView: UIView {
label.backgroundColor = UIColor.Colors.PBGreen
label.textColor = .white
label.textAlignment = .center
label.layer.cornerRadius = 20.0
label.set(cornerRadius: 20.0)
label.layer.masksToBounds = true

label.widthAnchor.constraint(equalToConstant: 40.0).isActive = true
Expand Down Expand Up @@ -265,7 +265,7 @@ open class PBContactRowView: UIView {
self.translatesAutoresizingMaskIntoConstraints = false
self.backgroundColor = UIColor(red: 0.969, green: 0.969, blue: 0.969, alpha: 1)
self.layer.masksToBounds = true
self.layer.cornerRadius = 10.0
self.set(cornerRadius: 10.0)

self.primaryStackView.addArrangedSubview(self.letterLabel)
self.primaryStackView.addArrangedSubview(self.contactInfoStackView)
Expand Down
2 changes: 1 addition & 1 deletion Sources/PashaKit/PBInfoBar/PBInfoBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ open class PBInfoBar: UIView {

private func setupDefaults() {
self.backgroundColor = UIColor.Colors.PBGrayTransparent
self.layer.cornerRadius = 12.0
self.set(cornerRadius: 12.0)
}

func setup(attentionLevel: AttentionLevel) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/PashaKit/PBPaddingLabel/PBPaddingLabel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ open class PBPaddingLabel: UILabel {
self.edgeInsets = edgeInsets
super.init(frame: CGRect.zero)
self.clipsToBounds = true
self.layer.cornerRadius = cornerRadius
self.set(cornerRadius: cornerRadius)
self.layer.masksToBounds = true
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PashaKit/PBRoundedView/PBRoundedView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ public class PBRoundedView: UIView {
public override func layoutSubviews() {
switch self.style {
case .roundedRect(let cornerRadius):
self.layer.cornerRadius = cornerRadius
self.set(cornerRadius: cornerRadius)
case .circle:
self.layer.cornerRadius = self.frame.width / 2.0
self.set(cornerRadius: self.frame.width / 2.0)
}
}

Expand Down
4 changes: 2 additions & 2 deletions Sources/PashaKit/PBRowView/PBRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -728,9 +728,9 @@ open class PBRowView: UIView, PBSkeletonable {
private func setupLeftIconCornerRadius(style: Style) {
switch style {
case .roundedRect(cornerRadius: let cornerRadius):
self.leftIconWrapperView.layer.cornerRadius = cornerRadius
self.leftIconWrapperView.set(cornerRadius: cornerRadius)
case .circle:
self.leftIconWrapperView.layer.cornerRadius = self.leftViewSize.width / 2
self.leftIconWrapperView.set(cornerRadius: self.leftViewSize.width / 2)
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/PashaKit/PBRowView/PBTransactionRowView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@ public class PBTransactionRowView: UIView, PBSkeletonable {
didSet {
switch self.leftIconStyle {
case .roundedRect(cornerRadius: let cornerRadius):
self.categoryImage.layer.cornerRadius = cornerRadius
self.categoryImage.set(cornerRadius: cornerRadius)
case .circle:
self.categoryImage.layer.cornerRadius = 20.0
self.categoryImage.set(cornerRadius: 20.0)
}
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ public class PBTransactionRowView: UIView, PBSkeletonable {
self.transactionInfoContainerView.addSubview(view)

view.translatesAutoresizingMaskIntoConstraints = false
view.layer.cornerRadius = 10
view.set(cornerRadius: 10.0)
view.isHidden = true

return view
Expand Down Expand Up @@ -329,9 +329,9 @@ public class PBTransactionRowView: UIView, PBSkeletonable {

switch self.leftIconStyle {
case .roundedRect(cornerRadius: let cornerRadius):
self.categoryImage.layer.cornerRadius = cornerRadius
self.categoryImage.set(cornerRadius: cornerRadius)
case .circle:
self.categoryImage.layer.cornerRadius = 20.0
self.categoryImage.set(cornerRadius: 20.0)
}

NSLayoutConstraint.activate([
Expand Down
10 changes: 5 additions & 5 deletions Sources/PashaKit/PBSelectField/PBAccountSelectField.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ open class PBAccountSelectField: UIView {
self.addSubview(view)

view.frame = CGRect()
view.layer.cornerRadius = 8
view.layer.borderColor = UIColor.Colors.PBGraySecondary.cgColor
view.layer.borderWidth = 1.0
view.set(cornerRadius: 12.0)
view.set(borderColor: UIColor.Colors.PBGraySecondary)
view.set(borderWidth: 1.0)
view.backgroundColor = .clear
view.translatesAutoresizingMaskIntoConstraints = false

Expand Down Expand Up @@ -270,12 +270,12 @@ open class PBAccountSelectField: UIView {
private func updateUI() {
switch self.isValid {
case .valid:
self.customBorder.layer.borderColor = UIColor.Colors.PBGraySecondary.cgColor
self.customBorder.set(borderColor: UIColor.Colors.PBGraySecondary)
self.footerLabel.textColor = UIColor.black.withAlphaComponent(0.6)
self.placeholderLabel.textColor = UIColor.black.withAlphaComponent(0.6)
self.footerLabel.text = self.footerLabelText
case .invalid(let error):
self.customBorder.layer.borderColor = UIColor.systemRed.cgColor
self.customBorder.set(borderColor: UIColor.systemRed)
self.footerLabel.textColor = .systemRed
self.placeholderLabel.textColor = .systemRed
self.footerLabel.text = error
Expand Down
20 changes: 10 additions & 10 deletions Sources/PashaKit/PBSelectables/PBBaseSelectableView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ open class PBBaseSelectableView: UIView {

func setupViews() {
self.setupDefaults()
self.layer.borderColor = UIColor.Colors.PBGraySecondary.cgColor
self.set(borderColor: UIColor.Colors.PBGraySecondary)
self.backgroundColor = UIColor.white
}

Expand All @@ -178,17 +178,17 @@ open class PBBaseSelectableView: UIView {
switch self.selectionStyle {
case .highlighted:
if self.isSelected {
self.layer.borderWidth = 2.0
self.layer.borderColor = self.selectedBorderColor.cgColor
self.set(borderWidth: 1.0)
self.set(borderColor: self.selectedBorderColor)
self.backgroundColor = self.selectedStateColor
} else {
self.layer.borderWidth = 1.0
self.layer.borderColor = UIColor.Colors.PBGraySecondary.cgColor
self.set(borderWidth: 1.0)
self.set(borderColor: UIColor.Colors.PBGraySecondary)
self.backgroundColor = UIColor.white
}
case .clear:
self.layer.borderWidth = 0.0
self.layer.borderColor = UIColor.clear.cgColor
self.set(borderWidth: 0.0)
self.set(borderColor: UIColor.clear)
self.backgroundColor = UIColor.clear
}
}
Expand All @@ -213,7 +213,7 @@ open class PBBaseSelectableView: UIView {
/// method to enable alert state.
///
public func setAlertState() {
self.layer.borderColor = UIColor.Colors.PBInvalidRed.cgColor
self.set(borderColor: UIColor.Colors.PBInvalidRed)
self.layer.backgroundColor = UIColor.clear.cgColor
}

Expand All @@ -222,8 +222,8 @@ open class PBBaseSelectableView: UIView {
}

private func setupDefaults() {
self.layer.cornerRadius = 8.0
self.layer.borderWidth = 1.0
self.set(cornerRadius: 12.0)
self.set(borderWidth: 1.0)
}
}

12 changes: 6 additions & 6 deletions Sources/PashaKit/PBTemplateView/PBTemplateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ public class PBTemplateView: UIView {
didSet {
switch self.viewType {
case .payment:
self.iconView.layer.cornerRadius = 24.0
self.iconView.set(cornerRadius: 24.0)
case .template:
self.iconView.layer.cornerRadius = 8.0
self.iconView.set(cornerRadius: 8.0)
}
}
}
Expand Down Expand Up @@ -160,7 +160,7 @@ public class PBTemplateView: UIView {
view.translatesAutoresizingMaskIntoConstraints = false

view.backgroundColor = UIColor(red: 0.604, green: 0.608, blue: 0.612, alpha: 0.08)
view.layer.cornerRadius = 24.0
view.set(cornerRadius: 24.0)

view.widthAnchor.constraint(equalToConstant: 48.0).isActive = true
view.heightAnchor.constraint(equalToConstant: 48.0).isActive = true
Expand Down Expand Up @@ -237,17 +237,17 @@ public class PBTemplateView: UIView {

private func setupViews(for type: ViewType) {
self.backgroundColor = .clear
self.layer.cornerRadius = 16.0
self.set(cornerRadius: 16.0)
self.layer.masksToBounds = true
self.contentStackView.addArrangedSubview(self.titleLabel)
self.contentStackView.addArrangedSubview(self.subtitleLabel)
self.setupConstraints(for: type)

switch type {
case .payment:
self.iconWrapperView.layer.cornerRadius = 24.0
self.iconWrapperView.set(cornerRadius: 24.0)
case .template:
self.iconWrapperView.layer.cornerRadius = 8.0
self.iconWrapperView.set(cornerRadius: 8.0)
}
}

Expand Down
Loading

0 comments on commit 91ca242

Please sign in to comment.