From 667c15aa332787cb10a5d61d810d58c19eaa3cda Mon Sep 17 00:00:00 2001 From: Ivan Smolin Date: Mon, 30 Jul 2018 14:43:59 +0300 Subject: [PATCH] code review notes --- .../BaseScrollContentController.swift | 27 ++++++------------- ...mattingService+DefaultImplementation.swift | 19 ++++++++++++- .../DateFormattingService.swift | 9 +++++++ 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/Sources/Classes/Controllers/BaseScrollContentController.swift b/Sources/Classes/Controllers/BaseScrollContentController.swift index b8a97ee4..e5889531 100644 --- a/Sources/Classes/Controllers/BaseScrollContentController.swift +++ b/Sources/Classes/Controllers/BaseScrollContentController.swift @@ -28,19 +28,20 @@ public typealias ScrollViewHolderView = UIView & ScrollViewHolder /// Base controller configurable with view model and ScrollViewHolder custom view. open class BaseScrollContentController: BaseCustomViewController { - private let defaultInsetsRelay = BehaviorRelay(value: .zero) - private var bottomInsetDisposable: Disposable? /// 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) { - bottomInsetDisposable = bottomInsetDriver - .withLatestFrom(defaultInsetsRelay.asDriver()) { - $0 + $1.bottom - } - .drive(customView.scrollView.rx.bottomInsetBinder) + 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) } /// Unbind scroll view from previous binding. @@ -48,18 +49,6 @@ open class BaseScrollContentController: B bottomInsetDisposable?.dispose() } - /// 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 - } - } - /// Contained UIScrollView instance. public var scrollView: UIScrollView { return customView.scrollView diff --git a/Sources/Extensions/DateFormattingService/DateFormattingService+DefaultImplementation.swift b/Sources/Extensions/DateFormattingService/DateFormattingService+DefaultImplementation.swift index 68b7499b..cc99f94f 100644 --- a/Sources/Extensions/DateFormattingService/DateFormattingService+DefaultImplementation.swift +++ b/Sources/Extensions/DateFormattingService/DateFormattingService+DefaultImplementation.swift @@ -36,7 +36,13 @@ public extension DateFormattingService { } func string(from date: DateInRegion, format: DateFormatType) -> String { - let dateInFormatterRegion = date.convertTo(region: currentRegion) + return date.toString(format.swiftDateFormat) + } + + func string(from date: DateInRegion, format: DateFormatType, formattedIn: Region? = nil) -> String { + let region = formattedIn ?? currentRegion + + let dateInFormatterRegion = date.convertTo(region: region) return dateInFormatterRegion.toString(format.swiftDateFormat) } @@ -80,4 +86,15 @@ public extension DateFormattingService where Self: Singleton { return shared.string(from: date, format: format) } + /// Method format date in given format for specific region. + /// + /// - Parameters: + /// - date: Date to format. + /// - format: Format that should be used for date formatting. + /// - formattedIn: A region that should be used for date formatting. In case of nil defaultRegion will be used. + /// - Returns: String that contains formatted date or nil if formatting did fail. + static func string(from date: DateInRegion, format: DateFormatType, formattedIn: Region?) -> String { + return shared.string(from: date, format: format, formattedIn: formattedIn) + } + } diff --git a/Sources/Protocols/DateFormatingService/DateFormattingService.swift b/Sources/Protocols/DateFormatingService/DateFormattingService.swift index cb23296c..ccba251c 100644 --- a/Sources/Protocols/DateFormatingService/DateFormattingService.swift +++ b/Sources/Protocols/DateFormatingService/DateFormattingService.swift @@ -56,4 +56,13 @@ public protocol DateFormattingService { /// - Returns: String that contains formatted date or nil if formatting did fail. func string(from date: DateInRegion, format: DateFormatType) -> String + /// Method format date in given format for specific region. + /// + /// - Parameters: + /// - date: Date to format. + /// - format: Format that should be used for date formatting. + /// - formattedIn: A region that should be used for date formatting. In case of nil defaultRegion will be used. + /// - Returns: String that contains formatted date or nil if formatting did fail. + func string(from date: DateInRegion, format: DateFormatType, formattedIn: Region?) -> String + }