Skip to content

Commit

Permalink
conform tableview to protocols(reuse and configure)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzopiz committed Jul 1, 2024
1 parent 37c3ac5 commit 7bfbb41
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
//
// BaseCollectionReusableView.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit


open class BaseCollectionReusableView: UICollectionReusableView, IConfigurable {

open override class var reuseIdentifier: String {
String(describing: BaseCollectionReusableView.self)
}

public override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
layoutViews()
configureViews()
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

open func configure(_ parametr: Any) { }
}

// MARK: - Configure
@objc
extension BaseCollectionReusableView {
/// Добавляет подвиды на представление.
/// Добавьте код для добавления подвидов на представление,
/// таких как их инициализация, настройка свойств и добавление на представление.
open func setupViews() { }

/// Устанавливает ограничения для подвидов внутри представления.
/// Добавьте код для установки ограничений для подвидов,
/// таких как установка автолейаут-ограничений, задание отступов и т.д.
open func layoutViews() { }

/// Настраивает внешний вид представления.
/// Добавьте код для настройки внешнего вида представления,
/// таких как установка фона, цветов, шрифтов и других свойств визуальных элементов.
/// Вы также можете применять стили, добавлять тени, закруглять углы и т.д.
open func configureViews() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// BaseTableViewCell.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

open class BaseTableViewCell: UICollectionViewCell, IConfigurable {

open override class var reuseIdentifier: String {
String(describing: BaseTableViewCell.self)
}

public override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
layoutViews()
configureViews()
}
required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

open func configure(_ parametr: Any) { }
}

// MARK: - Configure
@objc
extension BaseTableViewCell {
/// Добавляет подвиды на представление.
/// Добавьте код для добавления подвидов на представление,
/// таких как их инициализация, настройка свойств и добавление на представление.
open func setupViews() { }

/// Устанавливает ограничения для подвидов внутри представления.
/// Добавьте код для установки ограничений для подвидов,
/// таких как установка автолейаут-ограничений, задание отступов и т.д.
open func layoutViews() { }

/// Настраивает внешний вид представления.
/// Добавьте код для настройки внешнего вида представления,
/// таких как установка фона, цветов, шрифтов и других свойств визуальных элементов.
/// Вы также можете применять стили, добавлять тени, закруглять углы и т.д.
open func configureViews() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
//
// File.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

open class BaseTableViewHeaderFooterView: UITableViewHeaderFooterView, IConfigurable {

open override class var reuseIdentifier: String {
String(describing: BaseTableViewCell.self)
}
public override init(reuseIdentifier: String?) {
super.init(reuseIdentifier: reuseIdentifier)
setupViews()
layoutViews()
configureViews()
}

required public init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

open func configure(_ parametr: Any) { }
}

// MARK: - Configure
@objc
extension BaseTableViewHeaderFooterView {
/// Добавляет подвиды на представление.
/// Добавьте код для добавления подвидов на представление,
/// таких как их инициализация, настройка свойств и добавление на представление.
open func setupViews() { }

/// Устанавливает ограничения для подвидов внутри представления.
/// Добавьте код для установки ограничений для подвидов,
/// таких как установка автолейаут-ограничений, задание отступов и т.д.
open func layoutViews() { }

/// Настраивает внешний вид представления.
/// Добавьте код для настройки внешнего вида представления,
/// таких как установка фона, цветов, шрифтов и других свойств визуальных элементов.
/// Вы также можете применять стили, добавлять тени, закруглять углы и т.д.
open func configureViews() { }
}
14 changes: 14 additions & 0 deletions Sources/UIComponents/Extensions/UICollectionReusableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UICollectionReusableView.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

extension UICollectionReusableView: IReusableView {
@objc public class var reuseIdentifier: String {
String(describing: UICollectionReusableView.self)
}
}
10 changes: 6 additions & 4 deletions Sources/UIComponents/Extensions/UICollectionViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@

import UIKit

public protocol IReusableCell {
public protocol IReusableView {
static var reuseIdentifier: String { get }
}
extension UICollectionViewCell: IReusableCell {
@objc public class var reuseIdentifier: String { String(describing: UICollectionViewCell.self) }
}

extension UICollectionViewCell {
@objc public class override var reuseIdentifier: String {
String(describing: UICollectionViewCell.self)
}
}
27 changes: 27 additions & 0 deletions Sources/UIComponents/Extensions/UITableView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// UITableView.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

public extension UITableView {
/// Регистрирует указанные типы ячеек для использования в таблице.
/// - Parameter cells: Типы ячеек, которые необходимо зарегистрировать.
func registerCells(_ cells: UITableViewCell.Type...) {
cells.forEach { cell in
register(cell.self, forCellReuseIdentifier: cell.reuseIdentifier)
}
}

/// Регистрирует указанные типы представлений для использования в таблице.
/// - Parameter cells: Типы представлений, которые необходимо зарегистрировать.
func registerReuseViews(_ views: UITableViewHeaderFooterView.Type...) {
views.forEach { view in
register(view.self, forHeaderFooterViewReuseIdentifier: view.reuseIdentifier)
}
}
}

15 changes: 15 additions & 0 deletions Sources/UIComponents/Extensions/UITableViewCell.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// UITableViewCell.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

extension UITableViewCell: IReusableView {
@objc public class var reuseIdentifier: String {
String(describing: UITableViewCell.self)
}
}

14 changes: 14 additions & 0 deletions Sources/UIComponents/Extensions/UITableViewHeaderFooterView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//
// UITableViewHeaderFooterView.swift
//
//
// Created by Дмитрий Корчагин on 7/1/24.
//

import UIKit

extension UITableViewHeaderFooterView: IReusableView {
@objc public class var reuseIdentifier: String {
String(describing: UITableViewHeaderFooterView.self)
}
}

0 comments on commit 7bfbb41

Please sign in to comment.