Files
Pulse/Sources/PulseUI/Views/NotSplitView.swift
2022-08-07 20:52:47 -04:00

48 lines
1.4 KiB
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// The MIT License (MIT)
//
// Copyright (c) 20202022 Alexander Grebenyuk (github.com/kean).
import SwiftUI
import CoreData
import Pulse
import Combine
#if os(macOS)
struct NotSplitView: View, NSViewControllerRepresentable {
private let views: [AnyView]
private let isPanelOneCollaped: Bool
private let isPanelTwoCollaped: Bool
private let isVertical: Bool
init<V1: View, V2: View>(
_ v1: V1,
_ v2: V2,
isPanelOneCollaped: Bool = false,
isPanelTwoCollaped: Bool = false,
isVertical: Bool
) {
self.views = [AnyView(v1), AnyView(v2)]
self.isPanelOneCollaped = isPanelOneCollaped
self.isPanelTwoCollaped = isPanelTwoCollaped
self.isVertical = isVertical
}
func makeNSViewController(context: Context) -> NSSplitViewController {
let vc = NSSplitViewController()
vc.splitViewItems = views.map {
NSSplitViewItem(viewController: NSHostingController(rootView: $0))
}
vc.splitView.setHoldingPriority(.defaultHigh, forSubviewAt: 1)
return vc
}
func updateNSViewController(_ nsViewController: NSSplitViewController, context: Context) {
nsViewController.splitView.isVertical = isVertical
nsViewController.splitViewItems[0].isCollapsed = isPanelOneCollaped
nsViewController.splitViewItems[1].isCollapsed = isPanelTwoCollaped
}
}
#endif