Skip to content

Commit

Permalink
Support gradient masking for any SwiftUI.View
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnEstropia committed Mar 26, 2024
1 parent c610c1e commit 121e000
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Demo/Demo/BookChange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct BookChange: View, PreviewProvider {
}

private struct Content: View {

@State var count = 0

var body: some View {
Expand All @@ -27,6 +27,13 @@ struct BookChange: View, PreviewProvider {
.onChangeWithPrevious(of: count, emitsInitial: true) { newValue, oldValue in
print("\(newValue), \(oldValue)")
}
.foregroundLinearGradient(
.linearGradient(
colors: [.orange, .blue],
startPoint: .bottom,
endPoint: .bottomTrailing
)
)
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftUISupport/Extensions/View+Gradient.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import SwiftUI

extension Text {
extension View {

/**
[Extension]
*/
public func foregroundLinearGradient(_ gradient: LinearGradient) -> some View {

self
.hidden()
.overlay(
gradient
.aspectRatio(nil, contentMode: .fill)
Expand Down

0 comments on commit 121e000

Please sign in to comment.