-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: added layer background styling
- Loading branch information
1 parent
f6e9502
commit e0e0253
Showing
10 changed files
with
193 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ struct ContentView: View { | |
show.toggle() | ||
} | ||
} | ||
}y | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// | ||
// ButtonStyle+Extensions.swift | ||
// Layers | ||
// | ||
// Created by Raphael Salaja on 02/10/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct ScaleButtonStyle: ButtonStyle { | ||
public init() {} | ||
|
||
public func makeBody(configuration: Self.Configuration) -> some View { | ||
configuration.label | ||
.scaleEffect(configuration.isPressed ? Constants.Scale.pressed : 1) | ||
.transition(.scale(scale: 1.0)) | ||
} | ||
} | ||
|
||
extension ButtonStyle where Self == ScaleButtonStyle { | ||
static var scale: ScaleButtonStyle { | ||
ScaleButtonStyle() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// | ||
// Color+Extensions.swift | ||
// Layers | ||
// | ||
// Created by Raphael Salaja on 02/10/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
extension Color { | ||
|
||
/// Returns a Boolean value indicating whether the color is dark. | ||
var isDark: Bool { | ||
var red: CGFloat = 0 | ||
var green: CGFloat = 0 | ||
var blue: CGFloat = 0 | ||
|
||
guard UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil) | ||
else { | ||
return false | ||
} | ||
|
||
let luminance = | ||
Constants.Luminance.red * red + | ||
Constants.Luminance.green * green + | ||
Constants.Luminance.blue * blue | ||
|
||
return luminance < Constants.Luminance.threshold | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// | ||
// Modifiers+Extensions.swift | ||
// Layers | ||
// | ||
// Created by Raphael Salaja on 02/10/2023. | ||
// | ||
|
||
import SwiftUI | ||
|
||
// MARK: - Transition | ||
|
||
struct SimpleTransition: ViewModifier { | ||
func body(content: Content) -> some View { | ||
content | ||
.transition(.scale(scale: 1.0)) | ||
} | ||
} | ||
|
||
extension View { | ||
func simpleTransition() -> some View { | ||
modifier(SimpleTransition()) | ||
} | ||
} | ||
|
||
// MARK: - Layer | ||
|
||
struct LayerTitleStyle: ViewModifier { | ||
func body(content: Content) -> some View { | ||
content | ||
.font(.system(.title3, design: .rounded, weight: .bold)) | ||
} | ||
} | ||
|
||
struct LayerDescriptionStyle: ViewModifier { | ||
func body(content: Content) -> some View { | ||
content | ||
.font(.system(.headline, design: .rounded, weight: .medium)) | ||
.minimumScaleFactor(0.1) | ||
.foregroundColor(Color(.systemGray)) | ||
} | ||
} | ||
|
||
struct LayerButtonStyle: ViewModifier { | ||
var color: Color | ||
|
||
func body(content: Content) -> some View { | ||
content | ||
.fixedSize() | ||
.font(.body) | ||
.fontWeight(.bold) | ||
.fontDesign(.rounded) | ||
.foregroundColor(color.isDark ? Color.white : Color.black) | ||
} | ||
} | ||
|
||
extension View { | ||
func layerTitleStyle() -> some View { | ||
modifier(LayerTitleStyle()) | ||
} | ||
|
||
func layerDescriptionStyle() -> some View { | ||
modifier(LayerDescriptionStyle()) | ||
} | ||
|
||
func layerButtonStyle(color: Color) -> some View { | ||
modifier(LayerButtonStyle(color: color)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.