diff --git a/CHANGELOG.md b/CHANGELOG.md index 50f44e39..6e6c08b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ # Changelog +### 0.9.5 +- **Add**: `TitleType` enum, that defines `UIViewController`'s title type. +- **Add**: `UINavigationItem.largeTitleDisplayMode` property, that defines `UINavigationItem`'s large title display mode. +- **Add**: `UIViewController.updateNavigationItemTitle` method, that takes `TitleType` as a parameter and updates `UIViewController`'s title. + ### 0.9.4 - **Add**: initialization of `ApiRequestParameters`, that takes an array as a request parameter. - **Add**: `NetworkServiceConfiguration.apiRequestParameters` method, that creates `ApiRequestParameters` with array request parameter. diff --git a/LeadKit.podspec b/LeadKit.podspec index 5aa0ebbc..d213fcff 100644 --- a/LeadKit.podspec +++ b/LeadKit.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "LeadKit" - s.version = "0.9.4" + s.version = "0.9.5" 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" @@ -44,6 +44,7 @@ Pod::Spec.new do |s| "Sources/Extensions/DataLoading/GeneralDataLoading/GeneralDataLoadingController+DefaultImplementation.swift", "Sources/Extensions/DataLoading/PaginationDataLoading/*", "Sources/Extensions/Support/UIScrollView+Support.swift", + "Sources/Extensions/Support/UINavigationItem+Support.swift", "Sources/Extensions/TableKit/**/*.swift", "Sources/Extensions/Array/Array+SeparatorRowBoxExtensions.swift", "Sources/Extensions/Array/Array+RowExtensions.swift", @@ -76,6 +77,7 @@ Pod::Spec.new do |s| "Sources/Extensions/NetworkService/NetworkService+ActivityIndicator-UIApplication.swift", "Sources/Extensions/DataLoading/PaginationDataLoading/*", "Sources/Extensions/Support/UIScrollView+Support.swift", + "Sources/Extensions/Support/UINavigationItem+Support.swift", "Sources/Extensions/TableKit/**/*.swift", "Sources/Extensions/UIKit/UIApplication/UIApplication+OpenUrlSupport.swift", "Sources/Extensions/UIKit/UIApplication/UIApplication+Cellular.swift", diff --git a/LeadKit.xcodeproj/project.pbxproj b/LeadKit.xcodeproj/project.pbxproj index 0318f475..8618dc7c 100644 --- a/LeadKit.xcodeproj/project.pbxproj +++ b/LeadKit.xcodeproj/project.pbxproj @@ -665,6 +665,10 @@ 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+Support.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295474121E6628C009558E7 /* UINavigationItem+Support.swift */; }; + 7295474421E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */; }; + 7295474D21E75E84009558E7 /* UINavigationItem+Support.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7295474121E6628C009558E7 /* UINavigationItem+Support.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 +985,9 @@ 6B5B61443DDAB82927448CAA /* TableKitViewModel+Extenstions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "TableKitViewModel+Extenstions.swift"; sourceTree = ""; }; 6B5B62E7942E5AEE68A95449 /* Array+RowExtensions.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Array+RowExtensions.swift"; sourceTree = ""; }; 6B5B66503F2C42D009DEA011 /* TableKitViewModel.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TableKitViewModel.swift; sourceTree = ""; }; + 7295473E21E661E6009558E7 /* TitleType.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TitleType.swift; sourceTree = ""; }; + 7295474121E6628C009558E7 /* UINavigationItem+Support.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationItem+Support.swift"; sourceTree = ""; }; + 7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+UpdateNavigationItemTitle.swift"; sourceTree = ""; }; 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 = ""; }; 825F8F2720B3384C00594857 /* PaginationWrapperUIDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaginationWrapperUIDelegate.swift; sourceTree = ""; }; @@ -1161,6 +1168,7 @@ 671461D81EB3396E00EAB194 /* LeadKitError.swift */, 671461D91EB3396E00EAB194 /* ResizeMode.swift */, 67FDC25E1FA310EA00C76A77 /* RequestError.swift */, + 7295473E21E661E6009558E7 /* TitleType.swift */, ); path = Enums; sourceTree = ""; @@ -1278,6 +1286,7 @@ 671461FE1EB3396E00EAB194 /* Support */ = { isa = PBXGroup; children = ( + 7295474121E6628C009558E7 /* UINavigationItem+Support.swift */, 671461FF1EB3396E00EAB194 /* UIScrollView+Support.swift */, ); path = Support; @@ -1337,6 +1346,7 @@ 671463A61EB340C000EAB194 /* UIViewController+ConfigurableController.swift */, 671462191EB3396E00EAB194 /* UIViewController+DefaultXibName.swift */, 6714621A1EB3396E00EAB194 /* UIViewController+TopVisibleViewController.swift */, + 7295474321E66328009558E7 /* UIViewController+UpdateNavigationItemTitle.swift */, ); path = UIViewController; sourceTree = ""; @@ -2926,6 +2936,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 +2999,8 @@ B84CB06D20B8325D0090DB91 /* SessionManager.swift in Sources */, A658E5501F8CD9350093527A /* Array+SeparatorRowBoxExtensions.swift in Sources */, 673564F12068C2AD00F0CBED /* NumberFormattingService+DefaultImplementation.swift in Sources */, + 7295474221E6628C009558E7 /* UINavigationItem+Support.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 */, @@ -3535,6 +3548,7 @@ 67E352532119AC060035BDDB /* UIButton+ViewTextConfigurable.swift in Sources */, 6713C24220AF189100875921 /* RxNetworkOperationModel.swift in Sources */, 671462A11EB3396E00EAB194 /* Double+Rounding.swift in Sources */, + 7295474D21E75E84009558E7 /* UINavigationItem+Support.swift in Sources */, 671463091EB3396E00EAB194 /* UIView+Rotation.swift in Sources */, 67ED2BDF20B44DEB00508B3E /* InitializableView.swift in Sources */, 6714626D1EB3396E00EAB194 /* XibView.swift in Sources */, diff --git a/Sources/Enums/TitleType.swift b/Sources/Enums/TitleType.swift new file mode 100644 index 00000000..b2a95229 --- /dev/null +++ b/Sources/Enums/TitleType.swift @@ -0,0 +1,32 @@ +// +// 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. +// + +/// Title type for UIViewController title. +/// +/// - large: large sized title +/// - normal: normal sized title +/// - empty: empty title +public enum TitleType { + case large(title: String) + case normal(title: String) + case empty +} diff --git a/Sources/Extensions/Alamofire/SessionManager+Extensions.swift b/Sources/Extensions/Alamofire/SessionManager+Extensions.swift index 94e39703..c392cc6c 100644 --- a/Sources/Extensions/Alamofire/SessionManager+Extensions.swift +++ b/Sources/Extensions/Alamofire/SessionManager+Extensions.swift @@ -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 { 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 { - + let requestObservable: Observable - + 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) } } diff --git a/Sources/Extensions/Support/UINavigationItem+Support.swift b/Sources/Extensions/Support/UINavigationItem+Support.swift new file mode 100644 index 00000000..bd4f4e82 --- /dev/null +++ b/Sources/Extensions/Support/UINavigationItem+Support.swift @@ -0,0 +1,43 @@ +// +// 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 Support where Base: UINavigationItem { + + /// The mode to use when displaying the title of the navigation bar. + var largeTitleDisplayMode: Base.LargeTitleDisplayMode { + get { + if #available(iOS 11.0, *) { + return base.largeTitleDisplayMode + } else { + return .never + } + } + + set { + if #available(iOS 11.0, *) { + base.largeTitleDisplayMode = newValue + } + } + } +} diff --git a/Sources/Extensions/UIKit/UIViewController/UIViewController+UpdateNavigationItemTitle.swift b/Sources/Extensions/UIKit/UIViewController/UIViewController+UpdateNavigationItemTitle.swift new file mode 100644 index 00000000..f702ebe7 --- /dev/null +++ b/Sources/Extensions/UIKit/UIViewController/UIViewController+UpdateNavigationItemTitle.swift @@ -0,0 +1,38 @@ +// +// 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 UIViewController { + + /// Updates UIViewController's title + /// + /// - Parameter titleType: UIViewController's title type + func updateNavigationItemTitle(with titleType: TitleType) { + switch titleType { + case let .large(newTitle), let .normal(newTitle): + title = newTitle + case .empty: + title = nil + } + } +} diff --git a/Sources/Structures/Api/ApiRequestParameters.swift b/Sources/Structures/Api/ApiRequestParameters.swift index 411ff4e8..ed841085 100644 --- a/Sources/Structures/Api/ApiRequestParameters.swift +++ b/Sources/Structures/Api/ApiRequestParameters.swift @@ -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 diff --git a/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift b/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift index 231dd924..0917337e 100644 --- a/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift +++ b/Sources/Structures/NetworkService/NetworkServiceConfiguration.swift @@ -95,7 +95,7 @@ public extension NetworkServiceConfiguration { encoding: requestEncoding ?? encoding, headers: requestHeaders) } - + /// Convenient method to create ApiRequestParameters. /// /// - Parameters: