2021-10-18 11:13:04 -07:00
|
|
|
//
|
2021-10-18 13:13:25 -07:00
|
|
|
// ScreenBackground.swift
|
2021-10-18 11:13:04 -07:00
|
|
|
// secant-testnet
|
|
|
|
//
|
|
|
|
// Created by Francisco Gindre on 10/18/21.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
2021-12-13 12:50:04 -08:00
|
|
|
|
|
|
|
/// A Vertical LinearGradient that takes an array of Colors and renders them vertically
|
|
|
|
/// in a centered fashion mostly used as a background for Screen views..
|
2021-10-18 12:45:57 -07:00
|
|
|
struct ScreenBackground: View {
|
2021-12-13 12:50:04 -08:00
|
|
|
var colors: [Color]
|
|
|
|
|
2021-10-18 11:13:04 -07:00
|
|
|
var body: some View {
|
|
|
|
LinearGradient(
|
|
|
|
colors: colors,
|
|
|
|
startPoint: UnitPoint(x: 0.5, y: 0),
|
|
|
|
endPoint: UnitPoint(x: 0.5, y: 1)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-18 06:06:17 -08:00
|
|
|
extension ScreenBackground {
|
|
|
|
static let `default` = ScreenBackground(
|
|
|
|
colors: [
|
|
|
|
Asset.Colors.ScreenBackground.gradientStart.color,
|
|
|
|
Asset.Colors.ScreenBackground.gradientEnd.color
|
|
|
|
]
|
|
|
|
)
|
|
|
|
}
|
2021-10-18 12:45:57 -07:00
|
|
|
struct ScreenBackgroundModifier: ViewModifier {
|
2021-12-13 12:50:04 -08:00
|
|
|
var colors: [Color]
|
|
|
|
|
2021-10-18 11:13:04 -07:00
|
|
|
func body(content: Content) -> some View {
|
|
|
|
ZStack {
|
2021-12-13 12:50:04 -08:00
|
|
|
ScreenBackground(colors: colors)
|
2021-10-18 11:13:04 -07:00
|
|
|
.edgesIgnoringSafeArea(.all)
|
2021-12-13 12:50:04 -08:00
|
|
|
|
2021-10-18 11:13:04 -07:00
|
|
|
content
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension View {
|
2021-12-13 12:50:04 -08:00
|
|
|
/// Adds a Vertical Linear Gradient with the default Colors of VLinearGradient.
|
|
|
|
/// Supports both Light and Dark Mode
|
2021-10-18 12:45:57 -07:00
|
|
|
func applyScreenBackground() -> some View {
|
2021-10-18 11:13:04 -07:00
|
|
|
self.modifier(
|
2021-12-13 12:50:04 -08:00
|
|
|
ScreenBackgroundModifier(
|
|
|
|
colors: [
|
|
|
|
Asset.Colors.ScreenBackground.gradientStart.color,
|
|
|
|
Asset.Colors.ScreenBackground.gradientEnd.color
|
|
|
|
]
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
func applyErredScreenBackground() -> some View {
|
|
|
|
self.modifier(
|
|
|
|
ScreenBackgroundModifier(
|
|
|
|
colors: [
|
|
|
|
Asset.Colors.ScreenBackground.redGradientStart.color,
|
|
|
|
Asset.Colors.ScreenBackground.redGradientEnd.color
|
|
|
|
]
|
|
|
|
)
|
2021-10-18 11:13:04 -07:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-18 13:13:25 -07:00
|
|
|
struct ScreenBackground_Previews: PreviewProvider {
|
2021-10-18 11:13:04 -07:00
|
|
|
static var previews: some View {
|
|
|
|
VStack {
|
|
|
|
Text("Hello")
|
|
|
|
}
|
2021-10-18 12:45:57 -07:00
|
|
|
.applyScreenBackground()
|
2021-10-18 11:13:04 -07:00
|
|
|
.preferredColorScheme(.light)
|
|
|
|
}
|
|
|
|
}
|