Skip to content

Commit

Permalink
Merge branch '2.0.0'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README_CH.md
  • Loading branch information
张行 committed Jul 29, 2019
2 parents ae48278 + 25a625f commit abffc06
Show file tree
Hide file tree
Showing 34 changed files with 982 additions and 285 deletions.
184 changes: 107 additions & 77 deletions README.md
@@ -1,25 +1,35 @@
---
typora-copy-images-to: ../SwiftTableViewGroup/images/
typora-root-url: ../SwiftTableViewGroup
---

# SwiftTableViewGroup

# [🇨🇳(中文)](./README_CH.md)

> ❇️`SwiftTableViewGroup` is the previous one. ZHTableViewGroupSwift` is developed using the syntax of the latest `Swift5.1` `@_functionBuilder` combined with the latest `SwiftUI` design pattern.
> ❇️`SwiftTableViewGroup`is developed using the syntax of the latest Swift5.1``@_functionBuilder` combined with the latest `SwiftUI` design pattern.
>
> ❇️`SwiftTableViewGroup`是利用最新的`Swift.1`语法`@_functionBuilder`符合`SwiftUI`设计的数据驱动。
[TOC]

## ChangeLog(更新记录)

### v2.0.0

## Demo
- Support `UICollectionView` data driver(支持`UICollectionView`数据驱动)
- Changing `Api` is easier to use(更改`Api`使用更简单)
- Support for custom height or size(支持自定义高度或者大小)
- Safer to use(使用更加安全)

![image-20190726143607274](/images/2019-07-26-063607.png)
## Demo(例子)

![image-20190729103132510](/images/image-20190729103132510.png)

![image-20190726143633679](/images/2019-07-26-063634.png)

![image-20190726143714253](/images/image-20190726143714253.png)

![image-20190729103652825](/images//image-20190729103652825.png)

## 安装

### Swift Package Manager(Xcode 11)
Expand All @@ -28,125 +38,137 @@ typora-root-url: ../SwiftTableViewGroup
https://github.com/josercc/SwiftTableViewGroup
```

## Claim
## Claim(要求)

- `Xcode11`
- `Swift5.1`

## How to use
## How to use(怎么使用)

### Code template (not real code)
### UITableView

#### Fake code(伪代码)

```swift
let tableView = UITableView()
var dataSource = TableView(tableView:tableView)
/// setup configuration(初始化配置)
dataSource.setup {
/// Header
/// Add Header
TableViewHeaderFooterView
/// Cell
/// Add Cell
TableViewCell
/// Footer
/// Add More Cell
...
/// Add Footer
TableViewHeaderFooterView
}
/// Perform registration and refresh(执行注册和刷新)
dataSource.reloadData
```

### Create a static text list)
#### Create a static text list(创建一个简单的列表)

```swift
let source:[String] = [
"Normal list text",
"Complex setup interface",
]
func steupTableView() {
self.dataSource.setup {
/// Create a TableViewCell with a default type of UITableViewCell
TableCell { (tableCell, blockType, cell, index) in
/// Calling Config and DidSlectRow callbacks without executing this method
tableCell.makeContentBlock(type: blockType,
cell: cell,
index: index,
configContent: CellBlockContent<UITableViewCell> {(cell,index) in
cell.textLabel?.text = source[index]
cell.accessoryType = .disclosureIndicator
},
didSelectRowContent: self.didSelectRowContent())
}

.number(source.count) /// Set the number of cells
.height(45)
}
self.dataSource.reloadData()
TableCell { content, contentCell in
/// Create a configured block(创建配置的 Block)
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = self.source[index]
cell.accessoryType = .disclosureIndicator
}
///The callbacks for config and didSelectRow can be raised separately to prevent the code from being messy
func didSelectRowContent() -> CellBlockContent<UITableViewCell> {
/// The generic type of CellBlockContent must match the type of the created declaration. Otherwise, the callback cannot be completed.
CellBlockContent<UITableViewCell> {(cell,index) in
}
/// Create a clickback call block(创建点击回调 Block)
content.didSelectRow(UITableViewCell.self) { (cell, index) in
}
}
.number(self.source.count)
.height(45)
}
self.dataSource.reloadData()
```

![image-20190726143607274](/images/2019-07-26-063607.png)

### Create complex interfaces
#### Create complex TableView(创建复杂的表格)

```swift
var settingDataSource = TableView(tableView: tableView)
let settingDataSource = TableView(tableView: tableView)
settingDataSource.setup {
/// Create a Header
TableHeaderFooterView(SettingHeaderView.self, .header,{ (tableHeader, header, section) in
tableHeader.makeContentBlock(headerFooter: header, section: section, configContent: HeaderFooterBlockContent<SettingHeaderView> {(header,section) in
header.textLabel?.text = "Header"
})
/// Create `SettingHeaderView` Header(创建自定义`SettingHeaderView`Header)
TableHeaderView(SettingHeaderView.self, { content,contentHeader in
content.configuration(SettingHeaderView.self) { (view, section) in
view.textLabel?.text = "Header"
}
})
.height(49)
/// Create a custom UITableViewCell automatic height
/// Create `IntrinsicContentTextLabelCell` Cell(创建`IntrinsicContentTextLabelCell`Cell)
TableCell(IntrinsicContentTextLabelCell.self)
/// Create a default UITableViewCell dynamic change quantity
TableCell { (tableCell, blockType, cell, index) in
tableCell.makeContentBlock(type: blockType, cell: cell, index: index, configContent: CellBlockContent<UITableViewCell> {(cell,index) in
/// Create Dynamic change number Cell(创建动态更改数量的 Cell)
TableCell { content,contentCell in
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = "\(index) 点击我会增加哦"
}, didSelectRowContent: CellBlockContent<UITableViewCell> {(cell,index) in
let number = tableCell.number + 1
tableCell.number(number)
settingDataSource.reloadData()
})
}
content.didSelectRow(UITableViewCell.self) { (cell, index) in
let number = contentCell.number + 1;
contentCell.number(number)
settingDataSource.reloadData()
}
}
/// Create a default UITableViewCell dynamic change height
TableCell { (tableCell, blockType, cell, index) in
tableCell.makeContentBlock(type: blockType,
cell: cell,
index: index,
configContent: CellBlockContent<UITableViewCell> {(cell,index) in
cell.textLabel?.text = "点击我改变高度"
},
didSelectRowContent: CellBlockContent<UITableViewCell> {(cell,index) in
let height = tableCell.height == 44 ? 100 : 44;
tableCell.height(CGFloat(height))
settingDataSource.reloadData()
})
.height(44)
/// Create Dynamic change height Cell)(创建动态更改高度的 Cell)
TableCell { content,contentCell in
content.configuration(UITableViewCell.self) { (cell, index) in
cell.textLabel?.text = "点击我改变高度"
}
content.didSelectRow(UITableViewCell.self) { (cell, index) in
let height = contentCell.height == 44 ? 100 : 44;
contentCell.height(CGFloat(height))
settingDataSource.reloadData()
}
}
.height(44)
}
```

![image-20190726143714253](/images/image-20190726143714253.png)

#### Dynamic change quantity
##### Dynamic change quantity(动态更改数量)

![image-20190726145544399](/images/image-20190726145544399.png)

#### Dynamic height
##### Dynamic height(动态修改高度)

![image-20190726145605726](/images/image-20190726145605726.png)

### UICollectionView

```swift
self.dataSource.setup {
/// Create normal class `UICollectionViewCell` cell(创建默认为`UITableViewCell`类的 Cell)
CollectionCell { content, cellContent in
content.configuration(UICollectionViewCell.self) { (cell, index) in
cell.backgroundColor = index % 2 == 0 ? UIColor.red : UIColor.blue
}
content.didSelectRow(UICollectionViewCell.self) { (cell, index) in
cell.backgroundColor = cell.backgroundColor == UIColor.red ? UIColor.blue : UIColor.red
}
}
.number(20)
.size(CGSize(width: 100, height: 200))

}
.inset(UIEdgeInsets(top: 20, left: 10, bottom: 20, right: 10))
self.dataSource.reloadData()
```

![image-20190729105419637](/images//image-20190729105419637.png)

## Problem

### ❓How to dynamically insert or delete some elements
### ❓How to dynamically insert or delete some elements(怎么动态的插入或者删除一组元素)

> You can change the element properties of the opposite side of the TableView's Sections array and then call `reloadData`.
> You can change the element properties of the opposite side of the TableView's Sections array and then call `reloadData`.(您可以更改TableView的Sections数组的另一侧的元素属性,然后调用`reloadData`。)
### ❓How to listen to other agents of `UIScrollView`
### ❓How to listen to other agents of `UIScrollView`(怎么监听`UIScrollView`其他代理方法)

```swift
public struct ScrollViewDelegate {
Expand All @@ -160,7 +182,7 @@ public struct ScrollViewDelegate {

```

> Can implement the above proxy method of `UITableView`
> Can implement the above proxy method of `UITableView`(可以实现`UITableView的上述代理方法)
Example

Expand All @@ -169,9 +191,17 @@ tableView.scrollDelegate?.scrollViewDidScroll = { scrollView in
}
```

### I feel that there are too few supported features.
### I feel that there are too few supported features.(我觉得支持的功能太少了。)

> Can submit PR or commit ISSUSE(可以提交PR或提ISSUSE)
## Api Document(Api 文档)

> Can submit PR or mention ISSUSE
- Height or size setting priority (高度或者大小的设置优先级)
- height( UITableViewCell/UITableHeaderFooterView)(高度( UITableViewCell/UITableHeaderFooterView))
- custom > setting > auto(sizeToFit)(自定义 > 设置 > 自动获取(sizeToFit))
- size(UICollectionViewCell/UICollectionReusableView)(大小(UICollectionViewCell/UICollectionReusableView))
- custom > setting > FlowLayout(自定义 > 设置 > FlowLayout)

## contact me

Expand Down
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDEDidComputeMac32BitWarning</key>
<true/>
</dict>
</plist>
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<array/>
</plist>
Binary file not shown.
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Bucket
uuid = "6B5E2258-7ED1-49E5-BC6A-D0CEC200B9F7"
type = "0"
version = "2.0">
</Bucket>
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SwiftTableViewGroup.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>1</integer>
</dict>
</dict>
</dict>
</plist>

0 comments on commit abffc06

Please sign in to comment.