forked from Automattic/pocket-casts-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NowPlayingOptions.swift
85 lines (76 loc) · 2.91 KB
/
NowPlayingOptions.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import SwiftUI
struct NowPlayingOptions: View {
@StateObject var viewModel: NowPlayingViewModel
@Binding var presentView: WatchInterfaceType?
@Binding var optionSelected: Bool
var body: some View {
GeometryReader { geo in
VStack(spacing: 5) {
HStack {
NowPlayingOption(iconName: "markasplayed", title: L10n.markPlayedShort) {
viewModel.markPlayed()
optionSelected.toggle()
}
.frame(maxWidth: geo.size.width / 2)
NowPlayingOption(iconName: "episodedetails", title: L10n.watchEpisodeDetails) {
presentView = .episodeDetails
optionSelected.toggle()
}
.frame(maxWidth: geo.size.width / 2)
}
.frame(maxHeight: geo.size.height / 2)
if viewModel.hasChapters {
HStack {
NowPlayingOption(iconName: "prevchapter", title: L10n.watchChapterPrev) {
viewModel.changeChapter(next: false)
optionSelected.toggle()
}
.frame(maxWidth: geo.size.width / 2)
NowPlayingOption(iconName: "nextchapter", title: L10n.watchChapterNext) {
viewModel.changeChapter(next: true)
optionSelected.toggle()
}
.frame(maxWidth: geo.size.width / 2)
}
}
}
.frame(maxHeight: .infinity, alignment: .center)
}
}
}
private struct NowPlayingOption: View {
var iconName: String
var title: String
var action: () -> Void
var body: some View {
Button {
action()
} label: {
VStack(alignment: .center, spacing: 5) {
Image(iconName)
.resizable()
.aspectRatio(1, contentMode: .fit)
.frame(minHeight: 20, maxHeight: 30)
Text(title)
.layoutPriority(1)
.multilineTextAlignment(.center)
.font(.dynamic(size: 13))
.minimumScaleFactor(0.7)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(5)
.background(Color.background)
.clipShape(RoundedRectangle(cornerRadius: 20))
}
.buttonStyle(.plain)
.frame(maxHeight: .infinity)
}
}
struct NowPlayingOptions_Previews: PreviewProvider {
static var previews: some View {
ForEach(PreviewDevice.previewDevices) {
NowPlayingOptions(viewModel: NowPlayingViewModel(), presentView: .constant(nil), optionSelected: .constant(false))
.previewDevice($0)
}
}
}