diff --git a/CHANGELOG.md b/CHANGELOG.md index b6e86452..7e03a42d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. diff --git a/LeadKit.podspec b/LeadKit.podspec index 7bec78c7..b77d9254 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -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" diff --git a/Sources/Classes/Controllers/BaseScrollContentController.swift b/Sources/Classes/Controllers/BaseScrollContentController.swift index 71a24404..ee8a575c 100644 --- a/Sources/Classes/Controllers/BaseScrollContentController.swift +++ b/Sources/Classes/Controllers/BaseScrollContentController.swift @@ -29,19 +29,17 @@ public typealias ScrollViewHolderView = UIView & ScrollViewHolder open class BaseScrollContentController: BaseCustomViewController { private var bottomInsetDisposable: Disposable? + private let defaultInsetsRelay = BehaviorRelay(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) { - 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: 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 { diff --git a/Sources/Extensions/UIKit/UIScrollView/UIScrollView+RxBindings.swift b/Sources/Extensions/UIKit/UIScrollView/UIScrollView+RxBindings.swift index 5b5be346..6e7c3793 100644 --- a/Sources/Extensions/UIKit/UIScrollView/UIScrollView+RxBindings.swift +++ b/Sources/Extensions/UIKit/UIScrollView/UIScrollView+RxBindings.swift @@ -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 { 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 } } }