Skip to content

Commit 72b630e

Browse files
authored
Merge pull request #32 from mtj0928/fix-preview
fix API
2 parents 4e840a9 + 6476766 commit 72b630e

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Sources/SlideKit/SlideComponents/Code/Code.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ struct Code_Previews: PreviewProvider {
4242
.lineSpacing(12)
4343
}
4444
}
45-
.previewSlideBackgroundColor(SwiftUI.Color(red: 42 / 255, green: 42 / 255, blue: 48 / 255))
45+
.previewColor(background: SwiftUI.Color(red: 42 / 255, green: 42 / 255, blue: 48 / 255))
4646
}
4747

4848
private static var code: String {

Sources/SlideKit/Views/Previews/SlidePreview.swift

+21-6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public struct SlidePreview: View {
1313
@ObservedObject
1414
private var slideIndexController: SlideIndexController
1515

16+
@Environment(\.previewForegroundColor)
17+
private var foregroundColor: Color
18+
1619
@Environment(\.previewBackgroundColor)
1720
private var backgroundColor: Color
1821

@@ -28,24 +31,36 @@ public struct SlidePreview: View {
2831
SlideRouterView(slideIndexController: slideIndexController)
2932
.background(backgroundColor)
3033
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading)
31-
.foregroundColor(.black)
34+
.foregroundColor(foregroundColor)
3235
}
3336
.ignoresSafeArea()
3437
.aspectRatio(slideSize, contentMode: .fit)
3538
}
3639

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)
3943
}
4044
}
4145

42-
private enum Key: EnvironmentKey {
46+
private enum PreviewBackgroundColorKey: EnvironmentKey {
4347
static let defaultValue = Color.white
4448
}
4549

4650
extension EnvironmentValues {
4751
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 }
5065
}
5166
}

0 commit comments

Comments
 (0)