Merge pull request #208 from TouchInstinct/fix/tableViewInsetBinding
Table view content offset when keyboard appears fixed
This commit is contained in:
commit
4ca23cf3d0
|
|
@ -1,5 +1,8 @@
|
|||
# Changelog
|
||||
|
||||
### 0.9.20
|
||||
- **Fix**: `bindBottomInsetBinding(from bottomInsetDriver:)` in `BaseScrollContentController` works correctly now.
|
||||
|
||||
### 0.9.19
|
||||
- **Add**: `hexString` property for `UIColor` that returns hex representation of color as string.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
Pod::Spec.new do |s|
|
||||
s.name = "LeadKit"
|
||||
s.version = "0.9.19"
|
||||
s.version = "0.9.20"
|
||||
s.summary = "iOS framework with a bunch of tools for rapid development"
|
||||
s.homepage = "https://github.com/TouchInstinct/LeadKit"
|
||||
s.license = "Apache License, Version 2.0"
|
||||
|
|
|
|||
|
|
@ -29,19 +29,17 @@ public typealias ScrollViewHolderView = UIView & ScrollViewHolder
|
|||
open class BaseScrollContentController<ViewModel, View: ScrollViewHolderView>: BaseCustomViewController<ViewModel, View> {
|
||||
|
||||
private var bottomInsetDisposable: Disposable?
|
||||
private let defaultInsetsRelay = BehaviorRelay<UIEdgeInsets>(value: .zero)
|
||||
|
||||
/// Bind given driver to bottom inset of scroll view. Takes into account default bottom insets.
|
||||
///
|
||||
/// - Parameter bottomInsetDriver: Driver that emits CGFloat bottom inset changes.
|
||||
public func bindBottomInsetBinding(from bottomInsetDriver: Driver<CGFloat>) {
|
||||
let contentInsetObservable = customView.scrollView.rx
|
||||
.observe(UIEdgeInsets.self, #keyPath(UIScrollView.contentInset))
|
||||
|
||||
let bottomInset = contentInsetObservable.map { $0?.bottom ?? 0 }
|
||||
|
||||
bottomInsetDisposable = bottomInsetDriver.asObservable()
|
||||
.withLatestFrom(bottomInset) { $0 + $1 }
|
||||
.bind(to: customView.scrollView.rx.bottomInsetBinder)
|
||||
bottomInsetDisposable = bottomInsetDriver
|
||||
.withLatestFrom(defaultInsetsRelay.asDriver()) {
|
||||
$0 + $1.bottom
|
||||
}
|
||||
.drive(customView.scrollView.rx.bottomInsetBinder)
|
||||
}
|
||||
|
||||
/// Unbind scroll view from previous binding.
|
||||
|
|
@ -53,6 +51,18 @@ open class BaseScrollContentController<ViewModel, View: ScrollViewHolderView>: B
|
|||
public var scrollView: UIScrollView {
|
||||
return customView.scrollView
|
||||
}
|
||||
|
||||
/// Default insets used for contained scroll view.
|
||||
public var defaultInsets: UIEdgeInsets {
|
||||
get {
|
||||
return defaultInsetsRelay.value
|
||||
}
|
||||
set {
|
||||
defaultInsetsRelay.accept(newValue)
|
||||
customView.scrollView.contentInset = newValue
|
||||
customView.scrollView.scrollIndicatorInsets = newValue
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public extension BaseScrollContentController {
|
||||
|
|
|
|||
|
|
@ -26,14 +26,11 @@ import RxCocoa
|
|||
public extension Reactive where Base: UIScrollView {
|
||||
|
||||
/// Binder instance that updates contentInset bottom value.
|
||||
/// If it doesn't work, observe it on MainScheduler.asyncInstance.
|
||||
var bottomInsetBinder: Binder<CGFloat> {
|
||||
return Binder(base) { base, value in
|
||||
// Quick workaround.
|
||||
// For some reason code in closure won't work without async call.
|
||||
DispatchQueue.main.async {
|
||||
base.contentInset.bottom = value
|
||||
base.scrollIndicatorInsets.bottom = value
|
||||
}
|
||||
base.contentInset.bottom = value
|
||||
base.scrollIndicatorInsets.bottom = value
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue