Skip to content

Commit

Permalink
fix for ui blocking on text entry. BEWARE - you'll need to wrap your …
Browse files Browse the repository at this point in the history
…ui updates on main thread. eg

        dispatch_async(dispatch_get_main_queue()) {
		}
  • Loading branch information
johndpope committed May 3, 2016
1 parent e853480 commit bdc6190
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
32 changes: 19 additions & 13 deletions RAMReel/Framework/CollectionViewWrapper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -170,24 +170,30 @@ public class CollectionViewWrapper
// MARK: Update & Adjust

func updateOffset(notification: NSNotification? = nil) {
collectionView.reloadData()
collectionView.layoutIfNeeded()

let durationNumber = notification?.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber
let duration = durationNumber?.doubleValue ?? 0.1

UIView.animateWithDuration(duration) {
let number = self.collectionView.numberOfItemsInSection(0)
let itemIndex = self.scrollDelegate.itemIndex ?? number/2
dispatch_async(dispatch_get_main_queue()) {
self.collectionView.reloadData()
self.collectionView.layoutIfNeeded()
let durationNumber = notification?.userInfo?[UIKeyboardAnimationDurationUserInfoKey] as? NSNumber
let duration = durationNumber?.doubleValue ?? 0.1

if itemIndex > 0 {
let inset = self.collectionView.contentInset.top
let itemHeight = self.collectionLayout.itemHeight
let offset = CGPoint(x: 0, y: CGFloat(itemIndex) * itemHeight - inset)
UIView.animateWithDuration(duration) {
let number = self.collectionView.numberOfItemsInSection(0)
let itemIndex = self.scrollDelegate.itemIndex ?? number/2

self.collectionView.contentOffset = offset
if itemIndex > 0 {
let inset = self.collectionView.contentInset.top
let itemHeight = self.collectionLayout.itemHeight
let offset = CGPoint(x: 0, y: CGFloat(itemIndex) * itemHeight - inset)

self.collectionView.contentOffset = offset
}
}
}



}

func adjustScroll(notification: NSNotification? = nil) {
Expand Down
4 changes: 3 additions & 1 deletion RAMReel/Framework/TextFieldReactor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ public struct TextFieldReactor

self.editingTarget = TextFieldTarget(controlEvents: UIControlEvents.EditingChanged, textField: textField) {
if let text = $0.text {
dataFlow.transport(text)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0)) {
dataFlow.transport(text)
}
}
}
}
Expand Down

0 comments on commit bdc6190

Please sign in to comment.