Skip to content

Commit 26e1e6f

Browse files
authored
Merge pull request #28 from mtj0928/fix-foreground-color
Fix foreground color and fix iOS's app structure
2 parents fb055ed + ce593f7 commit 26e1e6f

File tree

7 files changed

+56
-22
lines changed

7 files changed

+56
-22
lines changed

SlideKitDemo-iOS/SlideKitDemo-iOS/SceneDelegate.swift

+7-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,13 @@ final class SceneDelegate: NSObject, SlideWindowSceneDelegate {
2020

2121
var window: UIWindow?
2222

23-
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
24-
guard let windowScene = (scene as? UIWindowScene) else { return }
25-
26-
if session.role == .externalDisplay && Self.externalDisplayManager.externalDisplayMode == .mirroring {
27-
return
28-
}
23+
var content: some View {
24+
SlideRouterView(slideIndexController: Self.slideIndexController)
25+
.background(.white)
26+
.foregroundColor(.black)
27+
}
2928

30-
self.window = makeRootWindow(
31-
windowScene: windowScene,
32-
slidePresentationMode: session.role == .externalDisplay ? .presentation : .presenter
33-
)
29+
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
30+
setup(scene, willConnectTo: session, options: connectionOptions)
3431
}
3532
}

SlideKitDemo-iOS/SlideKitDemo-iOS/Slides/BasicSlide.swift

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct BasicSlide: Slide {
1919
HStack {
2020
Text("Hoge")
2121
Circle()
22+
.frame(width: 50, height: 50)
2223
}
2324
} child: {
2425
Item("AAA")

SlideKitDemo-macOS/SlideKitDemo-macOS/SlideKitDemo_macOSApp.swift

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ struct SlideKitDemo_macOSApp: App {
1919
var presentationContentView: some View {
2020
SlideRouterView(slideIndexController: Self.configuration.slideIndexController)
2121
.slideTheme(Self.configuration.theme)
22+
.foregroundColor(.black) // Edit this color if you want to use another color for text color.
2223
.background(.white)
2324
}
2425

SlideKitDemo-macOS/SlideKitDemo-macOS/Slides/CustomHeaderStyleSlide.swift

+2-3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ struct CustomHeaderStyle: HeaderSlideStyle {
3737
}
3838
VStack(alignment: .leading, spacing: 48) {
3939
configuration.content
40+
.font(.system(size: 48))
4041
}
4142
.padding()
4243
}
@@ -62,16 +63,14 @@ struct CustomItemStyle: ItemStyle {
6263
case nil: EmptyView()
6364
}
6465
}
65-
.font(.system(size: configuration.fontSize))
6666

6767
configuration.label
68-
.font(.system(size: configuration.fontSize))
6968
.fixedSize()
7069
}
7170

7271

7372
if let child = configuration.child {
74-
child.padding(.leading, configuration.fontSize)
73+
child.padding(.leading)
7574
}
7675
}
7776
}

Sources/SlideKit/SlideWindowSceneDelegate.swift

+45-7
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ import SwiftUI
1010
import UIKit
1111

1212
public protocol SlideWindowSceneDelegate where Self: UIWindowSceneDelegate {
13+
associatedtype SlideContent: View
1314
var window: UIWindow? { get set }
15+
var content: SlideContent { get }
16+
1417
static var slideSize: CGSize { get }
1518
static var slideIndexController: SlideIndexController { get }
1619
static var externalDisplayManager: ExternalDisplayManager { get }
@@ -19,6 +22,22 @@ public protocol SlideWindowSceneDelegate where Self: UIWindowSceneDelegate {
1922
func rootView(for presentationMode: SlidePresentationMode) -> AnyView
2023
}
2124

25+
extension SlideWindowSceneDelegate {
26+
27+
public func setup(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
28+
guard let windowScene = (scene as? UIWindowScene) else { return }
29+
30+
if session.role == .externalDisplay && Self.externalDisplayManager.externalDisplayMode == .mirroring {
31+
return
32+
}
33+
34+
self.window = makeRootWindow(
35+
windowScene: windowScene,
36+
slidePresentationMode: session.role == .externalDisplay ? .presentation : .presenter
37+
)
38+
}
39+
}
40+
2241
extension SlideWindowSceneDelegate {
2342
func startMirroring() {
2443
guard self.window?.windowScene?.session.role == .externalDisplay else {
@@ -49,17 +68,38 @@ extension SlideWindowSceneDelegate {
4968
slideSize: Self.slideSize,
5069
slideIndexController: Self.slideIndexController,
5170
externalDisplayManager: Self.externalDisplayManager
52-
53-
))
71+
) { [weak self] in
72+
if let self {
73+
self.content
74+
} else {
75+
Text("failed to cast self")
76+
}
77+
})
5478
}
5579
}
5680

57-
public struct _RootView: View {
81+
public struct _RootView<Content: View>: View {
5882
let presentationMode: SlidePresentationMode
5983
let slideSize: CGSize
6084
let slideIndexController: SlideIndexController
6185
let externalDisplayManager: ExternalDisplayManager
6286

87+
let content: () -> Content
88+
89+
init(
90+
presentationMode: SlidePresentationMode,
91+
slideSize: CGSize,
92+
slideIndexController: SlideIndexController,
93+
externalDisplayManager: ExternalDisplayManager,
94+
@ViewBuilder content: @escaping () -> Content
95+
) {
96+
self.presentationMode = presentationMode
97+
self.slideSize = slideSize
98+
self.slideIndexController = slideIndexController
99+
self.externalDisplayManager = externalDisplayManager
100+
self.content = content
101+
}
102+
63103
public var body: some View {
64104
switch presentationMode {
65105
case .presenter:
@@ -68,13 +108,11 @@ public struct _RootView: View {
68108
slideIndexController: slideIndexController,
69109
externalDisplayManager: externalDisplayManager
70110
) {
71-
SlideRouterView(slideIndexController: slideIndexController)
72-
.background(.white)
111+
content()
73112
}
74113
case .presentation:
75114
PresentationView(slideSize: slideSize) {
76-
SlideRouterView(slideIndexController: slideIndexController)
77-
.background(.white)
115+
content()
78116
}
79117
}
80118
}

Sources/SlideKit/Views/PresentationView.swift

-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ public struct PresentationView<Content>: View where Content: View {
4242
#endif
4343

4444
}
45-
.preferredColorScheme(.light)
4645
.ignoresSafeArea()
4746
#if os(macOS)
4847
.configureWindow { window in

Sources/SlideKit/Views/SlideRouterView.swift

-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public struct SlideRouterView: View {
2929
forward: { slideIndexController.forward() }
3030
)
3131
.environment(\.slideIndexController, slideIndexController)
32-
.foregroundColor(.black)
3332
}
3433
}
3534

0 commit comments

Comments
 (0)