From b7170bda30f218e8743e5554efaa85a00859dbcf Mon Sep 17 00:00:00 2001 From: Ramon Torres Date: Fri, 4 Aug 2023 21:26:58 -0400 Subject: [PATCH] Update docs (#4) * Update docs * Make examples more obvious * Update README --- .swiftlint.yml | 2 +- README.md | 12 ++-- Sources/SmoothGradient/CubicBezierCurve.swift | 8 +++ Sources/SmoothGradient/Gradient+Smooth.swift | 64 +++++++++---------- .../SmoothGradient/SmoothLinearGradient.swift | 19 ++++++ 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index a64e5ae..440ee96 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -23,7 +23,7 @@ opt_in_rules: - identical_operands - implicit_return - implicitly_unwrapped_optional - # - missing_docs + - missing_docs - number_separator - operator_usage_whitespace - overridden_super_call diff --git a/README.md b/README.md index da65631..0f6b7c9 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ pod 'SmoothGradient', '~> 1.0.0' ## Usage -### Pre-iOS 17 +### Pre-iOS 17/Pre-macOS 14 ```swift import SmoothGradient @@ -41,7 +41,7 @@ import SmoothGradient struct ContentView: View { var body: some View { LinearGradient( - gradient: .smooth(from: .black, to: .white, curve: .easeInOut), + gradient: .smooth(from: .black, to: .white, curve: .easeInOut), // ⬅️ startPoint: .top, endPoint: .bottom ) @@ -49,19 +49,19 @@ struct ContentView: View { } ``` -## iOS 17+ +## iOS 17+/macOS 14+ ```swift import SmoothGradient struct ContentView: View { var body: some View { - SmoothLinearGradient( + SmoothLinearGradient( // ⬅️ from: .black, to: .white, - curve: .easeInOut, startPoint: .top, - endPoint: .bottom + endPoint: .bottom, + curve: .easeInOut ) } } diff --git a/Sources/SmoothGradient/CubicBezierCurve.swift b/Sources/SmoothGradient/CubicBezierCurve.swift index 788d5e1..07f4df6 100644 --- a/Sources/SmoothGradient/CubicBezierCurve.swift +++ b/Sources/SmoothGradient/CubicBezierCurve.swift @@ -26,21 +26,29 @@ public struct CubicBezierCurve: Curve { let b: CGPoint let c: CGPoint + /// A bezier curve that starts out slowly, then speeds up as it finishes. public static let easeIn = CubicBezierCurve( p1: UnitPoint(x: 0.42, y: 0), p2: UnitPoint(x: 1, y: 1) ) + /// A bezier curve that starts out quickly, then slows down as it approaches the end. public static let easeOut = CubicBezierCurve( p1: UnitPoint(x: 0, y: 0), p2: UnitPoint(x: 0.58, y: 1) ) + /// A bezier curve that starts out slowly, speeds up over the middle, then slows down again as it approaches the end. public static let easeInOut = CubicBezierCurve( p1: UnitPoint(x: 0.42, y: 0), p2: UnitPoint(x: 0.58, y: 1) ) + /// Creates a new Cubic Bezier curve with the given control points. + /// + /// - Parameters: + /// - p1: Control point 1. + /// - p2: Control point 2. public init(p1: UnitPoint, p2: UnitPoint) { self.p1 = p1 self.p2 = p2 diff --git a/Sources/SmoothGradient/Gradient+Smooth.swift b/Sources/SmoothGradient/Gradient+Smooth.swift index 4e44746..ac4d9eb 100644 --- a/Sources/SmoothGradient/Gradient+Smooth.swift +++ b/Sources/SmoothGradient/Gradient+Smooth.swift @@ -14,14 +14,14 @@ import SwiftUI #if compiler(>=5.9) extension Gradient { - // Creates a gradient with the given easing function. - // - // - Parameters: - // - from: The start color. - // - to: The end color. - // - curve: The easing function to use. - // - steps: The number of steps to use when generating the gradient. Defaults to 16. - // - Returns: A gradient. + /// Creates a gradient with the given easing function. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - curve: The easing function to use. + /// - steps: The number of steps to use when generating the gradient. Defaults to 16. + /// - Returns: A gradient. @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) public static func smooth( from: Color, @@ -37,14 +37,14 @@ extension Gradient { ) } - // Creates a gradient with the given easing function. - // - // - Parameters: - // - from: The start color. - // - to: The end color. - // - curve: The easing function to use. - // - steps: The number of steps to use when generating the gradient. Defaults to 16. - // - Returns: A gradient. + /// Creates a gradient with the given easing function. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - curve: The easing function to use. + /// - steps: The number of steps to use when generating the gradient. Defaults to 16. + /// - Returns: A gradient. @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) public static func smooth( from: Stop, @@ -65,14 +65,14 @@ extension Gradient { // MARK: - Pre iOS 17 extension Gradient { - // Creates a gradient with the given easing function. - // - // - Parameters: - // - from: The start color. - // - to: The end color. - // - curve: The easing function to use. - // - steps: The number of steps to use when generating the gradient. Defaults to 16. - // - Returns: A gradient. + /// Creates a gradient with the given easing function. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - curve: The easing function to use. + /// - steps: The number of steps to use when generating the gradient. Defaults to 16. + /// - Returns: A gradient. @available(iOS, introduced: 14.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)") @available(macOS, introduced: 11.0, deprecated: 14.0, renamed: "smooth(from:to:curve:steps:)") @available(tvOS, introduced: 14.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)") @@ -92,14 +92,14 @@ extension Gradient { ) } - // Creates a gradient with the given easing function. - // - // - Parameters: - // - from: The start color. - // - to: The end color. - // - curve: The easing function to use. - // - steps: The number of steps to use when generating the gradient. Defaults to 16. - // - Returns: A gradient. + /// Creates a gradient with the given easing function. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - curve: The easing function to use. + /// - steps: The number of steps to use when generating the gradient. Defaults to 16. + /// - Returns: A gradient. @available(iOS, introduced: 14.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)") @available(macOS, introduced: 11.0, deprecated: 14.0, renamed: "smooth(from:to:curve:steps:)") @available(tvOS, introduced: 14.0, deprecated: 17.0, renamed: "smooth(from:to:curve:steps:)") diff --git a/Sources/SmoothGradient/SmoothLinearGradient.swift b/Sources/SmoothGradient/SmoothLinearGradient.swift index 9141fd5..22f4a49 100644 --- a/Sources/SmoothGradient/SmoothLinearGradient.swift +++ b/Sources/SmoothGradient/SmoothLinearGradient.swift @@ -11,6 +11,7 @@ import SwiftUI #if compiler(>=5.9) +/// A smooth linear gradient. @available(iOS 17.0, macOS 14.0, tvOS 17.0, watchOS 10.0, *) public struct SmoothLinearGradient: ShapeStyle, View { let from: Gradient.Stop @@ -20,6 +21,15 @@ public struct SmoothLinearGradient: ShapeStyle, View { let curve: UnitCurve let steps: Int + /// Creates a smooth gradient from two colors. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - startPoint: Origin of the gradient. + /// - endPoint: End point of the gradient. Together with `startPoint` defines the gradient's direction. + /// - curve: Easing curve to use. + /// - steps: Number of steps to use when generating the gradient. Defaults to 16. public init( from: Color, to: Color, @@ -38,6 +48,15 @@ public struct SmoothLinearGradient: ShapeStyle, View { ) } + /// Creates a smooth gradient from two color stops. + /// + /// - Parameters: + /// - from: The start color. + /// - to: The end color. + /// - startPoint: Origin of the gradient. + /// - endPoint: End point of the gradient. Together with `startPoint` defines the gradient's direction. + /// - curve: Easing curve to use. + /// - steps: Number of steps to use when generating the gradient. Defaults to 16. public init( from: Gradient.Stop, to: Gradient.Stop,