@@ -10,7 +10,10 @@ import SwiftUI
10
10
import UIKit
11
11
12
12
public protocol SlideWindowSceneDelegate where Self: UIWindowSceneDelegate {
13
+ associatedtype SlideContent : View
13
14
var window : UIWindow ? { get set }
15
+ var content : SlideContent { get }
16
+
14
17
static var slideSize : CGSize { get }
15
18
static var slideIndexController : SlideIndexController { get }
16
19
static var externalDisplayManager : ExternalDisplayManager { get }
@@ -19,6 +22,22 @@ public protocol SlideWindowSceneDelegate where Self: UIWindowSceneDelegate {
19
22
func rootView( for presentationMode: SlidePresentationMode ) -> AnyView
20
23
}
21
24
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
+
22
41
extension SlideWindowSceneDelegate {
23
42
func startMirroring( ) {
24
43
guard self . window? . windowScene? . session. role == . externalDisplay else {
@@ -49,17 +68,38 @@ extension SlideWindowSceneDelegate {
49
68
slideSize: Self . slideSize,
50
69
slideIndexController: Self . slideIndexController,
51
70
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
+ } )
54
78
}
55
79
}
56
80
57
- public struct _RootView : View {
81
+ public struct _RootView < Content : View > : View {
58
82
let presentationMode : SlidePresentationMode
59
83
let slideSize : CGSize
60
84
let slideIndexController : SlideIndexController
61
85
let externalDisplayManager : ExternalDisplayManager
62
86
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
+
63
103
public var body : some View {
64
104
switch presentationMode {
65
105
case . presenter:
@@ -68,13 +108,11 @@ public struct _RootView: View {
68
108
slideIndexController: slideIndexController,
69
109
externalDisplayManager: externalDisplayManager
70
110
) {
71
- SlideRouterView ( slideIndexController: slideIndexController)
72
- . background ( . white)
111
+ content ( )
73
112
}
74
113
case . presentation:
75
114
PresentationView ( slideSize: slideSize) {
76
- SlideRouterView ( slideIndexController: slideIndexController)
77
- . background ( . white)
115
+ content ( )
78
116
}
79
117
}
80
118
}
0 commit comments