More polishing.

This commit is contained in:
Krunoslav Zaher 2015-07-05 13:29:51 +02:00
parent 327f82355e
commit dc262916ec
10 changed files with 60 additions and 46 deletions

View File

@ -89,6 +89,10 @@ public class DelegateProxy : _RXDelegateProxy {
return self._forwardToDelegate
}
public func dispose() {
objc_setAssociatedObject(parentObject, self.classForCoder.delegateAssociatedObjectTag(), nil, UInt(OBJC_ASSOCIATION_RETAIN))
}
deinit {
#if TRACE_RESOURCES
OSAtomicDecrement32(&resourceCount)

View File

@ -106,7 +106,7 @@ static NSMutableDictionary *forwardableSelectorsPerClass = nil;
forwardableSelectorsPerClass = [[NSMutableDictionary alloc] init];
}
NSLog(@"Class: %@", NSStringFromClass(self));
// NSLog(@"Class: %@", NSStringFromClass(self));
NSMutableSet *allowedSelectors = [NSMutableSet set];
@ -122,7 +122,7 @@ static NSMutableDictionary *forwardableSelectorsPerClass = nil;
for (unsigned int j = 0; j < protocolMethodCount; ++j) {
struct objc_method_description method = methods[j];
if (RX_is_method_with_description_void(method)) {
NSLog(@"Allowed selector: %@", NSStringFromSelector(method.name));
// NSLog(@"Allowed selector: %@", NSStringFromSelector(method.name));
[allowedSelectors addObject:SEL_VALUE(method.name)];
}
}

View File

@ -23,7 +23,7 @@ class RxTableViewDelegateProxy : RxScrollViewDelegateProxy
typealias ItemSelectedObserver = ObserverOf<NSIndexPath>
typealias ItemSelectedDisposeKey = Bag<ItemSelectedObserver>.KeyType
let tableView: UITableView
unowned let tableView: UITableView
var itemSelectedObservers: Bag<ItemSelectedObserver> = Bag()

View File

@ -10,7 +10,6 @@ import Foundation
import RxSwift
import UIKit
// This is the most simple (but probably most common) way of using rx with UICollectionView.
extension UICollectionView {
// factories

View File

@ -24,13 +24,14 @@ class RxCollectionViewSectionedAnimatedDataSource<S: SectionModelType> : RxColle
case .Next(let boxedSections):
for c in boxedSections.value {
//println("Animating ==============================\n\(c)\n===============================\n")
setSections(c.finalSections)
if !set {
setSections(c.finalSections)
collectionView.reloadData()
set = true
return
}
setSections(c.finalSections)
collectionView.performBatchUpdates(c)
}
case .Error(let error):

View File

@ -66,10 +66,16 @@ func indexSections<S: SectionModelType where S: Hashable, S.Item: Hashable>(sect
}
func indexSectionItems<S: SectionModelType where S: Hashable, S.Item: Hashable>(sections: [S]) -> [S.Item : (Int, Int)] {
var indexedItems: [S.Item : (Int, Int)] = [:]
var totalItems = 0
for i in 0 ..< sections.count {
totalItems += sections[i].items.count
}
for (i, section) in enumerate(sections) {
for (j, item) in enumerate(section.items) {
// let's make sure it's enough
var indexedItems: [S.Item : (Int, Int)] = Dictionary(minimumCapacity: totalItems * 3)
for i in 0 ..< sections.count {
for (j, item) in enumerate(sections[i].items) {
precondition(indexedItems[item] == nil, "Item \(item) has already been indexed at \(indexedItems[item]!)" )
indexedItems[item] = (i, j)
}
@ -252,6 +258,8 @@ func differentiate<S: SectionModelType where S: Hashable, S.Item: Hashable>(
}
}
deletes.deletedSections = deletes.deletedSections.reverse()
// }
var untouchedOldIndex: Int? = 0
@ -329,6 +337,8 @@ func differentiate<S: SectionModelType where S: Hashable, S.Item: Hashable>(
}
// }
deletes.deletedItems = deletes.deletedItems.reverse()
// mark new and moved items {
// 3rd stage
for (i, finalSection) in enumerate(finalSections) {

View File

@ -20,6 +20,8 @@ class PartialUpdatesViewController : ViewController {
var moc: NSManagedObjectContext!
var child: NSManagedObjectContext!
var timer: NSTimer? = nil
static let initialValue: [HashableSectionModel<String, Int>] = [
NumberSection(model: "section 1", items: [1, 2, 3]),
NumberSection(model: "section 2", items: [4, 5, 6]),
@ -78,6 +80,31 @@ class PartialUpdatesViewController : ViewController {
override func viewDidLoad() {
super.viewDidLoad()
let generateCustomSize = true
let runAutomatically = false
// For UICollectionView, if another animation starts before previous one is finished, it will sometimes crash :(
// It's not deterministic (because Randomizer generates deterministic updates), and if you click fast
// It sometimes will and sometimes wont crash, depending on tapping speed.
// I guess you can maybe try some tricks with timeout, hard to tell :( That's on Apple side.
if generateCustomSize {
let nSections = 10
let nItems = 100
var sections = [HashableSectionModel<String, Int>]()
for i in 0 ..< nSections {
sections.append(HashableSectionModel(model: "Section \(i + 1)", items: Array(i * nItems ..< (i + 1) * nItems)))
}
generator = Randomizer(rng: PseudoRandomGenerator(4, 3), sections: sections)
}
if runAutomatically {
timer = NSTimer.scheduledTimerWithTimeInterval(0.6, target: self, selector: "randomize", userInfo: nil, repeats: true)
}
self.sections.next(generator.sections)
let tvAnimatedDataSource = RxTableViewSectionedAnimatedDataSource<NumberSection>()
@ -111,6 +138,11 @@ class PartialUpdatesViewController : ViewController {
updates
>- partialUpdatesCollectionViewOutlet.rx_subscribeWithReactiveDataSource(cvAnimatedDataSource)
>- disposeBag.addDisposable
}
override func viewWillDisappear(animated: Bool) {
self.timer?.invalidate()
}
@IBAction func randomize() {
@ -122,6 +154,8 @@ class PartialUpdatesViewController : ViewController {
values = PartialUpdatesViewController.firstChange!
}
//println(values)
sections.next(values)
}
}

View File

@ -15,8 +15,6 @@ class WikipediaSearchViewController: ViewController {
private var disposeBag = DisposeBag()
private var viewModel: SearchViewModel? = nil
@IBOutlet weak var tv: UITableView?
override func awakeFromNib() {
super.awakeFromNib()
}
@ -26,11 +24,11 @@ class WikipediaSearchViewController: ViewController {
override func viewDidLoad() {
super.viewDidLoad()
let resultsTableView = self.searchDisplayController!.searchResultsTableView
let searchBar = self.searchDisplayController!.searchBar
resultsTableView.registerNib(UINib(nibName: "WikipediaSearchCell", bundle: nil), forCellReuseIdentifier: "WikipediaSearchCell")
tv!.registerNib(UINib(nibName: "WikipediaSearchCell", bundle: nil), forCellReuseIdentifier: "WikipediaSearchCell")
resultsTableView.rowHeight = 194
@ -41,28 +39,6 @@ class WikipediaSearchViewController: ViewController {
selectedResult: selectedResult
)
/*let sectionedDs = RxTableViewSectionedReloadDataSource<SectionModel<String, WikipediaSearchResult>>()
sectionedDs.cellFactory = { (tv, ip, viewModel) in
let cell = tv.dequeueReusableCellWithIdentifier("WikipediaSearchCell", forIndexPath: ip) as! WikipediaSearchCell
//cell.viewModel = viewModel
return cell
}
let results: Observable<[SectionModel<String, WikipediaSearchResult>]> = just([])
results
>- tv!.rx_subscribeWithReactiveDataSource(sectionedDs)
>- disposeBag.addDisposable
results
>- tv.rx_subscribeItemsToWithCellIdentifier("WikipediaSearchCell") { (_, viewModel, cell: WikipediaSearchCell) in
cell.viewModel = viewModel
}
>- disposeBag.addDisposable
*/
// map table view rows
// {
viewModel.rows
@ -87,5 +63,4 @@ class WikipediaSearchViewController: ViewController {
self.viewModel = viewModel
// }
}
}

View File

@ -484,30 +484,21 @@ This is only showcase app, not intended for production purposes.</string>
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
<nil key="highlightedColor"/>
</label>
<tableView clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="prototypes" style="plain" separatorStyle="default" rowHeight="44" sectionHeaderHeight="22" sectionFooterHeight="22" translatesAutoresizingMaskIntoConstraints="NO" id="TKD-6V-72I">
<rect key="frame" x="29" y="201" width="254" height="340"/>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
</tableView>
</subviews>
<color key="backgroundColor" white="1" alpha="1" colorSpace="calibratedWhite"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="q4t-TG-WEX" secondAttribute="trailing" constant="-16" id="9Bk-YV-Ndt"/>
<constraint firstItem="q4t-TG-WEX" firstAttribute="leading" secondItem="rhi-Gj-NG4" secondAttribute="leadingMargin" constant="-16" id="IIN-VP-EdF"/>
<constraint firstItem="qRP-g3-i5K" firstAttribute="top" secondItem="TKD-6V-72I" secondAttribute="bottom" constant="27" id="LMY-eV-QRF"/>
<constraint firstItem="FeZ-zt-ZeK" firstAttribute="leading" secondItem="rhi-Gj-NG4" secondAttribute="leadingMargin" constant="13" id="MSu-fp-qv1"/>
<constraint firstAttribute="trailingMargin" secondItem="TKD-6V-72I" secondAttribute="trailing" constant="21" id="Nq9-33-tL6"/>
<constraint firstAttribute="centerX" secondItem="FeZ-zt-ZeK" secondAttribute="centerX" constant="-0.5" id="UXX-0S-lap"/>
<constraint firstAttribute="trailingMargin" secondItem="FeZ-zt-ZeK" secondAttribute="trailing" constant="12" id="ahS-rn-Gm5"/>
<constraint firstItem="TKD-6V-72I" firstAttribute="top" secondItem="q4t-TG-WEX" secondAttribute="bottom" constant="93" id="bDD-vT-mV4"/>
<constraint firstItem="q4t-TG-WEX" firstAttribute="top" secondItem="5dr-42-uib" secondAttribute="bottom" id="cYt-41-Gst"/>
<constraint firstAttribute="centerY" secondItem="FeZ-zt-ZeK" secondAttribute="centerY" multiplier="1.2" id="d4B-SW-gN2"/>
<constraint firstItem="TKD-6V-72I" firstAttribute="leading" secondItem="rhi-Gj-NG4" secondAttribute="leadingMargin" constant="13" id="oF7-X9-Vcx"/>
</constraints>
</view>
<navigationItem key="navigationItem" title="Search Wikipedia" id="QNG-ow-NDA"/>
<connections>
<outlet property="searchDisplayController" destination="4OD-HT-2f1" id="hGe-qe-2O9"/>
<outlet property="tv" destination="TKD-6V-72I" id="oaa-cF-0UX"/>
</connections>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="mQm-27-dBN" userLabel="First Responder" sceneMemberID="firstResponder"/>