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