diff --git a/Package.swift b/Package.swift index 698d8992..ddb68741 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,7 @@ let package = Package( .library(name: "TISwiftUtils", targets: ["TISwiftUtils"]), .library(name: "TIFoundationUtils", targets: ["TIFoundationUtils"]), .library(name: "TIUIElements", targets: ["TIUIElements"]), - .library(name: "OTPSwiftView", targets: ["OTPSwiftView"]) + .library(name: "OTPSwiftView", targets: ["OTPSwiftView"]), ], targets: [ .target(name: "TITransitions", path: "TITransitions/Sources"), @@ -20,6 +20,6 @@ let package = Package( .target(name: "TISwiftUtils", path: "TISwiftUtils/Sources"), .target(name: "TIFoundationUtils", dependencies: ["TISwiftUtils"], path: "TIFoundationUtils/Sources"), .target(name: "TIUIElements", dependencies: ["TIUIKitCore"], path: "TIUIElements/Sources"), - .target(name: "OTPSwiftView", dependencies: ["TIUIKitCore", "TISwiftUtils"], path: "OTPSwiftView/Sources") + .target(name: "OTPSwiftView", dependencies: ["TIUIKitCore", "TISwiftUtils"], path: "OTPSwiftView/Sources"), ] ) diff --git a/TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift similarity index 98% rename from TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift rename to TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift index b24434a4..6196b28a 100644 --- a/TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift +++ b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+ActivityIndicatorHolder.swift @@ -21,7 +21,6 @@ // import UIKit -import TIUIKitCore extension UIActivityIndicatorView: ActivityIndicatorHolder { public var activityIndicator: Animatable { diff --git a/TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift similarity index 98% rename from TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift rename to TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift index 2d709284..a80f1656 100644 --- a/TIUIElements/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift +++ b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+Animatable.swift @@ -21,6 +21,5 @@ // import UIKit -import TIUIKitCore extension UIActivityIndicatorView: Animatable {} diff --git a/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+LoadingIndicator.swift b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+LoadingIndicator.swift new file mode 100644 index 00000000..30576365 --- /dev/null +++ b/TIUIKitCore/Sources/Extensions/UIActivityIndicatorView/UIActivityIndicatorView+LoadingIndicator.swift @@ -0,0 +1,25 @@ +// +// Copyright (c) 2017 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 UIActivityIndicatorView: LoadingIndicator {} diff --git a/TIUIKitCore/Sources/Extensions/UIView/UIView+LoadingIndicator.swift b/TIUIKitCore/Sources/Extensions/UIView/UIView+LoadingIndicator.swift new file mode 100644 index 00000000..43288f0a --- /dev/null +++ b/TIUIKitCore/Sources/Extensions/UIView/UIView+LoadingIndicator.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) 2017 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 LoadingIndicator where Self: UIView { + + var view: Self { + return self + } +} diff --git a/TIUIKitCore/Sources/Protocols/LoadingIndicator/LoadingIndicator.swift b/TIUIKitCore/Sources/Protocols/LoadingIndicator/LoadingIndicator.swift new file mode 100644 index 00000000..94c9c7a8 --- /dev/null +++ b/TIUIKitCore/Sources/Protocols/LoadingIndicator/LoadingIndicator.swift @@ -0,0 +1,45 @@ +// +// Copyright (c) 2017 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 + +/// Protocol that describes placeholder view, containing loading indicator. +public protocol LoadingIndicatorHolder: class { + var loadingIndicator: Animatable { get } + var indicatorOwner: UIView { get } +} + +public extension LoadingIndicatorHolder where Self: UIView { + var indicatorOwner: UIView { + return self + } +} + +/// Protocol that describes badic loading indicator. +public protocol LoadingIndicator { + + /// Type of view. Should be instance of UIView with basic animation actions. + associatedtype View: UIView, Animatable + + /// The underlying view. + var view: View { get } +} diff --git a/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolder.swift b/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolder.swift new file mode 100644 index 00000000..0f3b4120 --- /dev/null +++ b/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolder.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) 2020 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.UIButton + +/// Protocol that contains button property. +public protocol ButtonHolder { + + /// Contained UIButton instance. + var button: UIButton { get } +} diff --git a/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolderView.swift b/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolderView.swift new file mode 100644 index 00000000..22b08e84 --- /dev/null +++ b/TIUIKitCore/Sources/Protocols/UIKit/ButtonHolder/ButtonHolderView.swift @@ -0,0 +1,26 @@ +// +// Copyright (c) 2020 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.UIView + +/// View which contains button +public typealias ButtonHolderView = UIView & ButtonHolder diff --git a/Sources/Protocols/DataLoading/PaginationDataLoading/PaginationWrappable.swift b/TIUIKitCore/Sources/Protocols/UIKit/CollectionViewHolder.swift similarity index 70% rename from Sources/Protocols/DataLoading/PaginationDataLoading/PaginationWrappable.swift rename to TIUIKitCore/Sources/Protocols/UIKit/CollectionViewHolder.swift index acd7b92d..55f7a3bf 100644 --- a/Sources/Protocols/DataLoading/PaginationDataLoading/PaginationWrappable.swift +++ b/TIUIKitCore/Sources/Protocols/UIKit/CollectionViewHolder.swift @@ -20,19 +20,11 @@ // THE SOFTWARE. // -import UIKit +import UIKit.UICollectionView -/// Protocol that contains background view property. -public protocol BackgroundViewHolder { +/// Protocol that contains table view property. +public protocol CollectionViewHolder { - var backgroundView: UIView? { get set } + /// Contained UICollectionView instance. + var collectionView: UICollectionView { get } } - -/// Protocol that contains footer view property. -public protocol FooterViewHolder { - - var footerView: UIView? { get set } -} - -/// Protocol that conforms to ScrollViewHolder, BackgroundViewHolder and FooterViewHolder protocols. -public protocol PaginationWrappable: ScrollViewHolder, BackgroundViewHolder, FooterViewHolder {} diff --git a/TIUIKitCore/Sources/Protocols/UIKit/ScrollViewHolder.swift b/TIUIKitCore/Sources/Protocols/UIKit/ScrollViewHolder.swift new file mode 100644 index 00000000..7d2c4214 --- /dev/null +++ b/TIUIKitCore/Sources/Protocols/UIKit/ScrollViewHolder.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) 2018 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.UIScrollView + +/// Protocol that contains scroll view property. +public protocol ScrollViewHolder { + + /// Contained UIScrollView instance. + var scrollView: UIScrollView { get } +} diff --git a/TIUIKitCore/Sources/Protocols/UIKit/TableViewHolder.swift b/TIUIKitCore/Sources/Protocols/UIKit/TableViewHolder.swift new file mode 100644 index 00000000..cabe3652 --- /dev/null +++ b/TIUIKitCore/Sources/Protocols/UIKit/TableViewHolder.swift @@ -0,0 +1,30 @@ +// +// Copyright (c) 2018 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.UITableView + +/// Protocol that contains table view property. +public protocol TableViewHolder { + + /// Contained UITableView instance. + var tableView: UITableView { get } +} diff --git a/TIUIKitCore/Sources/Views/AnyLoadingIndicator.swift b/TIUIKitCore/Sources/Views/AnyLoadingIndicator.swift new file mode 100644 index 00000000..d6539a4a --- /dev/null +++ b/TIUIKitCore/Sources/Views/AnyLoadingIndicator.swift @@ -0,0 +1,59 @@ +// +// Copyright (c) 2017 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 + +/// Type that performs some kind of type erasure for LoadingIndicator. +public struct AnyLoadingIndicator: Animatable { + + private let backgroundView: UIView + private let animatableView: Animatable + + /// Initializer with indicator that should be wrapped. + /// + /// - Parameter _: indicator for wrapping. + public init (_ base: Indicator) where Indicator: LoadingIndicator { + self.backgroundView = base.view + self.animatableView = base.view + } + + /// Initializer with placeholder view, that wraps indicator. + /// + /// - Parameter loadingIndicatorHolder: placeholder view, containing indicator. + public init(loadingIndicatorHolder: LoadingIndicatorHolder) { + self.backgroundView = loadingIndicatorHolder.indicatorOwner + self.animatableView = loadingIndicatorHolder.loadingIndicator + } + + /// The background view. + public var view: UIView { + return backgroundView + } + + public func startAnimating() { + animatableView.startAnimating() + } + + public func stopAnimating() { + animatableView.stopAnimating() + } +}