code review notes

This commit is contained in:
Ivan Smolin 2018-07-30 14:43:59 +03:00
parent 8b9f3edace
commit 667c15aa33
3 changed files with 35 additions and 20 deletions

View File

@ -28,19 +28,20 @@ public typealias ScrollViewHolderView = UIView & ScrollViewHolder
/// Base controller configurable with view model and ScrollViewHolder custom view.
open class BaseScrollContentController<ViewModel, View: ScrollViewHolderView>: BaseCustomViewController<ViewModel, View> {
private let defaultInsetsRelay = BehaviorRelay<UIEdgeInsets>(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<CGFloat>) {
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<ViewModel, View: ScrollViewHolderView>: 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

View File

@ -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)
}
}

View File

@ -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
}