mirror of
https://github.com/JohnEstropia/CoreStore.git
synced 2026-09-09 19:31:58 +02:00
106 lines
2.7 KiB
Swift
106 lines
2.7 KiB
Swift
//
|
|
// Demo
|
|
// Copyright © 2020 John Rommel Estropia, Inc. All rights reserved.
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
|
|
// MARK: - Menu
|
|
|
|
extension Menu {
|
|
|
|
// MARK: - Menu.MainView
|
|
|
|
struct MainView: View {
|
|
|
|
@Environment(\.horizontalSizeClass)
|
|
private var horizontalSizeClass
|
|
|
|
// MARK: View
|
|
|
|
@ViewBuilder
|
|
var body: some View {
|
|
|
|
if self.horizontalSizeClass == .compact {
|
|
NavigationStack {
|
|
|
|
self.menuList
|
|
}
|
|
}
|
|
else {
|
|
NavigationSplitView(
|
|
sidebar: {
|
|
|
|
self.menuList
|
|
},
|
|
detail: {
|
|
|
|
Menu.PlaceholderView()
|
|
}
|
|
)
|
|
}
|
|
}
|
|
|
|
|
|
// MARK: Private
|
|
|
|
@ViewBuilder
|
|
private var menuList: some View {
|
|
List {
|
|
|
|
ForEach(Menu.Section.allCases, id: \.self) { section in
|
|
|
|
SwiftUI::Section(
|
|
content: {
|
|
|
|
ForEach(section.routes) { route in
|
|
|
|
NavigationLink(
|
|
destination: {
|
|
LazyDestination {
|
|
route.destination
|
|
}
|
|
},
|
|
label: {
|
|
Menu.ItemView(
|
|
title: route.title,
|
|
subtitle: route.subtitle,
|
|
isEnabled: route.isEnabled
|
|
)
|
|
}
|
|
)
|
|
.disabled(!route.isEnabled)
|
|
}
|
|
},
|
|
header: {
|
|
|
|
Text(section.rawValue)
|
|
}
|
|
)
|
|
}
|
|
}
|
|
.navigationTitle("CoreStore Demos")
|
|
.listStyle(.sidebar)
|
|
}
|
|
|
|
|
|
// MARK: - LazyDestination
|
|
|
|
private struct LazyDestination<Content: View>: View {
|
|
|
|
init(@ViewBuilder content: @escaping () -> Content) {
|
|
|
|
self.content = content
|
|
}
|
|
|
|
var body: some View {
|
|
|
|
self.content()
|
|
}
|
|
|
|
private let content: () -> Content
|
|
}
|
|
}
|
|
}
|