Skip to content

Commit b9fe9d3

Browse files
committed
Improve splash screen behavior
1 parent e060c6e commit b9fe9d3

3 files changed

Lines changed: 39 additions & 40 deletions

File tree

Demo/Demo/ContentView.swift

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,18 @@ struct ContentView: View {
3333
}
3434
}
3535
}
36-
.navigationTitle("Demo")
36+
.navigationTitle("VideoKit")
3737
.fullScreenCover(item: $selection) { sampleVideo in
3838
videoPlayer(for: sampleVideo)
3939
}
4040
.toolbar {
4141
ToolbarItem(placement: .primaryAction) {
4242
Menu {
43-
Toggle("Launch Video", isOn: $isVideoSplashScreenEnabled)
44-
Section {
43+
Toggle("Splash Video", isOn: $isVideoSplashScreenEnabled)
44+
Section("List") {
4545
Picker("Video Mode", selection: $videoMode) {
46-
Text("Modal Videos").tag(VideoMode.modal)
47-
Text("Inline Videos").tag(VideoMode.inline)
46+
Text("List Videos").tag(VideoMode.modal)
47+
Text("List Previews").tag(VideoMode.inline)
4848
}
4949
}
5050
} label: {
@@ -56,8 +56,7 @@ struct ContentView: View {
5656
}
5757
.task { fetchSampleVideos() }
5858
.videoSplashScreen(
59-
videoURL: videoSplashUrl,
60-
isEnabled: isVideoSplashScreenEnabled,
59+
videoURL: isVideoSplashScreenEnabled ? videoSplashUrl : nil,
6160
configuration: .demo,
6261
videoPlayerView: { videoPlayer in
6362
ZStack {

RELEASE_NOTES.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ Until then, breaking changes can happen in any minor version.
1010

1111
This version bumps the package to Swift 6.1 and the demo app to iOS 26.
1212

13+
### 💡 Adjustments
14+
15+
* `VideoSplashScreenViewModifier` now avoids redrawing the source view.
16+
17+
### 💥 Breaking Changes
18+
19+
* `VideoSplashScreenViewModifier` no longer has an enabled property.
20+
1321

1422

1523
## 0.3

Sources/VideoKit/Splash/VideoSplashScreenViewModifier.swift

Lines changed: 25 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,18 @@ public struct VideoSplashScreenViewModifier<VideoPlayerView: View>: ViewModifier
8686
private extension VideoSplashScreenViewModifier {
8787

8888
@ViewBuilder var playerView: some View {
89-
videoPlayerView(
90-
VideoPlayer(
91-
videoURL: videoURL,
92-
controllerConfiguration: { controller in
93-
controller.showsPlaybackControls = false
94-
},
95-
didPlayToEndAction: dismissSplashScreen
89+
if let videoURL {
90+
videoPlayerView(
91+
VideoPlayer(
92+
videoURL: videoURL,
93+
controllerConfiguration: { controller in
94+
controller.showsPlaybackControls = false
95+
},
96+
didPlayToEndAction: dismissSplashScreen
97+
)
9698
)
97-
)
98-
.ignoresSafeArea()
99+
.ignoresSafeArea()
100+
}
99101
}
100102
}
101103

@@ -139,43 +141,39 @@ public extension VideoSplashScreenConfiguration {
139141

140142
public extension View {
141143

142-
/// Apply a video splash screen that uses a plain ``VideoPlayer`` view.
144+
/// Apply a video splash screen that uses a plain ``VideoPlayer`` view
145+
/// and a standard configuration.
143146
///
144147
/// The splash screen will be presented when the view is loaded and dismiss
145148
/// itself to reveal the underlying view once the video finishes playing.
146149
///
147150
/// - Parameters:
148-
/// - videoURL: The video URL to play.
149-
/// - isEnabled: Whether the splash screen is enabled, by default `true`.
150-
/// - configuration: The configuration to apply, by default ``VideoSplashScreenConfiguration/standard``.
151+
/// - videoURL: The video URL to play, if any.
151152
@ViewBuilder
152153
func videoSplashScreen(videoURL: URL?) -> some View {
153154
self.videoSplashScreen(
154155
videoURL: videoURL,
155-
isEnabled: true,
156156
configuration: nil,
157157
videoPlayerView: { $0 }
158158
)
159159
}
160160

161-
/// Apply a video splash screen that uses a plain ``VideoPlayer`` view.
161+
/// Apply a video splash screen that uses a plain ``VideoPlayer`` view
162+
/// and a custom configuration.
162163
///
163164
/// The splash screen will be presented when the view is loaded and dismiss
164165
/// itself to reveal the underlying view once the video finishes playing.
165166
///
166167
/// - Parameters:
167-
/// - videoURL: The video URL to play.
168-
/// - isEnabled: Whether the splash screen is enabled, by default `true`.
169-
/// - configuration: The configuration to apply, by default ``VideoSplashScreenConfiguration/standard``.
168+
/// - videoURL: The video URL to play, if any.
169+
/// - configuration: The configuration to apply.
170170
@ViewBuilder
171171
func videoSplashScreen(
172172
videoURL: URL?,
173-
isEnabled: Bool = true,
174173
configuration: VideoSplashScreenConfiguration
175174
) -> some View {
176175
self.videoSplashScreen(
177176
videoURL: videoURL,
178-
isEnabled: isEnabled,
179177
configuration: configuration,
180178
videoPlayerView: { $0 }
181179
)
@@ -187,28 +185,22 @@ public extension View {
187185
/// itself to reveal the underlying view once the video finishes playing.
188186
///
189187
/// - Parameters:
190-
/// - videoURL: The video URL to play.
191-
/// - isEnabled: Whether the splash screen is enabled, by default `true`.
188+
/// - videoURL: The video URL to play, if any.
192189
/// - configuration: The configuration to apply, by default ``VideoSplashScreenConfiguration/standard``.
193190
/// - videoPlayerView: A custom video player content builder.
194191
@ViewBuilder
195192
func videoSplashScreen<VideoPlayerView: View>(
196193
videoURL: URL?,
197-
isEnabled: Bool = true,
198194
configuration: VideoSplashScreenConfiguration? = nil,
199195
@ViewBuilder videoPlayerView: @escaping (VideoPlayer) -> VideoPlayerView
200196
) -> some View {
201-
if isEnabled {
202-
self.modifier(
203-
VideoSplashScreenViewModifier(
204-
videoURL: videoURL,
205-
configuration: configuration,
206-
videoPlayerView: videoPlayerView
207-
)
197+
self.modifier(
198+
VideoSplashScreenViewModifier(
199+
videoURL: videoURL,
200+
configuration: configuration,
201+
videoPlayerView: videoPlayerView
208202
)
209-
} else {
210-
self
211-
}
203+
)
212204
}
213205
}
214206

0 commit comments

Comments
 (0)