-
Notifications
You must be signed in to change notification settings - Fork 11
/
StoriesView.swift
71 lines (62 loc) · 1.89 KB
/
StoriesView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
// Copyright (c) SRG SSR. All rights reserved.
//
// License information is available from the LICENSE file.
//
import AVFoundation
import PillarboxPlayer
import SwiftUI
// Behavior: h-exp, v-exp
private struct StoryView: View {
@ObservedObject var player: Player
@State private var isBusy = false
var body: some View {
ZStack {
VideoView(player: player)
.gravity(.resizeAspectFill)
.ignoresSafeArea()
ProgressView()
.opacity(isBusy ? 1 : 0)
TimeProgress(player: player)
}
.tint(.white)
.animation(.defaultLinear, value: isBusy)
.accessibilityElement()
.accessibilityLabel("Video")
.onReceive(player: player, assign: \.isBusy, to: $isBusy)
}
}
// Behavior: h-exp, v-exp
private struct TimeProgress: View {
let player: Player
@StateObject private var progressTracker = ProgressTracker(interval: CMTime(value: 1, timescale: 10))
var body: some View {
ProgressView(value: progressTracker.progress)
.padding()
.opacity(progressTracker.isProgressAvailable ? 1 : 0)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
.bind(progressTracker, to: player)
}
}
// Behavior: h-exp, v-exp
struct StoriesView: View {
@StateObject private var model = StoriesViewModel(stories: Story.stories(from: MediaList.storyUrns))
var body: some View {
TabView(selection: $model.currentStory) {
ForEach(model.stories) { story in
StoryView(player: model.player(for: story))
.tag(story)
}
}
.background(.black)
.tabViewStyle(.page)
.ignoresSafeArea()
.tracked(name: "stories")
}
}
extension StoriesView: SourceCodeViewable {
static let filePath = #file
}
#Preview {
StoriesView()
}