Several things were added:

- TitleType enum
- Large title display mode variable
- Function for updating title in view controllers
This commit is contained in:
Artur Azarau 2019-01-10 10:01:22 +03:00
parent c19f56ecf6
commit 707d4bc6f4
7 changed files with 141 additions and 20 deletions

View File

@ -665,6 +665,9 @@
6B5B6EF1577C8CC06E4CCF1B /* Array+RowExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B62E7942E5AEE68A95449 /* Array+RowExtensions.swift */; };
6B5B6F0BFA22832C47142BAD /* TableKitViewModel+Extenstions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B61443DDAB82927448CAA /* TableKitViewModel+Extenstions.swift */; };
6B5B6F4E2B4F6F74348AC138 /* TableKitViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6B5B66503F2C42D009DEA011 /* TableKitViewModel.swift */; };
7295473F21E661E6009558E7 /* TitleType.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295473E21E661E6009558E7 /* TitleType.swift */; };
7295474221E6628C009558E7 /* UINavigationItem+TitleDisplay.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295474121E6628C009558E7 /* UINavigationItem+TitleDisplay.swift */; };
7295474421E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */; };
820CAD8420B43B080033EF94 /* PaginationWrapperDelegate+DefaultImplementation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 820CAD8320B43B080033EF94 /* PaginationWrapperDelegate+DefaultImplementation.swift */; };
825F8F2820B3384C00594857 /* PaginationWrapperUIDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 825F8F2720B3384C00594857 /* PaginationWrapperUIDelegate.swift */; };
82F8BB181F5DDED100C1061B /* Single+DeferredJust.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F8BB171F5DDED100C1061B /* Single+DeferredJust.swift */; };
@ -981,6 +984,9 @@
6B5B61443DDAB82927448CAA /* TableKitViewModel+Extenstions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableKitViewModel+Extenstions.swift"; sourceTree = "<group>"; };
6B5B62E7942E5AEE68A95449 /* Array+RowExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+RowExtensions.swift"; sourceTree = "<group>"; };
6B5B66503F2C42D009DEA011 /* TableKitViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableKitViewModel.swift; sourceTree = "<group>"; };
7295473E21E661E6009558E7 /* TitleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleType.swift; sourceTree = "<group>"; };
7295474121E6628C009558E7 /* UINavigationItem+TitleDisplay.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationItem+TitleDisplay.swift"; sourceTree = "<group>"; };
7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+UpdateNavigationItemTitle.swift"; sourceTree = "<group>"; };
78405D3B3D3C3E17456877FF /* Pods_LeadKit_iOSTests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_LeadKit_iOSTests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
820CAD8320B43B080033EF94 /* PaginationWrapperDelegate+DefaultImplementation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PaginationWrapperDelegate+DefaultImplementation.swift"; sourceTree = "<group>"; };
825F8F2720B3384C00594857 /* PaginationWrapperUIDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationWrapperUIDelegate.swift; sourceTree = "<group>"; };
@ -1161,6 +1167,7 @@
671461D81EB3396E00EAB194 /* LeadKitError.swift */,
671461D91EB3396E00EAB194 /* ResizeMode.swift */,
67FDC25E1FA310EA00C76A77 /* RequestError.swift */,
7295473E21E661E6009558E7 /* TitleType.swift */,
);
path = Enums;
sourceTree = "<group>";
@ -1337,6 +1344,7 @@
671463A61EB340C000EAB194 /* UIViewController+ConfigurableController.swift */,
671462191EB3396E00EAB194 /* UIViewController+DefaultXibName.swift */,
6714621A1EB3396E00EAB194 /* UIViewController+TopVisibleViewController.swift */,
7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */,
);
path = UIViewController;
sourceTree = "<group>";
@ -1574,6 +1582,7 @@
672947E4206EA67B00AC6B6B /* UIImage */,
67E902552125B55E008EDF45 /* UIImageView */,
67274776206CD07B00725163 /* UILabel */,
7295474021E6623D009558E7 /* UINavigationItem */,
6741CEB820E242CF00FEC4D9 /* UIScrollView */,
36DAAF4F2007CC330090BE0D /* UITableView */,
67E3524C2119ABD00035BDDB /* UITextField */,
@ -2167,6 +2176,14 @@
path = TableKitViewModel;
sourceTree = "<group>";
};
7295474021E6623D009558E7 /* UINavigationItem */ = {
isa = PBXGroup;
children = (
7295474121E6628C009558E7 /* UINavigationItem+TitleDisplay.swift */,
);
path = UINavigationItem;
sourceTree = "<group>";
};
78CFEE201C5C456B00F50370 = {
isa = PBXGroup;
children = (
@ -2926,6 +2943,7 @@
673564F62068C68D00F0CBED /* NumberFormat.swift in Sources */,
67DB776921087154001CB56B /* CollectionViewWrapperView.swift in Sources */,
671462901EB3396E00EAB194 /* CGImage+Crop.swift in Sources */,
7295473F21E661E6009558E7 /* TitleType.swift in Sources */,
671462FC1EB3396E00EAB194 /* UIView+XibNameProtocol.swift in Sources */,
67EB7FC0206140E600BDD9FB /* TotalCountCursor.swift in Sources */,
36DAAF512007CC920090BE0D /* UITableView+Extensions.swift in Sources */,
@ -2988,6 +3006,8 @@
B84CB06D20B8325D0090DB91 /* SessionManager.swift in Sources */,
A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */,
673564F12068C2AD00F0CBED /* NumberFormattingService+DefaultImplementation.swift in Sources */,
7295474221E6628C009558E7 /* UINavigationItem+TitleDisplay.swift in Sources */,
7295474421E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift in Sources */,
671462EC1EB3396E00EAB194 /* UIImage+Extensions.swift in Sources */,
6713C24120AF189100875921 /* RxNetworkOperationModel.swift in Sources */,
677452AE206274630024EEEF /* PaginationWrapper.swift in Sources */,

View File

@ -0,0 +1,27 @@
//
// Copyright (c) 2019 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
enum TitleType {
case large(title: String)
case normal(title: String)
case empty
}

View File

@ -29,15 +29,14 @@ import RxAlamofire
/// - getMethodForbidden: invalid usage of get method
/// - urlEncodingForbidden: invalid usage of URLEncoding
enum RequestUsageError: Error {
case getMethodForbidden
case urlEncodingForbidden
}
public extension Reactive where Base: SessionManager {
/// Creates an observable of the `Request`.
///
/// - Parameters:
@ -47,36 +46,36 @@ public extension Reactive where Base: SessionManager {
/// - encoding: The kind of encoding used to process parameters
/// - headers: A dictionary containing all the additional headers
/// - Returns: An observable of the `Request`
public func request(_ method: Alamofire.HTTPMethod,
_ url: URLConvertible,
parameters: [Any]? = nil,
encoding: JSONEncoding = .default,
headers: [String: String]? = nil)
func request(_ method: Alamofire.HTTPMethod,
_ url: URLConvertible,
parameters: [Any]? = nil,
encoding: JSONEncoding = .default,
headers: [String: String]? = nil)
-> Observable<DataRequest> {
return Observable.deferred {
guard method != .get else {
assertionFailure("Unable to pass array in get request")
throw RequestUsageError.getMethodForbidden
}
let urlRequest = try URLRequest(url: try url.asURL(), method: method, headers: headers)
let encodedUrlRequest = try encoding.encode(urlRequest, withJSONObject: parameters)
return self.request(urlRequest: encodedUrlRequest)
}
}
/// Method which executes request with given api parameters
///
/// - Parameter requestParameters: api parameters to pass Alamofire
/// - Returns: Observable with request
func apiRequest(requestParameters: ApiRequestParameters)
-> Observable<DataRequest> {
let requestObservable: Observable<DataRequest>
switch requestParameters.parameters {
case .dictionary(let parameters)?:
requestObservable = request(requestParameters.method,
@ -89,7 +88,7 @@ public extension Reactive where Base: SessionManager {
assertionFailure("Invalid encoding type with array parameter")
return .error(RequestUsageError.urlEncodingForbidden)
}
requestObservable = request(requestParameters.method,
requestParameters.url,
parameters: parameters,
@ -102,7 +101,7 @@ public extension Reactive where Base: SessionManager {
encoding: requestParameters.encoding,
headers: requestParameters.headers)
}
return requestObservable
.map { $0.validate(statusCode: self.base.acceptableStatusCodes) }
}

View File

@ -0,0 +1,41 @@
//
// Copyright (c) 2019 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the Software), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import UIKit
public extension UINavigationItem {
var largeTitleDisplayModeIOS11: LargeTitleDisplayMode {
get {
if #available(iOS 11.0, *) {
return largeTitleDisplayMode
} else {
return .never
}
}
set {
if #available(iOS 11.0, *) {
largeTitleDisplayMode = newValue
}
}
}
}

View File

@ -0,0 +1,34 @@
//
// Copyright (c) 2019 Touch Instinct
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
import UIKit
extension UIViewController {
func updateNavigationItemTitle(with titleType: TitleType) {
switch titleType {
case let .large(newTitle), let .normal(newTitle):
title = newTitle
case .empty:
title = nil
}
}
}

View File

@ -35,7 +35,7 @@ public struct ApiRequestParameters {
case dictionary(Parameters)
case array([Any])
}
let method: HTTPMethod
let url: URLConvertible
let parameters: RequestParameters?
@ -58,13 +58,13 @@ public struct ApiRequestParameters {
self.parameters = nil
}
}
public init(url: URLConvertible,
method: HTTPMethod = .get,
parameters: [Any]? = nil,
encoding: ParameterEncoding = URLEncoding.default,
headers: HTTPHeaders? = nil) {
self.method = method
self.url = url
self.encoding = encoding

View File

@ -95,7 +95,7 @@ public extension NetworkServiceConfiguration {
encoding: requestEncoding ?? encoding,
headers: requestHeaders)
}
/// Convenient method to create ApiRequestParameters.
///
/// - Parameters: