// // PaginationButton.swift // VDS // // Created by Bandaru, Krishna Kishore on 05/03/24. // import UIKit import VDSColorTokens ///This is customised button for Pagination view @objc(PaginationButton) open class PaginationButton: ButtonBase { //-------------------------------------------------- // MARK: - Private Properties //-------------------------------------------------- /// Type of the PaginationButton private var type: Type = .next /// Button tint color configuration private let buttonTintColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteWhite) /// Button title color configuration private let buttonTextColorConfiguration = SurfaceColorConfiguration(VDSColor.paletteBlack, VDSColor.paletteWhite) /// Button configuration for iOS 15+ @available(iOS 15.0, *) private var buttonConfiguration: Button.Configuration { var configuration = ButtonBase.Configuration.plain() configuration.imagePadding = VDSLayout.Spacing.space2X.value configuration.imagePlacement = type == .next ? .trailing : .leading configuration.titleAlignment = type == .next ? .trailing : .leading configuration.contentInsets = .zero return configuration } //-------------------------------------------------- // MARK: - Public Properties //-------------------------------------------------- /// TextStyle used on the titleLabel. open override var textStyle: TextStyle { TextStyle.boldBodySmall } /// UIColor used on the titleLabel text. open override var textColor: UIColor { buttonTextColorConfiguration.getColor(surface) } //-------------------------------------------------- // MARK: - Initializers //-------------------------------------------------- init(type: Type) { self.type = type super.init() } required public init() { super.init() } public required init?(coder: NSCoder) { super.init(coder: coder) } //-------------------------------------------------- // MARK: - Overrides //-------------------------------------------------- /// Executed on initialization for this View. open override func initialSetup() { super.initialSetup() if #available(iOS 15.0, *) { configuration = buttonConfiguration } else { semanticContentAttribute = type == .next ? .forceRightToLeft : .forceLeftToRight imageEdgeInsets = .init(top: 0, left: 0, bottom: 0, right: VDSLayout.Spacing.space2X.value) } contentHorizontalAlignment = type == .next ? .trailing : .leading } /// Used to make changes to the View based off a change events or from local properties. open override func updateView() { text = type.title setImage(type.image, for: .normal) tintColor = buttonTintColorConfiguration.getColor(surface) super.updateView() } } extension PaginationButton { //-------------------------------------------------- // MARK: - Enum to configure PaginationButton //-------------------------------------------------- enum `Type` { case previous, next var title: String { switch self { case .next: "Next" case .previous: "Previous" } } ///Image for the configuration type var image: UIImage? { switch self { case .previous: BundleManager.shared.image(for: "pagination-arrow-left")?.withRenderingMode(.alwaysTemplate) case .next: BundleManager.shared.image(for: "pagination-arrow-right")?.withRenderingMode(.alwaysTemplate) } } } }