Skip to content

Commit bacf109

Browse files
author
son.le
committed
Push project
1 parent 5246ca5 commit bacf109

File tree

26 files changed

+2334
-0
lines changed

26 files changed

+2334
-0
lines changed

Assets/SwiftUIKit.png

20.8 KB
Loading

Assets/demo.jpeg

182 KB
Loading

Assets/rxswiftuikit_banner.png

83.7 KB
Loading

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 misshypocrite
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Podfile

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
platform :ios, '11.0'
2+
use_frameworks!
3+
4+
workspace 'RxSwiftUIKit.xcworkspace'
5+
6+
def dependencyPod
7+
pod 'Carbon', '1.0.0-rc.6'
8+
pod 'RxSwift'
9+
pod 'RxCocoa'
10+
pod 'SwiftUIKit_pro', '1.0.0'
11+
end
12+
13+
14+
target 'RxSwiftUIKit' do
15+
16+
project 'RxSwiftUIKit'
17+
18+
dependencyPod
19+
20+
end
21+
22+
target 'RxSwiftUIKit-Example' do
23+
24+
project 'RxSwiftUIKit-Example/RxSwiftUIKit-Example'
25+
26+
dependencyPod
27+
28+
end
29+

Podfile.lock

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
PODS:
2+
- Carbon (1.0.0-rc.6):
3+
- DifferenceKit/Core (~> 1.1)
4+
- DifferenceKit/Core (1.2.0)
5+
- RxCocoa (6.1.0):
6+
- RxRelay (= 6.1.0)
7+
- RxSwift (= 6.1.0)
8+
- RxRelay (6.1.0):
9+
- RxSwift (= 6.1.0)
10+
- RxSwift (6.1.0)
11+
- SwiftUIKit_pro (1.0.0):
12+
- SwiftUIKit_pro/Core (= 1.0.0)
13+
- SwiftUIKit_pro/Core (1.0.0)
14+
15+
DEPENDENCIES:
16+
- Carbon (= 1.0.0-rc.6)
17+
- RxCocoa
18+
- RxSwift
19+
- SwiftUIKit_pro (= 1.0.0)
20+
21+
SPEC REPOS:
22+
trunk:
23+
- Carbon
24+
- DifferenceKit
25+
- RxCocoa
26+
- RxRelay
27+
- RxSwift
28+
- SwiftUIKit_pro
29+
30+
SPEC CHECKSUMS:
31+
Carbon: 84c3402754e682960ef85dd20a2fe44c723701d2
32+
DifferenceKit: 5659c430bb7fe45876fa32ce5cba5d6167f0c805
33+
RxCocoa: 5c51f02d562cbd94629f6c26cf0c80fe4ab8d343
34+
RxRelay: 483e1a19fad961b41f0b0c0bee506f46c1ae14fe
35+
RxSwift: a834e5c538e89eca0cae86f403f4fbf0336786ce
36+
SwiftUIKit_pro: b3bcc6888f7840db0d53f0881e367401603d1290
37+
38+
PODFILE CHECKSUM: 7a8482d6455c2f0f65ea7543835f0ffe00e66e9c
39+
40+
COCOAPODS: 1.10.1

README.md

+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
![SwiftUIKit](./Assets/rxswiftuikit_banner.png)
2+
3+
<br/>
4+
5+
[![iOS version support](https://img.shields.io/badge/platform-iOS%2011.0+-8EBEA4)](#Required)
6+
[![latest release](https://img.shields.io/badge/pod-1.0-C9D9D6)](#Development%20Progress)
7+
[![test](https://img.shields.io/badge/test-TODO-FFD6B2)](#Development%20Progress)
8+
9+
# RxSwiftUIKit
10+
11+
**RxSwiftUIKit** is an extension of [SwiftUIKit](https://github.com/sonla58/SwiftUIKit). Combine with [RxSwift](https://github.com/ReactiveX/RxSwift) and [Carbon](https://github.com/ra1028/Carbon), tt gives us the ability to build the tableView or collectionView using the declarative way.
12+
13+
<img src="Assets/demo.jpeg" align="right" width="300px" hspace="10px" vspace="0px">
14+
15+
```swift
16+
ListView(style: .plain, reloadTriggers: [self.items.map { _ in Void() }]) {
17+
InstanceComponent(identifier: 0) { (_) in
18+
ZStackView {
19+
UILabel()
20+
.dx.text("This screen was build by `InstanceComponent` in `ListView`. Check `ViewController` class for more infomation.")
21+
.dx.font(UIFont.systemFont(ofSize: 14, weight: .regular))
22+
.dx.numberOfLines(0)
23+
.dx.textAlignment(NSTextAlignment.center)
24+
.stickingToParentEdges(left: 16, right: 16, top: 14, bottom: 14)
25+
}
26+
.dx.style(SimpleCard())
27+
.fillingParent(insets: (22, 22, 14, 14))
28+
}
29+
30+
Group(of: self.items.value) { (item: Item) in
31+
InstanceComponent(identifier: item.0) { (i) in
32+
ZStackView {
33+
UILabel()
34+
.dx.text(i)
35+
.stickingToParentEdges(left: 20, right: .greaterThanOrEqualTo(20), top: 12, bottom: 12)
36+
UIButton()
37+
.dx.useRx(withUnretained: self, disposeBag: self.disposeBag, reactiveBlock: { (owner, base: UIButton) in
38+
base.rx.tap
39+
.bind { (_) in
40+
item.1()
41+
}
42+
})
43+
.fillingParent()
44+
}
45+
.fillingParent()
46+
}
47+
}
48+
}
49+
```
50+
51+
# Requirement
52+
53+
- iOS 11+
54+
- XCode 11+
55+
- Swift 5.3+
56+
57+
# Installation
58+
59+
## CocoaPods
60+
61+
Add following line to your project's Podfile
62+
```ruby
63+
pod 'RxSwiftUIKit', '1.0.0'
64+
```
65+
Run `pod install` to install SwiftUIKit
66+
67+
## Source Code
68+
69+
Drop all files in folder `./RxSwiftUIKit/Source` to your project or download this repo and drag `RxSwiftUIKit.xcodeproj` to your project with necessary files then link your app with `SwiftUIKit` framework munualy
70+
71+
# Usage
72+
73+
## Layout
74+
75+
To build layout with Declarative way using LayoutBuilder, read [SwiftUIKit](https://github.com/sonla58/SwiftUIKit)
76+
77+
## Component
78+
79+
**Component** is a unit of the UI in [Carbon](https://github.com/ra1028/Carbon) to build UITableView or UICollectionView. Please read more document of Carbon here: [Carbon Document]([Carbon](https://github.com/ra1028/Carbon))
80+
81+
Build Component
82+
83+
```swift
84+
struct BasicComponemt: Component {
85+
let title: String
86+
let onTap: () -> Void
87+
88+
func renderContent() -> BasicView {
89+
BasicView()
90+
}
91+
92+
func render(in content: BasicView) {
93+
content.title = title
94+
content.onTap = onTap
95+
}
96+
}
97+
98+
class BasicView: UI.View {
99+
100+
let title: String
101+
let onTap: () -> Void = { }
102+
103+
override var subviewsLayout: SomeView {
104+
ZStackView {
105+
UILabel()
106+
.dx.text(title)
107+
.stickingToParentEdges(left: 20, right: .greaterThanOrEqualTo(20), top: 12, bottom: 12)
108+
UIButton()
109+
.dx.useRx(withUnretained: self,
110+
disposeBag: self.disposeBag,
111+
reactiveBlock: { (owner, base: UIButton) in
112+
base.rx.tap
113+
.bind { (_) in
114+
owner.onTap()
115+
}
116+
})
117+
.fillingParent()
118+
}
119+
.fillingParent()
120+
}
121+
}
122+
```
123+
124+
or you can use `InstanceComponent` to build basic component with LayoutBuilder
125+
126+
```swift
127+
InstanceComponent(identifier: id) { (id) in
128+
ZStackView {
129+
UILabel()
130+
.dx.text(id)
131+
.stickingToParentEdges(left: 20, right: .greaterThanOrEqualTo(20), top: 12, bottom: 12)
132+
UIButton()
133+
.dx.useRx(withUnretained: self,
134+
disposeBag: self.disposeBag,
135+
reactiveBlock: { (owner, base: UIButton) in
136+
base.rx.tap
137+
.bind { (_) in
138+
print(id)
139+
}
140+
})
141+
.fillingParent()
142+
}
143+
.fillingParent()
144+
}
145+
```
146+
147+
## ListView
148+
149+
```swift
150+
let list = BehaviorRelay<[String]>(value: [
151+
"Bún Đậu",
152+
"Phở",
153+
"Mắm tôm"
154+
])
155+
156+
ListView(style: .plain, reloadTriggers: [self.list.map { _ in Void() }]) {
157+
Group(list) { item in
158+
BasicComponent(title: item) {
159+
print(item)
160+
}
161+
}
162+
}
163+
.fillingParent()
164+
```
165+
166+
`reloadTriggers` is an array of `Observable<Void>`, when one of triggers receive `next` event, listView will be reload data automatically.
167+
168+
## GridView
169+
170+
```swift
171+
let list = BehaviorRelay<[String]>(value: [
172+
"Bún Đậu",
173+
"Phở",
174+
"Mắm tôm"
175+
])
176+
177+
GridView(reloadTriggers: [self.list.map { _ in Void() }]) {
178+
Group(list) { item in
179+
BasicComponent(title: item) {
180+
print(item)
181+
}
182+
}
183+
}
184+
.fillingParent()
185+
```
186+
187+
This is a basic example of usage GridView with default layout: `UICollectionViewFlowLayout` and default `Renderer`. Read Complex example in [Carbon](https://github.com/ra1028/Carbon)

0 commit comments

Comments
 (0)