-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
126 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// Glass.swift | ||
// PrismExample | ||
// | ||
// Created by A. Zheng (github.com/aheze) on 9/26/22. | ||
// Copyright © 2022 A. Zheng. All rights reserved. | ||
// | ||
|
||
import Prism | ||
import SwiftUI | ||
|
||
struct GlassGalleryView: View { | ||
@ObservedObject var model: ViewModel | ||
|
||
var body: some View { | ||
GalleryCardView(model: model, kind: .glass) { | ||
PrismGlassView( | ||
tilt: model.configuration.tilt, | ||
size: model.configuration.size, | ||
extrusion: model.configuration.extrusion, | ||
levitation: model.configuration.levitation, | ||
shadowColor: model.configuration.shadowColor, | ||
shadowOpacity: model.configuration.shadowOpacity, | ||
color: .blue, | ||
opacity: 0.5 | ||
) | ||
} | ||
} | ||
} | ||
|
||
struct GlassDetailView: View { | ||
@State var color = Color.blue | ||
@State var opacity = CGFloat(0.5) | ||
var body: some View { | ||
DetailView { configuration in | ||
PrismGlassView( | ||
tilt: configuration.tilt, | ||
size: configuration.size, | ||
extrusion: configuration.extrusion, | ||
levitation: configuration.levitation, | ||
shadowColor: configuration.shadowColor, | ||
shadowOpacity: configuration.shadowOpacity, | ||
color: color, | ||
opacity: opacity | ||
) | ||
} controls: { | ||
ExampleColorView(title: "Color", value: $color) | ||
ExampleSliderView(title: "Opacity", value: $opacity, range: 0 ... 1) | ||
} | ||
.navigationTitle("Glass") | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// PrismGlassView.swift | ||
// Prism | ||
// | ||
// Created by A. Zheng (github.com/aheze) on 9/26/22. | ||
// Copyright © 2022 A. Zheng. All rights reserved. | ||
// | ||
|
||
import SwiftUI | ||
|
||
public struct PrismGlassView: View { | ||
var configuration: PrismConfiguration | ||
var color: Color | ||
var opacity: CGFloat | ||
|
||
public init( | ||
configuration: PrismConfiguration, | ||
color: Color, | ||
opacity: CGFloat | ||
) { | ||
self.configuration = configuration | ||
self.color = color | ||
self.opacity = opacity | ||
} | ||
|
||
public var body: some View { | ||
PrismView(configuration: configuration) { | ||
color | ||
.opacity(opacity - 0.2) | ||
} left: { | ||
color.brightness(-0.1) | ||
.opacity(opacity - 0.1) | ||
} right: { | ||
color.brightness(-0.3) | ||
.opacity(opacity) | ||
} | ||
} | ||
} | ||
|
||
public extension PrismGlassView { | ||
init( | ||
tilt: CGFloat, | ||
size: CGSize, | ||
extrusion: CGFloat, | ||
levitation: CGFloat = CGFloat(0), | ||
shadowColor: SwiftUI.Color = Color.black, | ||
shadowOpacity: CGFloat = CGFloat(0.25), | ||
color: Color, | ||
opacity: CGFloat | ||
) { | ||
let configuration = PrismConfiguration( | ||
tilt: tilt, | ||
size: size, | ||
extrusion: extrusion, | ||
levitation: levitation, | ||
shadowColor: shadowColor, | ||
shadowOpacity: shadowOpacity | ||
) | ||
self.configuration = configuration | ||
self.color = color | ||
self.opacity = opacity | ||
} | ||
} |