From 2f89c0cafc1ccca417134c105367b71beb8f6c63 Mon Sep 17 00:00:00 2001 From: Meng Li Date: Mon, 5 Aug 2019 11:37:59 +0900 Subject: [PATCH] Update podspec and README. --- Example/Podfile.lock | 4 ++-- README.md | 11 +++++++--- RxController.podspec | 2 +- document/chapter6-cell.md | 42 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/Example/Podfile.lock b/Example/Podfile.lock index 27d78f1..6455696 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -12,7 +12,7 @@ PODS: - RxCocoa (5.0.0): - RxRelay (~> 5) - RxSwift (~> 5) - - RxController (0.7.3): + - RxController (0.7.4): - RxCocoa (~> 5) - RxFlow (~> 2) - RxSwift (~> 5) @@ -64,7 +64,7 @@ SPEC CHECKSUMS: Reusable: 82be188f29d96dc5eff0db7b2393bcc08d2cdd5b RxBinding: 58be2cf1311165489a66eacb4a3e33932d598a53 RxCocoa: fcf32050ac00d801f34a7f71d5e8e7f23026dcd8 - RxController: b488ac97a465e30d127e6451e8e7d93429b72f44 + RxController: bd7fb19277fed720e394cd30708c1f5bc9a24db9 RxDataSources: efee07fa4de48477eca0a4611e6d11e2da9c1114 RxDataSourcesSingleSection: 42ee6900e6c069ce2d0bb9a1cd81308dce772d28 RxFlow: ee6f1fdbacfa4ca8926122e466dfba32e3edf73f diff --git a/README.md b/README.md index d804579..67504c5 100644 --- a/README.md +++ b/README.md @@ -155,12 +155,17 @@ var name: Observable { ``` Pay attention to that **subscribing the `RxControllerEvent` in the `init` method of the view model is not effective**. -It necessary to subscribe the `RxControllerEvent` in the `prepareForParentEvents` methods like: +It necessary to subscribe or bind the `RxControllerEvent` in the `prepareForParentEvents` methods. ```Swift override func prepareForParentEvents() { - parentEvents.unwrappedValue(of: Event.sample, type: EventData.self) - .bind(to: data).disposed(by: disposeBag) + // Subscribe an event. + parentEvents.unwrappedValue(of: Event.sample, type: EventData.self).subscribe(onNext: { + // ... + }.disposed(by: disposeBag)) + + // Bind an event to a relay directly. + parentEvents.bind(of: Event.sample, to: data).disposed(by: disposeBag) } ``` diff --git a/RxController.podspec b/RxController.podspec index eabac79..531fdcc 100644 --- a/RxController.podspec +++ b/RxController.podspec @@ -8,7 +8,7 @@ Pod::Spec.new do |s| s.name = 'RxController' - s.version = '0.7.3' + s.version = '0.7.4' s.summary = 'A library for developing with MVVM-C based on RxFlow and RxSwift.' # This description is used to generate tags and improve search results. diff --git a/document/chapter6-cell.md b/document/chapter6-cell.md index 7c803c4..ee0b184 100644 --- a/document/chapter6-cell.md +++ b/document/chapter6-cell.md @@ -77,6 +77,18 @@ extension PersonTableViewCell: Configurable { ## 6.3 Table view cell height Calculating cell height is a troublesome problem for the table view cell. +If the cell height is dynamical, using autolayout using SnapKit in the cell and automatic row height in the table view is recommended. + +```swift +private lazy var tableView: UITableView = { + let tableView = UITableView() + tableView.rowHeight = UITableView.automaticDimension + tableView.register(cellType: DemoTableViewCell.self) + return tableView +}() +``` + +In the cell class, the autolayout rule is different with which in the view controller or the customized view. ## 6.4 Tap action @@ -114,7 +126,7 @@ func pick(at index: Int) { Sometimes, a single cell may contains multiple tap action for multiple customized buttons. In the view controller, the reactive extension is recommended in the definition closure of the customized buttons. However, for the reusable cells, managing the `disposeBag` and avoiding the multiple tap action binding are troublesome. -As we said in the top of this chapter, we use the pure MVC design pattern for reusable cells. +As we said in the top of this chapter, **the pure MVC design pattern is recommended for handling events of reusable cells.** Here, we define the customized button and add tap action with `addTarget` method directly. ```swift @@ -126,3 +138,31 @@ private lazy var favoriteButton: UIButton = { return button }() ``` + +When the button is tapped, the objc method will be invoked. + +```swift +@objc +private func favoriteTapped() { + didFavoriteTapped?() +} +``` +In this private method, an optional closure is invoked. +This clousre is defined as an internal optional property. + +```swift +var didFavoriteTapped: (() -> Void)? +``` + +The tapped closure should be setted in the dataSource of the tableView. + +```swift +private lazy var dataSource = FavoriteTableViewCell.tableViewSingleSectionDataSource(configureCell: { [unowned self] cell, indexPath, _ in + cell.didFavoriteTapped = { + self.viewModel.pick(at: indexPath.row) + } +}) +``` + +At last, a method in the view model will be invoked. +This method is responsible for handling the specific business logic. \ No newline at end of file