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 Onboarding gradients #985

Merged
merged 4 commits into from
Sep 12, 2024
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
164 changes: 137 additions & 27 deletions Sources/Onboarding/OnboardingGradient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,52 +24,162 @@ public struct OnboardingGradient: View {
public init() {}

public var body: some View {
if #available(iOS 15, macOS 12, *) {
gradient
} else {
gradientImage
}
}

@available(iOS 15, macOS 12, *)
@ViewBuilder
private var gradient: some View {
switch colorScheme {
case .light:
lightGradient
LightGradient()
case .dark:
darkGradient
DarkGradient()
@unknown default:
lightGradient
LightGradient()
}
}

private var lightGradient: some View {
gradient(colorStops: [
.init(color: Color(red: 1, green: 0.9, blue: 0.87), location: 0.00),
.init(color: Color(red: 0.99, green: 0.89, blue: 0.87), location: 0.28),
.init(color: Color(red: 0.99, green: 0.89, blue: 0.87), location: 0.46),
.init(color: Color(red: 0.96, green: 0.87, blue: 0.87), location: 0.72),
.init(color: Color(red: 0.9, green: 0.84, blue: 0.92), location: 1.00),
])
private var gradientImage: some View {
Image("OnboardingGradient", bundle: bundle)
}
}

private var darkGradient: some View {
gradient(colorStops: [
.init(color: Color(red: 0.29, green: 0.19, blue: 0.25), location: 0.00),
.init(color: Color(red: 0.35, green: 0.23, blue: 0.32), location: 0.28),
.init(color: Color(red: 0.37, green: 0.25, blue: 0.38), location: 0.46),
.init(color: Color(red: 0.2, green: 0.15, blue: 0.32), location: 0.72),
.init(color: Color(red: 0.16, green: 0.15, blue: 0.34), location: 1.00),
])
}
@available(iOS 15, macOS 12, *)
extension OnboardingGradient {

struct LightGradient: View {

init() {}

var body: some View {
ZStack {
// 5th gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.97, green: 0.73, blue: 0.67).opacity(0.5), location: 0.00),
Gradient.Stop(color: .clear, location: 1.00),
],
center: UnitPoint(x: 0.2, y: 0.17),
endRadiusFraction: 1
)

// 4th gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 1, green: 0.91, blue: 0.64).opacity(0.12), location: 0.00),
Gradient.Stop(color: .clear, location: 1.00),
],
center: UnitPoint(x: 0.16, y: 0.86),
endRadiusFraction: 1
)

// 3rd gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.93, green: 0.9, blue: 1).opacity(0.8), location: 0.00),
Gradient.Stop(color: .clear, location: 1.00),
],
center: UnitPoint(x: 0.92, y: 0),
endRadiusFraction: 1
)

// 2nd gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.93, green: 0.9, blue: 1).opacity(0.8), location: 0.00),
Gradient.Stop(color: .clear, location: 1.00),
],
center: UnitPoint(x: 0.89, y: 1.07),
endRadiusFraction: 1
)

private func gradient(colorStops: [SwiftUI.Gradient.Stop]) -> some View {
LinearGradient(
stops: colorStops,
startPoint: UnitPoint(x: 0.5, y: 0),
endPoint: UnitPoint(x: 0.5, y: 1)
)
// 1st gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.8, green: 0.85, blue: 1).opacity(0.58), location: 0.15),
Gradient.Stop(color: .clear, location: 1.00),
],
center: UnitPoint(x: 1.02, y: 0.5),
endRadiusFraction: 1
)
}
.background(.white)
}
}

struct DarkGradient: View {

init() {}

var body: some View {
ZStack {
// 5th Gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0.5), location: 0.00),
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0), location: 1.00),
],
center: UnitPoint(x: 0.2, y: 0.17),
endRadiusFraction: 1
)

// 4th Gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 1, green: 1, blue: 0.54).opacity(0), location: 0.00),
Gradient.Stop(color: Color(red: 1, green: 0.91, blue: 0.64).opacity(0), location: 1.00),
],
center: UnitPoint(x: 0.16, y: 0.86),
endRadiusFraction: 1
)

// 3rd Gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0.8), location: 0.00),
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0), location: 1.00),
],
center: UnitPoint(x: 0.92, y: 0),
endRadiusFraction: 1
)

// 2nd Gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0.8), location: 0.00),
Gradient.Stop(color: Color(red: 0.17, green: 0.08, blue: 0.44).opacity(0), location: 1.00),
],
center: UnitPoint(x: 0.89, y: 1.07),
endRadiusFraction: 1
)

// 1st Gradient
EllipticalGradient(
stops: [
Gradient.Stop(color: Color(red: 0.89, green: 0.44, blue: 0.31).opacity(0.32), location: 0.15),
Gradient.Stop(color: Color(red: 0.89, green: 0.44, blue: 0.31).opacity(0), location: 1.00),
],
center: UnitPoint(x: 1.0, y: 0.5),
endRadiusFraction: 1
)

}
.background(Color(red: 0.07, green: 0.07, blue: 0.07))
}
}
}

#Preview("Light Mode") {
OnboardingGradient()
.preferredColorScheme(.light)
}

#Preview("Dark Mode") {
#Preview("Dark Mode - Elliptical") {
OnboardingGradient()
.preferredColorScheme(.dark)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"filename" : "OnboardingGradient.pdf",
"idiom" : "mac"
},
{
"appearances" : [
{
"appearance" : "luminosity",
"value" : "dark"
}
],
"filename" : "OnboardingGradientDark.pdf",
"idiom" : "mac"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file not shown.
Binary file not shown.
Loading