1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Views/BrowserPlayerControls.swift

73 lines
2.0 KiB
Swift
Raw Normal View History

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