Skip to content

Commit

Permalink
Merge pull request #46 from ra1028/declarative
Browse files Browse the repository at this point in the history
Declarative syntax with function builder
  • Loading branch information
ra1028 authored Sep 11, 2019
2 parents 824dc28 + 3a2c5c5 commit 94b684c
Show file tree
Hide file tree
Showing 155 changed files with 8,562 additions and 2,274 deletions.
78 changes: 44 additions & 34 deletions .jazzy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,42 +14,52 @@ xcodebuild_arguments:
- -scheme
- Carbon
custom_categories:
- name: Components
- name: Element
children:
- Component
- IdentifiableComponent
- AnyComponent
- name: Nodes
- Component
- IdentifiableComponent
- AnyComponent
- Section
- Group
- name: ComponentWrapper
children:
- CellNode
- ViewNode
- name: Section
- IdentifiedComponentWrapper
- ComponentWrapping
- name: Node
children:
- Section
- CellNode
- ViewNode
- name: Renderer
children:
- Renderer
- name: Adapters
children:
- Adapter
- UITableViewAdapter
- UICollectionViewAdapter
- UICollectionViewFlowLayoutAdapter
- name: Updaters
children:
- Updater
- UITableViewUpdater
- UITableViewReloadDataUpdater
- UICollectionViewUpdater
- UICollectionViewReloadDataUpdater
- name: Interfaces
children:
- ComponentRenderable
- UITableViewComponentCell
- UITableViewComponentHeaderFooterView
- UICollectionViewComponentCell
- UICollectionComponentReusableView
- name: Changesets
children:
- DataChangeset
- StagedDataChangeset
- Renderer
- name: Adapter
children:
- Adapter
- UITableViewAdapter
- UICollectionViewAdapter
- UICollectionViewFlowLayoutAdapter
- name: Updater
children:
- Updater
- UITableViewUpdater
- UITableViewReloadDataUpdater
- UICollectionViewUpdater
- UICollectionViewReloadDataUpdater
- name: Interface
children:
- ComponentRenderable
- UITableViewComponentCell
- UITableViewComponentHeaderFooterView
- UICollectionViewComponentCell
- UICollectionComponentReusableView
- name: Builder
children:
- CellsBuilder
- SectionsBuilder
- CellsBuildable
- SectionsBuildable
- Optional
- name: Changeset
children:
- DataChangeset
- StagedDataChangeset
46 changes: 19 additions & 27 deletions Carbon.playground/Contents.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,17 @@ import PlaygroundSupport

// Setup

let frame = CGRect(x: 0, y: 0, width: 320, height: 480)
let frame = CGRect(x: 0, y: 0, width: 375, height: 812)
let tableView = UITableView(frame: frame, style: .grouped)
tableView.estimatedSectionHeaderHeight = 44
tableView.estimatedSectionFooterHeight = 44

PlaygroundPage.current.needsIndefiniteExecution = true
PlaygroundPage.current.liveView = tableView

// Define component

struct Label: Component, Equatable {
struct Label: Component {
var text: String

func renderContent() -> UILabel {
Expand All @@ -30,10 +32,6 @@ struct Label: Component, Equatable {
func render(in content: UILabel) {
content.text = text
}

func referenceSize(in bounds: CGRect) -> CGSize? {
return CGSize(width: bounds.width, height: 44)
}
}

// Create renderer
Expand All @@ -47,26 +45,20 @@ renderer.target = tableView

// Render

renderer.render(
renderer.render {
Section(id: 0) {
Label(text: "Cell 1").identified(by: \.text)
Label(text: "Cell 2").identified(by: \.text)
Label(text: "Cell 3").identified(by: \.text)
Label(text: "Cell 4").identified(by: \.text)
}

Section(
id: 1,
header: ViewNode(Label(text: "Header 1")),
cells: [
CellNode(id: 1, Label(text: "Cell 1")),
CellNode(id: 2, Label(text: "Cell 2")),
CellNode(id: 3, Label(text: "Cell 3")),
CellNode(id: 4, Label(text: "Cell 4"))
],
footer: ViewNode(Label(text: "Footer 1"))
),
Section(
id: 2,
header: ViewNode(Label(text: "Header 2")),
cells: [
CellNode(id: 5, Label(text: "Cell 5")),
CellNode(id: 6, Label(text: "Cell 6")),
CellNode(id: 7, Label(text: "Cell 7"))
],
footer: ViewNode(Label(text: "Footer 2"))
)
)
header: Label(text: "Header 1"),
footer: Label(text: "Footer 1"),
cells: {
Label(text: "Cell 5").identified(by: \.text)
Label(text: "Cell 6").identified(by: \.text)
})
}
2 changes: 1 addition & 1 deletion Carbon.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'Carbon'
spec.version = '1.0.0-rc.2'
spec.version = '1.0.0-rc.3'
spec.author = { 'ra1028' => '[email protected]' }
spec.homepage = 'https://github.com/ra1028/Carbon'
spec.documentation_url = 'https://ra1028.github.io/Carbon'
Expand Down
114 changes: 109 additions & 5 deletions Carbon.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,17 @@

/* Begin PBXBuildFile section */
6B1BE6B722E5CA0D0054DB46 /* ComponentRenderable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B1BE6B622E5CA0D0054DB46 /* ComponentRenderable.swift */; };
6B37B2F52320339300A80D62 /* IdentifiedComponentWrapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B37B2F32320339300A80D62 /* IdentifiedComponentWrapper.swift */; };
6B37B2F62320339300A80D62 /* ComponentWrapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B37B2F42320339300A80D62 /* ComponentWrapping.swift */; };
6B4B11AD2322E62A00D2E7E0 /* Group.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B4B11AC2322E62A00D2E7E0 /* Group.swift */; };
6B5304532201EDB200A3E21E /* DataChangeset.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5304522201EDB200A3E21E /* DataChangeset.swift */; };
6B55C187232789FF004F89F2 /* ComponentWrappingTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C186232789FF004F89F2 /* ComponentWrappingTests.swift */; };
6B55C18923278E53004F89F2 /* IdentifiedComponentWrapperTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C18823278E53004F89F2 /* IdentifiedComponentWrapperTests.swift */; };
6B55C18C23278F6E004F89F2 /* GroupTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C18B23278F6E004F89F2 /* GroupTests.swift */; };
6B55C18E232791DA004F89F2 /* CellsBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C18D232791DA004F89F2 /* CellsBuilderTests.swift */; };
6B55C1902327968A004F89F2 /* SectionsBuilderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C18F2327968A004F89F2 /* SectionsBuilderTests.swift */; };
6B55C19223279865004F89F2 /* CellsBuildableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C19123279865004F89F2 /* CellsBuildableTests.swift */; };
6B55C19423279A69004F89F2 /* SectionsBuildableTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B55C19323279A69004F89F2 /* SectionsBuildableTests.swift */; };
6B6594A421E2532100291AAF /* IdentifiableComponent.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B65948621E2532100291AAF /* IdentifiableComponent.swift */; };
6B6594A621E2532100291AAF /* UICollectionViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B65948A21E2532100291AAF /* UICollectionViewAdapter.swift */; };
6B6594A721E2532100291AAF /* UITableViewAdapter.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B65948B21E2532100291AAF /* UITableViewAdapter.swift */; };
Expand Down Expand Up @@ -53,6 +63,10 @@
6B7EED9E224CA5DD00060872 /* UIScrollViewExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B7EED9D224CA5DD00060872 /* UIScrollViewExtensions.swift */; };
6B7EEDA0224CE4E100060872 /* UIScrollViewExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B7EED9F224CE4E000060872 /* UIScrollViewExtensionsTests.swift */; };
6BAEA43D228D4E920026F81E /* RuntimeAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BAEA43C228D4E920026F81E /* RuntimeAssociation.swift */; };
6BC83E4B231ED14700350855 /* CellsBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BC83E4A231ED14600350855 /* CellsBuilder.swift */; };
6BC83E4D231ED17300350855 /* CellsBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BC83E4C231ED17300350855 /* CellsBuildable.swift */; };
6BC83E51231ED21700350855 /* SectionsBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BC83E50231ED21700350855 /* SectionsBuilder.swift */; };
6BC83E53231ED42C00350855 /* SectionsBuildable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6BC83E52231ED42C00350855 /* SectionsBuildable.swift */; };
/* End PBXBuildFile section */

/* Begin PBXContainerItemProxy section */
Expand All @@ -67,7 +81,17 @@

/* Begin PBXFileReference section */
6B1BE6B622E5CA0D0054DB46 /* ComponentRenderable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentRenderable.swift; sourceTree = "<group>"; };
6B37B2F32320339300A80D62 /* IdentifiedComponentWrapper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentifiedComponentWrapper.swift; sourceTree = "<group>"; };
6B37B2F42320339300A80D62 /* ComponentWrapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ComponentWrapping.swift; sourceTree = "<group>"; };
6B4B11AC2322E62A00D2E7E0 /* Group.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Group.swift; sourceTree = "<group>"; };
6B5304522201EDB200A3E21E /* DataChangeset.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DataChangeset.swift; sourceTree = "<group>"; };
6B55C186232789FF004F89F2 /* ComponentWrappingTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ComponentWrappingTests.swift; sourceTree = "<group>"; };
6B55C18823278E53004F89F2 /* IdentifiedComponentWrapperTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IdentifiedComponentWrapperTests.swift; sourceTree = "<group>"; };
6B55C18B23278F6E004F89F2 /* GroupTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GroupTests.swift; sourceTree = "<group>"; };
6B55C18D232791DA004F89F2 /* CellsBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellsBuilderTests.swift; sourceTree = "<group>"; };
6B55C18F2327968A004F89F2 /* SectionsBuilderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionsBuilderTests.swift; sourceTree = "<group>"; };
6B55C19123279865004F89F2 /* CellsBuildableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellsBuildableTests.swift; sourceTree = "<group>"; };
6B55C19323279A69004F89F2 /* SectionsBuildableTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionsBuildableTests.swift; sourceTree = "<group>"; };
6B65947A21E252E300291AAF /* Carbon.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Carbon.framework; sourceTree = BUILT_PRODUCTS_DIR; };
6B65948621E2532100291AAF /* IdentifiableComponent.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IdentifiableComponent.swift; sourceTree = "<group>"; };
6B65948A21E2532100291AAF /* UICollectionViewAdapter.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UICollectionViewAdapter.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -116,6 +140,10 @@
6B7EED9D224CA5DD00060872 /* UIScrollViewExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIScrollViewExtensions.swift; sourceTree = "<group>"; };
6B7EED9F224CE4E000060872 /* UIScrollViewExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIScrollViewExtensionsTests.swift; sourceTree = "<group>"; };
6BAEA43C228D4E920026F81E /* RuntimeAssociation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RuntimeAssociation.swift; sourceTree = "<group>"; };
6BC83E4A231ED14600350855 /* CellsBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellsBuilder.swift; sourceTree = "<group>"; };
6BC83E4C231ED17300350855 /* CellsBuildable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CellsBuildable.swift; sourceTree = "<group>"; };
6BC83E50231ED21700350855 /* SectionsBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionsBuilder.swift; sourceTree = "<group>"; };
6BC83E52231ED42C00350855 /* SectionsBuildable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SectionsBuildable.swift; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand All @@ -138,6 +166,54 @@
/* End PBXFrameworksBuildPhase section */

/* Begin PBXGroup section */
6B4B11B223244A8500D2E7E0 /* Nodes */ = {
isa = PBXGroup;
children = (
6B65949121E2532100291AAF /* ViewNode.swift */,
6B65949821E2532100291AAF /* CellNode.swift */,
);
path = Nodes;
sourceTree = "<group>";
};
6B4B11B323244AE800D2E7E0 /* ComponentWrapper */ = {
isa = PBXGroup;
children = (
6B37B2F42320339300A80D62 /* ComponentWrapping.swift */,
6B37B2F32320339300A80D62 /* IdentifiedComponentWrapper.swift */,
);
path = ComponentWrapper;
sourceTree = "<group>";
};
6B55C1842327881A004F89F2 /* Nodes */ = {
isa = PBXGroup;
children = (
6B7ADEBD21F8BF89003803BE /* ViewNodeTests.swift */,
6B7ADEBF21F8C651003803BE /* CellNodeTests.swift */,
);
path = Nodes;
sourceTree = "<group>";
};
6B55C185232789DE004F89F2 /* ComponentWrapper */ = {
isa = PBXGroup;
children = (
6B55C186232789FF004F89F2 /* ComponentWrappingTests.swift */,
6B55C18823278E53004F89F2 /* IdentifiedComponentWrapperTests.swift */,
);
path = ComponentWrapper;
sourceTree = "<group>";
};
6B55C18A23278F57004F89F2 /* FunctionBuilder */ = {
isa = PBXGroup;
children = (
6B55C18B23278F6E004F89F2 /* GroupTests.swift */,
6B55C18D232791DA004F89F2 /* CellsBuilderTests.swift */,
6B55C19123279865004F89F2 /* CellsBuildableTests.swift */,
6B55C18F2327968A004F89F2 /* SectionsBuilderTests.swift */,
6B55C19323279A69004F89F2 /* SectionsBuildableTests.swift */,
);
path = FunctionBuilder;
sourceTree = "<group>";
};
6B65947021E252E300291AAF = {
isa = PBXGroup;
children = (
Expand All @@ -162,13 +238,14 @@
isa = PBXGroup;
children = (
6B65949921E2532100291AAF /* Component.swift */,
6B65948621E2532100291AAF /* IdentifiableComponent.swift */,
6B65949A21E2532100291AAF /* AnyComponent.swift */,
6B65949121E2532100291AAF /* ViewNode.swift */,
6B65949821E2532100291AAF /* CellNode.swift */,
6B65948621E2532100291AAF /* IdentifiableComponent.swift */,
6B65949021E2532100291AAF /* Section.swift */,
6B6594A321E2532100291AAF /* Renderer.swift */,
6B5304522201EDB200A3E21E /* DataChangeset.swift */,
6BC83E47231ECE5000350855 /* FunctionBuilder */,
6B4B11B323244AE800D2E7E0 /* ComponentWrapper */,
6B4B11B223244A8500D2E7E0 /* Nodes */,
6B65948921E2532100291AAF /* Adapters */,
6B65949221E2532100291AAF /* Updaters */,
6B65949D21E2532100291AAF /* Interfaces */,
Expand Down Expand Up @@ -245,10 +322,11 @@
6B7ADEB021F783E3003803BE /* ComponentTests.swift */,
6B7ADEC621F9F8F8003803BE /* IdentifiableComponentTests.swift */,
6B7ADEBB21F8B464003803BE /* AnyComponentTests.swift */,
6B7ADEBD21F8BF89003803BE /* ViewNodeTests.swift */,
6B7ADEBF21F8C651003803BE /* CellNodeTests.swift */,
6B7ADEC121F8C976003803BE /* SectionTests.swift */,
6B7ADEC821F9F9A6003803BE /* RendererTests.swift */,
6B55C18A23278F57004F89F2 /* FunctionBuilder */,
6B55C185232789DE004F89F2 /* ComponentWrapper */,
6B55C1842327881A004F89F2 /* Nodes */,
6B7ADECA21FA0662003803BE /* Adapters */,
6B7ADED621FB5953003803BE /* Updater */,
6B7ADEEC21FDB0EA003803BE /* Interfaces */,
Expand Down Expand Up @@ -298,6 +376,18 @@
path = Interfaces;
sourceTree = "<group>";
};
6BC83E47231ECE5000350855 /* FunctionBuilder */ = {
isa = PBXGroup;
children = (
6B4B11AC2322E62A00D2E7E0 /* Group.swift */,
6BC83E4A231ED14600350855 /* CellsBuilder.swift */,
6BC83E4C231ED17300350855 /* CellsBuildable.swift */,
6BC83E50231ED21700350855 /* SectionsBuilder.swift */,
6BC83E52231ED42C00350855 /* SectionsBuildable.swift */,
);
path = FunctionBuilder;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXHeadersBuildPhase section */
Expand Down Expand Up @@ -434,14 +524,21 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6B4B11AD2322E62A00D2E7E0 /* Group.swift in Sources */,
6B37B2F52320339300A80D62 /* IdentifiedComponentWrapper.swift in Sources */,
6B6594BB21E2532100291AAF /* UITableViewComponentHeaderFooterView.swift in Sources */,
6B7EED9E224CA5DD00060872 /* UIScrollViewExtensions.swift in Sources */,
6BC83E53231ED42C00350855 /* SectionsBuildable.swift in Sources */,
6B6594AC21E2532100291AAF /* Section.swift in Sources */,
6BC83E4B231ED14700350855 /* CellsBuilder.swift in Sources */,
6B6594B121E2532100291AAF /* UICollectionViewReloadDataUpdater.swift in Sources */,
6BC83E4D231ED17300350855 /* CellsBuildable.swift in Sources */,
6B6594B421E2532100291AAF /* Component.swift in Sources */,
6B6594B821E2532100291AAF /* UICollectionComponentReusableView.swift in Sources */,
6BAEA43D228D4E920026F81E /* RuntimeAssociation.swift in Sources */,
6BC83E51231ED21700350855 /* SectionsBuilder.swift in Sources */,
6B6594A621E2532100291AAF /* UICollectionViewAdapter.swift in Sources */,
6B37B2F62320339300A80D62 /* ComponentWrapping.swift in Sources */,
6B6594A921E2532100291AAF /* Adapter.swift in Sources */,
6B6594A721E2532100291AAF /* UITableViewAdapter.swift in Sources */,
6B6594AD21E2532100291AAF /* ViewNode.swift in Sources */,
Expand All @@ -465,22 +562,29 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
6B55C1902327968A004F89F2 /* SectionsBuilderTests.swift in Sources */,
6B7ADEC921F9F9A6003803BE /* RendererTests.swift in Sources */,
6B7ADEC721F9F8F8003803BE /* IdentifiableComponentTests.swift in Sources */,
6B55C19423279A69004F89F2 /* SectionsBuildableTests.swift in Sources */,
6B7ADEE121FBA6D1003803BE /* ComponentContainerElementTests.swift in Sources */,
6B7ADEC021F8C651003803BE /* CellNodeTests.swift in Sources */,
6B55C18923278E53004F89F2 /* IdentifiedComponentWrapperTests.swift in Sources */,
6B7ADECE21FA1B32003803BE /* UICollectionViewFlowLayoutAdapterTests.swift in Sources */,
6B7ADEB121F783E3003803BE /* ComponentTests.swift in Sources */,
6B7ADEDE21FBA59D003803BE /* UICollectionViewReloadDataTests.swift in Sources */,
6B7ADEBC21F8B464003803BE /* AnyComponentTests.swift in Sources */,
6B7EEDA0224CE4E100060872 /* UIScrollViewExtensionsTests.swift in Sources */,
6B7ADEBE21F8BF89003803BE /* ViewNodeTests.swift in Sources */,
6B55C187232789FF004F89F2 /* ComponentWrappingTests.swift in Sources */,
6B7ADECC21FA067E003803BE /* UITableViewAdapterTests.swift in Sources */,
6B55C19223279865004F89F2 /* CellsBuildableTests.swift in Sources */,
6B7ADEDA21FB909E003803BE /* UITableViewReloadDataUpdaterTests.swift in Sources */,
6B55C18C23278F6E004F89F2 /* GroupTests.swift in Sources */,
6B7ADEDC21FB91FF003803BE /* UICollectionViewUpdaterTests.swift in Sources */,
6B7ADEBA21F78957003803BE /* TestTools.swift in Sources */,
6B7ADED821FB5976003803BE /* UITableViewUpdaterTests.swift in Sources */,
6B7ADEC221F8C976003803BE /* SectionTests.swift in Sources */,
6B55C18E232791DA004F89F2 /* CellsBuilderTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 94b684c

Please sign in to comment.