mycode/myApp/HaruDanim/IOS/Views/SidebarRootView.swift
songyc macbook 9e81cd3d03 feat: auto-adapt layout for iPadOS/macOS with NavigationSplitView and hide irrelevant settings
- Add SidebarRootView: iPad/Mac (Designed for iPad) uses a NavigationSplitView
  sidebar listing all 7 tabs, sharing every existing screen (rootView) untouched
- Branch by device idiom (DeviceLayout.isPad) so iPhone keeps its tab bar UI,
  logic, and Live Activity behavior pixel-for-pixel, including landscape
- AppRouter gains sidebar mode: cross-tab routing (기록 확인/통계 보기) selects
  the target tab directly instead of detouring through the More tab
- Hide iPhone-only settings on iPad/Mac: 탭바 구성 section and the main grid's
  per-row column picker are meaningless with a sidebar/adaptive grid
- Main tab wide-screen layout: pinned goal cards flow in an adaptive grid
  (340-520pt cards) instead of full-width paging; action buttons auto-fill
  columns at 150-220pt so nothing stretches on large displays
- Verified on iPad Pro 11" simulator (sidebar, settings, stats routing,
  timetable) and iPhone 17 Pro (unchanged tab bar); both build clean

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013yKDMhuF39GVYy3FMcGHh7
2026-07-11 09:28:06 +09:00

80 lines
2.4 KiB
Swift

//
// SidebarRootView.swift
// Haru_Danim
//
// iPad · Mac(Designed for iPad) .
// iPhone MainTabView (rootView) NavigationSplitView .
// iPhone UI/ .
//
import SwiftUI
import SwiftData
import UIKit
/// (iPad, Mac Designed for iPad) .
/// iPhone( ) UI .
enum DeviceLayout {
static let isPad = UIDevice.current.userInterfaceIdiom == .pad
}
struct SidebarRootView: View {
@State private var router: AppRouter
init() {
let router = AppRouter()
router.usesSidebar = true
_router = State(initialValue: router)
}
private var selectedTab: AppTab {
AppTab(rawValue: router.tabSelection) ?? .main
}
/// (String)
private var sidebarSelection: Binding<AppTab?> {
Binding {
AppTab(rawValue: router.tabSelection) ?? .main
} set: { newValue in
if let newValue {
router.tabSelection = newValue.rawValue
}
}
}
var body: some View {
NavigationSplitView {
List(selection: sidebarSelection) {
Section {
ForEach(AppTab.allCases) { tab in
Label {
Text(tab.label)
} icon: {
Image(systemName: tab.symbol)
.foregroundStyle(AppTheme.green)
}
.tag(tab)
}
}
}
.listStyle(.sidebar)
.navigationTitle("하루 다님")
.navigationSplitViewColumnWidth(min: 190, ideal: 230, max: 300)
} detail: {
NavigationStack {
selectedTab.rootView
}
//
.id(selectedTab)
}
.environment(router)
}
}
#Preview {
SidebarRootView()
.modelContainer(for: [
Tag.self, Action.self, TimeSession.self,
CountEntry.self, Goal.self, Quest.self,
], inMemory: true)
}