Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
ra1028 committed Jul 28, 2019
1 parent 8c5f726 commit 549b2ef
Show file tree
Hide file tree
Showing 46 changed files with 1,824 additions and 3,548 deletions.
9 changes: 2 additions & 7 deletions .jazzy.yml
Expand Up @@ -44,17 +44,12 @@ custom_categories:
- UICollectionViewReloadDataUpdater
- name: Interfaces
children:
- ComponentRenderable
- UITableViewComponentCell
- UITableViewComponentHeaderFooterView
- UICollectionViewComponentCell
- UICollectionComponentReusableView
- name: Content Protocols
children:
- UITableViewCellContent
- UITableViewHeaderFooterViewContent
- UICollectionViewCellContent
- UICollectionReusableViewContent
- name: Changesets
children:
- DataChangeset
- StagedDataChangeset
- StagedDataChangeset
56 changes: 35 additions & 21 deletions README.md
Expand Up @@ -327,7 +327,9 @@ class MenuItemContent: UIControl {
addTarget(self, action: #selector(handleSelect), for: .touchUpInside)
}
}
```

```swift
struct MenuItem: Component {
var text: String
var onSelect: () -> Void
Expand Down Expand Up @@ -406,18 +408,42 @@ let renderer = Renderer(
)
```

Furthermore, it can be customized the class of the elements(cell/header/footer) which becomes the container of component by setting it to `config`.
Furthermore, it can be customized the class of the elements(cell/header/footer) which becomes the container of components by overriding some methods in adapter as following.
You can also use `xib` by giving nib as parameter of init of the return value Registration.

```swift
class CustomTableViewAdapter: UITableViewAdapter {
// Use custom cell.
override func cellRegistration(tableView: UITableView, indexPath: IndexPath, node: CellNode) -> CellRegistration {
return CellRegistration(class: CustomTableViewCell.self)
}

// Use custom header view.
override func headerViewRegistration(tableView: UITableView, section: Int, node: ViewNode) -> ViewRegistration {
return ViewRegistration(class: CustomTableViewHeaderFooterView.self)
}

// Use custom footer view.
override func footerViewRegistration(tableView: UITableView, section: Int, node: ViewNode) -> ViewRegistration {
return ViewRegistration(class: CustomTableViewHeaderFooterView.self)
}
}
```

- **config**
The configuration which having the classes of elements. It can be specified only when adapter is initialized.
In UICollectionViewAdapter, you can select the node corresponding to a certain kind.

```swift
let config = UITableViewAdapter.Config(
cellClass: CustomCell.self,
headerViewClass: CustomHeaderView.self,
footerViewClass: CustomFooterView.self
)
let adapter = UITableViewAdapter(config: config)
class CustomCollectionViewAdapter: UICollectionViewAdapter {
override func supplementaryViewNode(forElementKind kind: String, collectionView: UICollectionView, at indexPath: IndexPath) -> ViewNode? {
switch kind {
case "CustomSupplementaryViewKindSectionHeader":
return headerNode(in: indexPath.section)

default:
return super.supplementaryViewNode(forElementKind: kind, collectionView: collectionView, at: indexPath)
}
}
}
```

[See more](https://ra1028.github.io/Carbon/Adapters.html)
Expand Down Expand Up @@ -458,18 +484,6 @@ Default is `false`.

[See more](https://ra1028.github.io/Carbon/Updaters.html)

#### Element-Specific Behaviors

The `content` of component can be received some emement-specific events such as when highlighted, selected, or immediately after rendered, by conforming to protocols below.
We recommend to do implementation that doesn't count on this protocols.

- **UITableViewCellContent**
- **UITableViewHeaderFooterViewContent**
- **UICollectionViewCellContent**
- **UICollectionReusableViewContent**

[See more](https://ra1028.github.io/Carbon/Content%20Protocols.html)

---

## Requirements
Expand Down
3 changes: 1 addition & 2 deletions Sources/Adapters/UICollectionViewAdapter.swift
Expand Up @@ -3,7 +3,6 @@ import UIKit
/// An adapter for `UICollectionView`.
/// It can be inherited to implement customized behavior or give some unimplemented
/// methods of delegate or dataSource.
/// Classes of cell, header and footer to be rendered can be customized by `UICollectionViewRenderConfig`.
///
/// Attention : In UIKit, if inheriting the @objc class which using generics, the delegate and dataSource
/// are don't work properly, so this class doesn't use generics, and also the class inherited
Expand All @@ -15,7 +14,7 @@ open class UICollectionViewAdapter: NSObject, Adapter {
/// A closure that to handle selection events of cell.
open var didSelect: ((SelectionContext) -> Void)?

/// Create an adapter with initial data and rendering config.
/// Create an adapter with initial data.
///
/// - Parameters:
/// - data: An initial data to be rendered.
Expand Down
3 changes: 1 addition & 2 deletions Sources/Adapters/UITableViewAdapter.swift
Expand Up @@ -3,7 +3,6 @@ import UIKit
/// An adapter for `UITableView`.
/// It can be inherited to implement customized behavior or give some unimplemented
/// methods of delegate or dataSource.
/// Classes of cell, header and footer to be rendered can be customized by `UITableViewRenderConfig`.
///
/// Attention : In UIKit, if inheriting the @objc class which using generics, the delegate and dataSource
/// are don't work properly, so this class doesn't use generics, and also the class inherited
Expand All @@ -15,7 +14,7 @@ open class UITableViewAdapter: NSObject, Adapter {
/// A closure that to handle selection events of cell.
open var didSelect: ((SelectionContext) -> Void)?

/// Create an adapter with initial data and rendering config.
/// Create an adapter with initial data.
///
/// - Parameters:
/// - data: An initial data to be rendered.
Expand Down
14 changes: 14 additions & 0 deletions Sources/Interfaces/ComponentRenderable.swift
@@ -1,35 +1,45 @@
import UIKit

/// Represents a container that can render a component.
public protocol ComponentRenderable: class {
/// The container view to be render a component.
var componentContainerView: UIView { get }
}

private let renderedContentAssociation = RuntimeAssociation<Any?>(default: nil)
private let renderedComponentAssociation = RuntimeAssociation<AnyComponent?>(default: nil)

public extension ComponentRenderable {
/// A content of component that rendered on container.
private(set) var renderedContent: Any? {
get { return renderedContentAssociation[self] }
set { renderedContentAssociation[self] = newValue }
}

/// A component that latest rendered on container.
private(set) var renderedComponent: AnyComponent? {
get { return renderedComponentAssociation[self] }
set { renderedComponentAssociation[self] = newValue }
}

/// Invoked every time of before a component got into visible area.
func contentWillDisplay() {
guard let content = renderedContent else { return }

renderedComponent?.contentWillDisplay(content)
}

/// Invoked every time of after a component went out from visible area.
func contentDidEndDisplay() {
guard let content = renderedContent else { return }

renderedComponent?.contentDidEndDisplay(content)
}

/// Render given componet to container.
///
/// - Parameter:
/// - component: A component to be rendered.
func render(component: AnyComponent) {
switch (renderedContent, renderedComponent) {
case (let content?, let renderedComponent?) where !renderedComponent.shouldRender(next: component, in: content):
Expand All @@ -49,24 +59,28 @@ public extension ComponentRenderable {
}

public extension ComponentRenderable where Self: UITableViewCell {
/// The container view to be render a component.
var componentContainerView: UIView {
return contentView
}
}

public extension ComponentRenderable where Self: UITableViewHeaderFooterView {
/// The container view to be render a component.
var componentContainerView: UIView {
return contentView
}
}

public extension ComponentRenderable where Self: UICollectionViewCell {
/// The container view to be render a component.
var componentContainerView: UIView {
return contentView
}
}

public extension ComponentRenderable where Self: UICollectionReusableView {
/// The container view to be render a component.
var componentContainerView: UIView {
return self
}
Expand Down
38 changes: 14 additions & 24 deletions docs/Adapters.html
Expand Up @@ -101,7 +101,10 @@
<a class="nav-group-task-link" href="Classes/UITableViewAdapter.html">UITableViewAdapter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/Config.html">– Config</a>
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/CellRegistration.html">– CellRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/ViewRegistration.html">– ViewRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/SelectionContext.html">– SelectionContext</a>
Expand All @@ -110,7 +113,10 @@
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter.html">UICollectionViewAdapter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/Config.html">– Config</a>
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/CellRegistration.html">– CellRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/ViewRegistration.html">– ViewRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/SelectionContext.html">– SelectionContext</a>
Expand Down Expand Up @@ -143,6 +149,9 @@
<li class="nav-group-name">
<a class="nav-group-name-link" href="Interfaces.html">Interfaces</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ComponentRenderable.html">ComponentRenderable</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewComponentCell.html">UITableViewComponentCell</a>
</li>
Expand All @@ -157,23 +166,6 @@
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Content Protocols.html">Content Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UITableViewCellContent.html">UITableViewCellContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UITableViewHeaderFooterViewContent.html">UITableViewHeaderFooterViewContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UICollectionViewCellContent.html">UICollectionViewCellContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UICollectionReusableViewContent.html">UICollectionReusableViewContent</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Changesets.html">Changesets</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -247,8 +239,7 @@ <h4>Declaration</h4>
<div class="abstract">
<p>An adapter for <code>UITableView</code>.
It can be inherited to implement customized behavior or give some unimplemented
methods of delegate or dataSource.
Classes of cell, header and footer to be rendered can be customized by <code>UITableViewRenderConfig</code>.</p>
methods of delegate or dataSource.</p>

<p>Attention : In UIKit, if inheriting the @objc class which using generics, the delegate and dataSource
are don&rsquo;t work properly, so this class doesn&rsquo;t use generics, and also the class inherited
Expand Down Expand Up @@ -286,8 +277,7 @@ <h4>Declaration</h4>
<div class="abstract">
<p>An adapter for <code>UICollectionView</code>.
It can be inherited to implement customized behavior or give some unimplemented
methods of delegate or dataSource.
Classes of cell, header and footer to be rendered can be customized by <code>UICollectionViewRenderConfig</code>.</p>
methods of delegate or dataSource.</p>

<p>Attention : In UIKit, if inheriting the @objc class which using generics, the delegate and dataSource
are don&rsquo;t work properly, so this class doesn&rsquo;t use generics, and also the class inherited
Expand Down Expand Up @@ -346,7 +336,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2019 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2019-05-14)</p>
<p>&copy; 2019 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2019-07-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down
32 changes: 12 additions & 20 deletions docs/Changesets.html
Expand Up @@ -101,7 +101,10 @@
<a class="nav-group-task-link" href="Classes/UITableViewAdapter.html">UITableViewAdapter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/Config.html">– Config</a>
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/CellRegistration.html">– CellRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/ViewRegistration.html">– ViewRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewAdapter/SelectionContext.html">– SelectionContext</a>
Expand All @@ -110,7 +113,10 @@
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter.html">UICollectionViewAdapter</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/Config.html">– Config</a>
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/CellRegistration.html">– CellRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/ViewRegistration.html">– ViewRegistration</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UICollectionViewAdapter/SelectionContext.html">– SelectionContext</a>
Expand Down Expand Up @@ -143,6 +149,9 @@
<li class="nav-group-name">
<a class="nav-group-name-link" href="Interfaces.html">Interfaces</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/ComponentRenderable.html">ComponentRenderable</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Classes/UITableViewComponentCell.html">UITableViewComponentCell</a>
</li>
Expand All @@ -157,23 +166,6 @@
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Content Protocols.html">Content Protocols</a>
<ul class="nav-group-tasks">
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UITableViewCellContent.html">UITableViewCellContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UITableViewHeaderFooterViewContent.html">UITableViewHeaderFooterViewContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UICollectionViewCellContent.html">UICollectionViewCellContent</a>
</li>
<li class="nav-group-task">
<a class="nav-group-task-link" href="Protocols/UICollectionReusableViewContent.html">UICollectionReusableViewContent</a>
</li>
</ul>
</li>
<li class="nav-group-name">
<a class="nav-group-name-link" href="Changesets.html">Changesets</a>
<ul class="nav-group-tasks">
Expand Down Expand Up @@ -263,7 +255,7 @@ <h4>Declaration</h4>
</article>
</div>
<section class="footer">
<p>&copy; 2019 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2019-05-14)</p>
<p>&copy; 2019 <a class="link" href="https://github.com/ra1028" target="_blank" rel="external">Ryo Aoyama</a>. All rights reserved. (Last updated: 2019-07-29)</p>
<p>Generated by <a class="link" href="https://github.com/realm/jazzy" target="_blank" rel="external">jazzy ♪♫ v0.9.4</a>, a <a class="link" href="https://realm.io" target="_blank" rel="external">Realm</a> project.</p>
</section>
</body>
Expand Down

0 comments on commit 549b2ef

Please sign in to comment.