@@ -13,6 +13,9 @@ public struct SlidePreview: View {
13
13
@ObservedObject
14
14
private var slideIndexController : SlideIndexController
15
15
16
+ @Environment ( \. previewForegroundColor)
17
+ private var foregroundColor : Color
18
+
16
19
@Environment ( \. previewBackgroundColor)
17
20
private var backgroundColor : Color
18
21
@@ -28,24 +31,36 @@ public struct SlidePreview: View {
28
31
SlideRouterView ( slideIndexController: slideIndexController)
29
32
. background ( backgroundColor)
30
33
. frame ( maxWidth: . infinity, maxHeight: . infinity, alignment: . topLeading)
31
- . foregroundColor ( . black )
34
+ . foregroundColor ( foregroundColor )
32
35
}
33
36
. ignoresSafeArea ( )
34
37
. aspectRatio ( slideSize, contentMode: . fit)
35
38
}
36
39
37
- public func previewSlideBackgroundColor( _ color: Color ) -> some View {
38
- self . environment ( \. previewBackgroundColor, color)
40
+ public func previewColor( foreground: Color = . black, background: Color = . white) -> some View {
41
+ self . environment ( \. previewBackgroundColor, background)
42
+ . environment ( \. previewForegroundColor, foreground)
39
43
}
40
44
}
41
45
42
- private enum Key : EnvironmentKey {
46
+ private enum PreviewBackgroundColorKey : EnvironmentKey {
43
47
static let defaultValue = Color . white
44
48
}
45
49
46
50
extension EnvironmentValues {
47
51
fileprivate var previewBackgroundColor : Color {
48
- get { self [ Key . self] }
49
- set { self [ Key . self] = newValue }
52
+ get { self [ PreviewBackgroundColorKey . self] }
53
+ set { self [ PreviewBackgroundColorKey . self] = newValue }
54
+ }
55
+ }
56
+
57
+ private enum PreviewForegroundColorKey : EnvironmentKey {
58
+ static let defaultValue = Color . black
59
+ }
60
+
61
+ extension EnvironmentValues {
62
+ fileprivate var previewForegroundColor : Color {
63
+ get { self [ PreviewForegroundColorKey . self] }
64
+ set { self [ PreviewForegroundColorKey . self] = newValue }
50
65
}
51
66
}
0 commit comments