Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add checks for code so it can be used in projects with a minimum target < iOS 13 #38

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions SkeletonUI.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@ SkeletonUI aims to bring an elegant, declarative syntax to skeleton loading anim
s.author = { 'CSolanaM' => '[email protected]' }
s.source = { :git => 'https://github.com/CSolanaM/SkeletonUI.git', :tag => s.version.to_s }
s.social_media_url = 'https://twitter.com/CSolanaM'
s.ios.deployment_target = '13.0'
s.tvos.deployment_target = '13.0'
s.ios.deployment_target = '12.0'
s.tvos.deployment_target = '12.0'
s.watchos.deployment_target = '6.0'
s.macos.deployment_target = '10.15'
s.swift_version = '5.0'
s.source_files = 'Sources/SkeletonUI/**/*'
s.weak_framework = 'SwiftUI'
end
7 changes: 6 additions & 1 deletion Sources/SkeletonUI/Angle/AngleInteractor.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
#if arch(x86_64) || arch(arm64)

import Combine
import SwiftUI

// sourcery: AutoMockable
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol AngleInteractable: AnyObject {
var presenter: AnglePresenter { get }
var animation: CurrentValueSubject<Animation?, Never> { get }
var value: CurrentValueSubject<Double, Never> { get }
var range: CurrentValueSubject<ClosedRange<Double>, Never> { get }
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class AngleInteractor: AngleInteractable {
let presenter = AnglePresenter()
let animation: CurrentValueSubject<Animation?, Never>
Expand All @@ -27,3 +30,5 @@ final class AngleInteractor: AngleInteractable {
range.map { $0.lowerBound }.assign(to: \.value, on: presenter).store(in: &cancellables)
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Angle/AnglePresenter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnglePresenter: ObservableObject {
@Published var animation: Animation?
@Published var value: Double = .zero
@Published var range: ClosedRange<Double> = .zero ... 360
}

#endif
7 changes: 7 additions & 0 deletions Sources/SkeletonUI/Animation/AnimationInteractor.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
#if arch(x86_64) || arch(arm64)

import Combine
import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public enum AnimationType: Equatable {
case none
case pulse(range: ClosedRange<Double> = .zero ... 1, duration: Double = 2, delay: Double = 1, speed: Double = 2, autoreverses: Bool = true)
case linear(range: ClosedRange<CGFloat> = .zero ... 1, duration: Double = 4, delay: Double = 1, speed: Double = 5, autoreverses: Bool = false)
}

// sourcery: AutoMockable
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol AnimationInteractable: AnyObject {
var position: PositionInteractable { get }
var opacity: OpacityInteractable { get }
Expand All @@ -16,6 +20,7 @@ protocol AnimationInteractable: AnyObject {
var type: CurrentValueSubject<AnimationType, Never> { get }
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class AnimationInteractor: AnimationInteractable {
let position: PositionInteractable
let opacity: OpacityInteractable
Expand Down Expand Up @@ -54,3 +59,5 @@ final class AnimationInteractor: AnimationInteractable {
}.store(in: &cancellables)
}
}

#endif
10 changes: 9 additions & 1 deletion Sources/SkeletonUI/Appearance/AppearanceInteractor.swift
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
#if arch(x86_64) || arch(arm64)

import Combine
import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public enum GradientType: Equatable {
case linear
case angular
case radial
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public struct SkeletonColor {
public static var primary: Color {
#if os(iOS)
Expand All @@ -33,18 +37,20 @@ public struct SkeletonColor {
}
}


@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public enum AppearanceType: Equatable {
case solid(color: Color = SkeletonColor.primary, background: Color = SkeletonColor.background)
case gradient(GradientType = .linear, color: Color = SkeletonColor.primary, background: Color = SkeletonColor.background, radius: CGFloat = 1, angle: CGFloat = .zero)
}

// sourcery: AutoMockable
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol AppearanceInteractable: AnyObject {
var presenter: AppearancePresenter { get }
var type: CurrentValueSubject<AppearanceType, Never> { get }
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class AppearanceInteractor: AppearanceInteractable {
let presenter = AppearancePresenter()
let type: CurrentValueSubject<AppearanceType, Never>
Expand All @@ -56,3 +62,5 @@ final class AppearanceInteractor: AppearanceInteractable {
type.assign(to: \.type, on: presenter).store(in: &cancellables)
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Appearance/AppearancePresenter.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class AppearancePresenter: ObservableObject {
@Published var type: AppearanceType = .gradient()
}

#endif
6 changes: 5 additions & 1 deletion Sources/SkeletonUI/Extensions/ClosedRange+Normalize.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import CoreGraphics
#if arch(x86_64) || arch(arm64)

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension ClosedRange where Bound == CGFloat {
func normalize(with range: ClosedRange) -> ClosedRange {
let lowerBound = range.lowerBound == .zero ? self.lowerBound : range.lowerBound
Expand All @@ -8,9 +9,12 @@ extension ClosedRange where Bound == CGFloat {
}
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension ClosedRange where Bound == Double {
func normalize(with range: ClosedRange<CGFloat>) -> ClosedRange {
let normalized = (CGFloat(lowerBound) ... CGFloat(upperBound)).normalize(with: range)
return Double(normalized.lowerBound) ... Double(normalized.upperBound)
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/Image+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension Image {
#if os(iOS) || os(tvOS) || os(watchOS)
init(uiImage: UIImage?) {
Expand Down Expand Up @@ -100,3 +103,5 @@ public extension Image {
}
#endif
}

#endif
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand All @@ -24,3 +26,5 @@ public extension ModifiedContent where Content: View, Modifier == SkeletonModifi
return self
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/Optional+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
#if arch(x86_64) || arch(arm64)

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension Optional: OptionalType {
public var wrapped: Wrapped? {
self
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/SecureField+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension SecureField where Label == Text {
init(_ titleKey: LocalizedStringKey?, text: Binding<String>, onCommit: @escaping () -> Void = {}) {
if let titleKey = titleKey {
Expand All @@ -17,3 +20,5 @@ public extension SecureField where Label == Text {
}
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/Text+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension Text {
init<S>(_ content: S?) where S: OptionalType, S.Wrapped: StringProtocol {
if let content = content?.wrapped {
Expand All @@ -25,3 +28,5 @@ public extension Text {
}
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/TextField+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension TextField where Label == Text {
init(titleKey: LocalizedStringKey?, text: Binding<String>, onEditingChanged: @escaping (Bool) -> Void = { _ in }, onCommit: @escaping () -> Void = {}) {
if let titleKey = titleKey {
Expand Down Expand Up @@ -33,3 +36,5 @@ public extension TextField where Label == Text {
}
}
}

#endif
6 changes: 6 additions & 0 deletions Sources/SkeletonUI/Extensions/Toggle+OptionalType.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension Toggle where Label: View {
init(isOn: Binding<Bool>?, @ViewBuilder label: () -> Label) {
if let isOn = isOn {
Expand All @@ -10,6 +13,7 @@ public extension Toggle where Label: View {
}
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
public extension Toggle where Label == Text {
init(_ titleKey: LocalizedStringKey?, isOn: Binding<Bool>) {
if let titleKey = titleKey {
Expand All @@ -27,3 +31,5 @@ public extension Toggle where Label == Text {
}
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Extensions/UnitPoint+Angle.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
extension UnitPoint {
static func point(with position: CGFloat, _ radius: CGFloat, _ angle: CGFloat) -> UnitPoint {
let radians = angle * .pi / 180.0
return UnitPoint(x: (position + radius) * cos(radians), y: (position + radius) * sin(radians))
}
}

#endif
4 changes: 4 additions & 0 deletions Sources/SkeletonUI/Extensions/View+SkeletonModifier.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand All @@ -6,3 +8,5 @@ public extension View {
modifier(SkeletonModifier(skeleton: SkeletonInteractor(loading, size: size, transition: transition, animated: animated)))
}
}

#endif
4 changes: 4 additions & 0 deletions Sources/SkeletonUI/Modifiers/SkeletonModifier.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
Expand Down Expand Up @@ -41,3 +43,5 @@ public struct SkeletonModifier: ViewModifier {
.animation(skeleton.presenter.animated, value: skeleton.presenter.loading)
}
}

#endif
6 changes: 6 additions & 0 deletions Sources/SkeletonUI/Multiline/MultilineInteractor.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#if arch(x86_64) || arch(arm64)

import Combine
import SwiftUI

// sourcery: AutoMockable
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol MultilineInteractable: AnyObject {
var presenter: MultilinePresenter { get }
var line: CurrentValueSubject<Int, Never> { get }
Expand All @@ -11,6 +14,7 @@ protocol MultilineInteractable: AnyObject {
var scales: CurrentValueSubject<[Int: CGFloat]?, Never> { get }
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class MultilineInteractor: MultilineInteractable {
let presenter = MultilinePresenter()
let line: CurrentValueSubject<Int, Never>
Expand Down Expand Up @@ -39,3 +43,5 @@ final class MultilineInteractor: MultilineInteractable {
spacing.assign(to: \.spacing, on: presenter).store(in: &cancellables)
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Multiline/MultilinePresenter.swift
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class MultilinePresenter: ObservableObject {
@Published var line: Int = 0
@Published var lines: Int = 1
@Published var spacing: CGFloat?
@Published var scale: CGFloat = 1
@Published var scales: [Int: CGFloat]?
}

#endif
6 changes: 6 additions & 0 deletions Sources/SkeletonUI/Opacity/OpacityInteractor.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#if arch(x86_64) || arch(arm64)

import Combine
import SwiftUI

// sourcery: AutoMockable
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
protocol OpacityInteractable: AnyObject {
var presenter: OpacityPresenter { get }
var animation: CurrentValueSubject<Animation?, Never> { get }
var value: CurrentValueSubject<Double, Never> { get }
var range: CurrentValueSubject<ClosedRange<Double>, Never> { get }
}

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class OpacityInteractor: OpacityInteractable {
let presenter = OpacityPresenter()
let animation: CurrentValueSubject<Animation?, Never>
Expand All @@ -27,3 +31,5 @@ final class OpacityInteractor: OpacityInteractable {
range.map { $0.lowerBound }.assign(to: \.value, on: presenter).store(in: &cancellables)
}
}

#endif
5 changes: 5 additions & 0 deletions Sources/SkeletonUI/Opacity/OpacityPresenter.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
#if arch(x86_64) || arch(arm64)

import SwiftUI

@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
final class OpacityPresenter: ObservableObject {
@Published var animation: Animation?
@Published var value: Double = .zero
@Published var range: ClosedRange<Double> = .zero ... 1
}

#endif
Loading