yattee/Shared/Views/BrowserPlayerControls.swift

80 lines
2.2 KiB
Swift
Raw Normal View History

import Foundation
import SDWebImageSwiftUI
import SwiftUI
2022-02-16 20:23:11 +00:00
struct BrowserPlayerControls<Content: View, Toolbar: View>: View {
enum Context {
case browser, player
}
let content: Content
2022-06-24 23:39:29 +00:00
let toolbar: Toolbar?
init(
context _: Context? = nil,
@ViewBuilder toolbar: @escaping () -> Toolbar? = { nil },
@ViewBuilder content: @escaping () -> Content
) {
self.content = content()
2022-06-24 23:39:29 +00:00
self.toolbar = toolbar()
2022-02-04 17:38:29 +00:00
}
init(
context: Context? = nil,
@ViewBuilder content: @escaping () -> Content
) where Toolbar == EmptyView {
self.init(context: context, toolbar: { EmptyView() }, content: content)
}
var body: some View {
#if os(tvOS)
return content
#else
// TODO: remove
#if DEBUG
if #available(iOS 15.0, macOS 12.0, *) {
Self._printChanges()
}
#endif
return ZStack(alignment: .bottomLeading) {
content
.frame(maxHeight: .infinity)
#if !os(tvOS)
VStack(spacing: 0) {
#if os(iOS)
toolbar
.frame(height: 35)
.frame(maxWidth: .infinity)
.borderTop(height: 0.4, color: Color("ControlsBorderColor"))
.modifier(ControlBackgroundModifier())
#endif
2022-06-30 20:18:59 +00:00
ControlsBar(fullScreen: .constant(false))
.edgesIgnoringSafeArea(.bottom)
}
#endif
}
#endif
}
}
struct PlayerControlsView_Previews: PreviewProvider {
static var previews: some View {
2022-06-30 07:51:44 +00:00
BrowserPlayerControls(context: .player, toolbar: {
Button("Button") {}
}) {
BrowserPlayerControls {
VStack {
Spacer()
2022-06-30 07:51:44 +00:00
TextField("A", text: .constant("abc"))
Spacer()
}
}
.offset(y: -100)
}
.injectFixtureEnvironmentObjects()
}
}