From d4fa2d1109333a8b75fc75a52c5e3886ee503e7d Mon Sep 17 00:00:00 2001 From: Artur Date: Mon, 20 May 2019 16:20:45 +0300 Subject: [PATCH] Realization updated --- .../BaseScrollContentController.swift | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/Sources/Classes/Controllers/BaseScrollContentController.swift b/Sources/Classes/Controllers/BaseScrollContentController.swift index 6c1ea683..ee8a575c 100644 --- a/Sources/Classes/Controllers/BaseScrollContentController.swift +++ b/Sources/Classes/Controllers/BaseScrollContentController.swift @@ -29,18 +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.contentOffset - - let bottomInset = contentInsetObservable.map { $0.y } - - 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. @@ -52,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 {