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

Update docs #4

Merged
merged 3 commits into from
Aug 5, 2023
Merged
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
2 changes: 1 addition & 1 deletion .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,35 +33,35 @@ pod 'SmoothGradient', '~> 1.0.0'

## Usage

### Pre-iOS 17
### Pre-iOS 17/Pre-macOS 14

```swift
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
)
}
}
```

## 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
)
}
}
Expand Down
8 changes: 8 additions & 0 deletions Sources/SmoothGradient/CubicBezierCurve.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
64 changes: 32 additions & 32 deletions Sources/SmoothGradient/Gradient+Smooth.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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:)")
Expand All @@ -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:)")
Expand Down
19 changes: 19 additions & 0 deletions Sources/SmoothGradient/SmoothLinearGradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down