https://github.com/meniny/boom
🎢 UITableView and UICollectionView manager with efficient, declarative and type-safe approach.
https://github.com/meniny/boom
Last synced: over 1 year ago
JSON representation
🎢 UITableView and UICollectionView manager with efficient, declarative and type-safe approach.
- Host: GitHub
- URL: https://github.com/meniny/boom
- Owner: Meniny
- License: mit
- Created: 2018-06-05T10:08:32.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2019-04-21T11:03:29.000Z (about 7 years ago)
- Last Synced: 2025-02-21T16:34:48.255Z (over 1 year ago)
- Language: Swift
- Homepage:
- Size: 728 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.adoc
- License: LICENSE.md
Awesome Lists containing this project
README
:name: Boom
:author: Elias Abel
:author_esc: Elias%20Abel
:mail: admin@meniny.cn
:desc: an UITableView and UICollectionView manager with efficient, declarative and type-safe approach
:icon: {name}.png
:version: 1.1.0
:na: N/A
:ios: 9.0
:macos: {na}
:watchos: {na}
:tvos: {na}
:linux: {na}
:xcode: 10.2
:swift: 5
:license: MIT
:sep: %20%7C%20
:platform: iOS
// :toc: left
:toclevels: 6
:toc-title: TOC
:source-highlighter: highlightjs
// :source-highlighter: pygments
= Meet `{name}`
{author} <{mail}>
v{version}, 2019-04-21
[subs="attributes"]
++++
++++
:toc:
== 🏵 Introduction
**{name}** is {desc}.
== 📋 Requirements
[%header]
|===
2+^m|Type 1+^m|Requirement
1.5+^.^|Platform ^|iOS ^|{ios}+
^|macOS ^|{macos}
^|tvOS ^|{tvos}
^|watchOS ^|{watchos}
^|Linux ^|{linux}
^|IDE ^|Xcode ^| {xcode}+
^|Language ^|Swift ^| {swift}+
|===
== 📲 Installation
=== CocoaPods
`{name}` is available on link:https://cocoapods.org[CocoaPods].
[source, ruby, subs="verbatim,attributes"]
----
use_frameworks!
pod '{name}'
----
=== Manually
Copy all files in the `{name}` directory into your project.
== 🛌 Dependency
{na}
== ❤️ Contribution
You are welcome to fork and submit pull requests.
== 🔖 License
`{name}` is open-sourced software, licensed under the link:./LICENSE.md[`{license}`] license.
== 🔫 Usage
=== Prepare Model
For example:
[source, swift, subs="verbatim,attributes"]
----
import {name}
// Confirm to BoomModel protocol
struct CellData: Equatable, Hashable, BoomModel {
var identifier: Int {
return id.hashValue
}
let id: String = NSUUID().uuidString
var avatar: UIImage
var title: String
var detail: String?
init(avatar: UIImage, title: String, detail: String?) {
self.avatar = avatar
self.title = title
self.detail = detail
}
}
----
=== Prepare Cell
For example:
[source, swift, subs="verbatim,attributes"]
----
import {name}
class ConversationTableViewCell: UITableViewCell {
@IBOutlet weak var titleLbale: UILabel!
@IBOutlet weak var avatarImageView: UIImageView!
@IBOutlet weak var subtitleLabel: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
titleLbale.font = UIFont.boldSystemFont(ofSize: 20)
titleLbale.textColor = UIColor.darkText
subtitleLabel.font = UIFont.systemFont(ofSize: 15)
subtitleLabel.textColor = UIColor.lightGray
}
}
// Confirm to BoomCell protocol
extension ConversationTableViewCell {
static var reuseIdentifier: String {
return "ConversationTableViewCell"
}
static var registerAsClass: Bool {
return false
}
}
----
=== Generate Adapter
[source, swift, subs="verbatim,attributes"]
----
let adapter = TableAdapter()
adapter.on.dequeue = { ctx in
ctx.cell?.avatarImageView.image = ctx.model.avatar
ctx.cell?.titleLbale?.text = ctx.model.title
ctx.cell?.subtitleLabel?.text = ctx.model.detail
}
adapter.on.tap = { ctx in
print("Tapped on \(ctx.model.identifier)")
return .deselectAnimated
}
tableView.manager.register(adapter: adapter)
----
=== Generate Sections
[source, swift, subs="verbatim,attributes"]
----
let dataSet: [CellData] = [...]
// optional: Header
let header = TableSectionView()
header.on.height = { _ in
return 50
}
// optional: Footer
let footer = TableSectionView()
footer.on.height = { _ in
return 30
}
footer.on.dequeue = { ctx in
ctx.view?.titleLabel?.text = "\(dataSet.count) Data"
}
// generate
let section = TableSection(headerView: header, footerView: footer, models: dataSet)
// add to manager
tableView.manager.add(section: section)
----
=== Setup Height for Rows
[source, swift, subs="verbatim,attributes"]
----
tableView.manager.rowHeight = .autoLayout(estimated: 100)
----
=== Reload
[source, swift, subs="verbatim,attributes"]
----
tableView.manager.reloadData(after: { _ in
return TableReloadAnimations.default()
}, onEnd: nil)
----