91 lines
2.7 KiB
Swift
91 lines
2.7 KiB
Swift
//
|
|
// CarouselSlotCell.swift
|
|
// VDS
|
|
//
|
|
// Created by Kanamarlapudi, Vasavi on 23/08/24.
|
|
//
|
|
|
|
import Foundation
|
|
import UIKit
|
|
|
|
final class CarouselSlotCell: UICollectionViewCell {
|
|
|
|
///Identifier for the Calendar Date Cell.
|
|
static let identifier: String = String(describing: CarouselSlotCell.self)
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Initializers
|
|
//--------------------------------------------------
|
|
override init(frame: CGRect) {
|
|
super.init(frame: frame)
|
|
setUp()
|
|
}
|
|
|
|
required init?(coder: NSCoder) {
|
|
super.init(coder: coder)
|
|
setUp()
|
|
}
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Private Properties
|
|
//--------------------------------------------------
|
|
private var surface: Surface = .light
|
|
|
|
//--------------------------------------------------
|
|
// MARK: - Private Methods
|
|
//--------------------------------------------------
|
|
|
|
/// Configuring the cell with default setup.
|
|
private func setUp() {
|
|
isAccessibilityElement = true
|
|
}
|
|
|
|
/// Updating UI based on data along with surface.
|
|
func update(with component: UIView, slotAlignment: Carousel.CarouselSlotAlignmentModel?, surface: Surface) {
|
|
self.surface = surface
|
|
contentView.addSubview(component)
|
|
if var surfacedView = component as? Surfaceable {
|
|
surfacedView.surface = surface
|
|
}
|
|
setSlotAlignment(alignment: slotAlignment, contentView: component)
|
|
}
|
|
|
|
// Set slot alignment if provided. Used only when slot content have different heights or widths.
|
|
private func setSlotAlignment(alignment: Carousel.CarouselSlotAlignmentModel?, contentView: UIView) {
|
|
switch alignment?.vertical {
|
|
case .top:
|
|
contentView
|
|
.pinTop()
|
|
.pinBottomLessThanOrEqualTo()
|
|
case .middle:
|
|
contentView
|
|
.pinTopGreaterThanOrEqualTo()
|
|
.pinBottomLessThanOrEqualTo()
|
|
.pinCenterY()
|
|
case .bottom:
|
|
contentView
|
|
.pinTopGreaterThanOrEqualTo()
|
|
.pinBottom()
|
|
default: break
|
|
}
|
|
|
|
switch alignment?.horizontal {
|
|
case .left:
|
|
contentView
|
|
.pinLeading()
|
|
.pinTrailingLessThanOrEqualTo()
|
|
case .center:
|
|
contentView
|
|
.pinLeadingGreaterThanOrEqualTo()
|
|
.pinTrailingLessThanOrEqualTo()
|
|
.pinCenterX()
|
|
case .right:
|
|
contentView
|
|
.pinLeadingGreaterThanOrEqualTo()
|
|
.pinTrailing()
|
|
default: break
|
|
}
|
|
}
|
|
|
|
}
|