You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

249 lines
8.4 KiB

//
// ReferralView.swift
// GME Remit
//
// Created by Armaan Shrestha on 21/08/2022.
// Copyright © 2022 Gobal Money Express Co. Ltd. All rights reserved.
//
import UIKit
private let reuseIdentifier = "cell"
class ReferralView: UIView {
lazy var containerView: UIView = {
let view = UIView()
view.backgroundColor = .themeSubBackground
view.isUserInteractionEnabled = true
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
private var collectionView: UICollectionView!
var screenWidth = UIScreen.main.bounds.width
var screenHeight = UIScreen.main.bounds.height
var serviceIconSize: CGFloat = 65
var serviceIconSpacing: CGFloat = 14
public var data: [ReferralDetails]? {
didSet {
collectionView.reloadData()
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setup()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
setup()
fatalError("init(coder:) has not been implemented")
}
func setup() {
setupView()
}
func setupView() {
self.backgroundColor = .black
self.addSubview(containerView)
let layout = UICollectionViewFlowLayout()
collectionView = UICollectionView(frame: .zero, collectionViewLayout: layout)
collectionView.delegate = self
collectionView.dataSource = self
collectionView.register(ReferralCell.self, forCellWithReuseIdentifier: reuseIdentifier)
collectionView.backgroundColor = .clear
collectionView.isScrollEnabled = true
// Hide Scroll bars
collectionView.showsHorizontalScrollIndicator = false
collectionView.showsVerticalScrollIndicator = false
collectionView.translatesAutoresizingMaskIntoConstraints = false
// Avoids shadow of collection view cell from being clipped
collectionView.clipsToBounds = false
containerView.addSubview(collectionView)
setupLayoutConstraints()
// setupClickListiner()
}
func setupLayoutConstraints() {
NSLayoutConstraint.activate([
containerView.topAnchor.constraint(equalTo: safeAreaLayoutGuide.topAnchor),
containerView.leadingAnchor.constraint(equalTo: leadingAnchor),
containerView.trailingAnchor.constraint(equalTo: trailingAnchor),
containerView.bottomAnchor.constraint(equalTo: safeAreaLayoutGuide.bottomAnchor)
])
NSLayoutConstraint.activate([
collectionView.topAnchor.constraint(equalTo: containerView.topAnchor),
collectionView.leadingAnchor.constraint(equalTo: containerView.leadingAnchor),
collectionView.trailingAnchor.constraint(equalTo: containerView.trailingAnchor),
collectionView.bottomAnchor.constraint(equalTo: containerView.bottomAnchor)
])
}
}
extension ReferralView: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
public func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return data?.count ?? 0
// return 4
}
public func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! ReferralCell
let item = data![indexPath.row]
let dates = (item.createdDate ?? "").split(separator: " ")
let date = dates[0].replacingOccurrences(of: "/", with: "-", options: .literal, range: nil)
cell.titleText = date
cell.amountText = item.rewardAmount ?? ""
cell.typeText = item.rewardType ?? ""
return cell
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
let iconHeight = serviceIconSize
return CGSize(width: collectionView.frame.width, height: iconHeight)
}
public func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat {
return serviceIconSpacing
}
}
class ReferralCell: UICollectionViewCell {
lazy var wrapperView: UIView = {
let view = UIView()
view.backgroundColor = .clear
view.set(cornerRadius: 5)
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
lazy var mainStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 10
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
lazy var titleStackView : UIStackView = {
let stackView = UIStackView()
stackView.axis = .horizontal
stackView.spacing = 5
stackView.translatesAutoresizingMaskIntoConstraints = false
return stackView
}()
lazy var titleLabel: UILabel = {
let label = UILabel()
label.text = "text here"
label.font = .sanfrancisco(.semibold, size: 16)
label.numberOfLines = 1
label.textColor = .themeBlack
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
lazy var amountLabel: UILabel = {
let label = UILabel()
label.text = "text here"
label.font = .sanfrancisco(.bold, size: 14)
label.numberOfLines = 1
label.textColor = .themeBlue
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
lazy var typeLabel: UILabel = {
let label = UILabel()
label.text = "text here"
label.font = .sanfrancisco(.regular, size: 14)
label.numberOfLines = 1
label.textColor = .themeBlack
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
var titleText = String() {
didSet {
titleLabel.text = titleText
}
}
var amountText = String() {
didSet {
amountLabel.text = amountText
}
}
var verticalLine: UIView = {
var view = UIView()
view.backgroundColor = .themeGray2
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var typeText = String() {
didSet {
typeLabel.text = typeText
}
}
override init(frame: CGRect) {
super.init(frame: frame)
setupView()
}
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override func awakeFromNib() {
super.awakeFromNib()
}
func setupView() {
contentView.addSubview(wrapperView)
wrapperView.addSubview(mainStackView)
wrapperView.addSubview(verticalLine)
mainStackView.addArrangedSubview(titleStackView)
mainStackView.addArrangedSubview(typeLabel)
titleStackView.addArrangedSubview(titleLabel)
titleStackView.addArrangedSubview(amountLabel)
setupConstraint()
}
private func setupConstraint() {
NSLayoutConstraint.activate([
wrapperView.topAnchor.constraint(equalTo: contentView.topAnchor),
wrapperView.trailingAnchor.constraint(equalTo: contentView.trailingAnchor),
wrapperView.leadingAnchor.constraint(equalTo: contentView.leadingAnchor)
])
NSLayoutConstraint.activate([
mainStackView.topAnchor.constraint(equalTo: wrapperView.topAnchor, constant: 20),
mainStackView.leadingAnchor.constraint(equalTo: wrapperView.leadingAnchor, constant: 20),
mainStackView.trailingAnchor.constraint(equalTo: wrapperView.trailingAnchor, constant: -20),
mainStackView.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor, constant: -20)
])
NSLayoutConstraint.activate([
verticalLine.bottomAnchor.constraint(equalTo: wrapperView.bottomAnchor),
verticalLine.leadingAnchor.constraint(equalTo: wrapperView.leadingAnchor, constant: 10),
verticalLine.trailingAnchor.constraint(equalTo: wrapperView.trailingAnchor, constant: -10),
verticalLine.heightAnchor.constraint(equalToConstant: 1)
])
}
}