mycode/myApp/HaruDanim/IOS/Views/RadialNavigationView.swift
songyc macbook 8f2b5fab93 feat(nav): add experimental iPhone radial floating navigation menu
Adds an alternative iPhone navigation style, switchable in Settings, that
replaces the bottom tab bar with a single center floating button which fans
all tabs out into an upper 180° semicircle.

- Settings → 내비게이션: pick 기본 하단 탭 바 / 중앙 플로팅 반원 메뉴.
  Stored device-local via @AppStorage(SettingsKeys.navStyle) (not synced);
  the 탭바 구성 section auto-hides in radial mode since all tabs are shown.
- iPhone (Compact) only: RootNavigationView branches on NavStyle. iPad/Mac
  sidebar and the watch target are untouched.
- Radial menu (RadialNavigationView): glass FAB at bottom-center over a
  tab-bar-hidden TabView (per-tab navigation state preserved). Tapping the
  FAB blooms all 7 tabs into an upper 180° arc with per-icon name labels;
  tapping an icon routes immediately and closes; tapping the FAB or the
  dimming scrim closes. Current tab is highlighted.
- Drops the 더보기 indirection in radial mode via AppRouter.allTabsDirect,
  so cross-tab routing (openHistory/openStats) selects tabs directly.
- Liquid Glass (.ultraThinMaterial) styling on the FAB, icons and labels.
- Overlay is kept top-most in the ZStack with hit-testing gated to the
  expanded state, so scrolling grid content can never intercept the button.
- DEBUG: -navStyle radial / -radialExpanded YES launch args for simulator
  verification (no way to tap widgets/overlays via simctl).

Scope: iPhone navigation only; no changes to iPad/Mac sidebar, the watch
app, core data/models, or widget code.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013yKDMhuF39GVYy3FMcGHh7
2026-07-12 09:01:50 +09:00

231 lines
9.1 KiB
Swift

//
// RadialNavigationView.swift
// Haru_Danim
//
// [] iPhone (Radial) ( ).
//
// :
// - TabView 7 ·
// ( FAB ),
// - (ZStack ) .
// FAB/ · .
//
// iPhone(Compact) iPad·Mac SidebarRootView, watch .
//
import SwiftUI
// MARK: -
struct RadialTabView: View {
@State private var router: AppRouter
@State private var menuExpanded = false
init() {
let router = AppRouter()
// '' .
router.allTabsDirect = true
_router = State(initialValue: router)
#if DEBUG
// : -radialExpanded YES ( )
if UserDefaults.standard.bool(forKey: "radialExpanded") {
_menuExpanded = State(initialValue: true)
}
#endif
}
var body: some View {
ZStack {
// 1) TabView .
TabView(selection: $router.tabSelection) {
ForEach(AppTab.allCases) { tab in
Tab(tab.label, systemImage: tab.symbol, value: tab.rawValue) {
NavigationStack {
tab.rootView
}
.toolbar(.hidden, for: .tabBar)
}
}
}
// 2) . collapsed FAB .
RadialMenu(
expanded: $menuExpanded,
selection: $router.tabSelection
)
}
.environment(router)
}
}
// MARK: -
struct RadialMenu: View {
@Binding var expanded: Bool
/// AppTab.rawValue ( tabSelection )
@Binding var selection: String
//
private let fabSize: CGFloat = 62
private let itemSize: CGFloat = 52
private let desiredRadius: CGFloat = 150
private let bottomInset: CGFloat = 42
private let edgePadding: CGFloat = 18
/// ( )
private let labelOffset: CGFloat = 40
private var tabs: [AppTab] { AppTab.allCases }
private var currentTab: AppTab {
AppTab(rawValue: selection) ?? .main
}
var body: some View {
GeometryReader { geo in
//
let radius = min(desiredRadius, geo.size.width / 2 - itemSize / 2 - edgePadding)
ZStack {
// . .
Color.black
.opacity(expanded ? 0.22 : 0)
.ignoresSafeArea()
.allowsHitTesting(expanded)
.onTapGesture { close() }
// FAB( ) .
ZStack {
ForEach(Array(tabs.enumerated()), id: \.element.id) { index, tab in
arcItem(tab, index: index, count: tabs.count, radius: radius)
}
fab
}
.frame(width: fabSize, height: fabSize)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.padding(.bottom, bottomInset)
}
}
.ignoresSafeArea(.keyboard)
}
// MARK:
private var fab: some View {
Button {
toggle()
} label: {
ZStack {
Circle()
.fill(.ultraThinMaterial)
.overlay(Circle().strokeBorder(.white.opacity(0.18), lineWidth: 1))
.overlay(
Circle().fill(AppTheme.green.opacity(expanded ? 0.0 : 0.14))
)
Image(systemName: expanded ? "xmark" : currentTab.symbol)
.font(.system(size: expanded ? 22 : 24, weight: .semibold))
.foregroundStyle(AppTheme.green)
.rotationEffect(.degrees(expanded ? 90 : 0))
.contentTransition(.symbolEffect(.replace))
}
.frame(width: fabSize, height: fabSize)
.shadow(color: .black.opacity(0.22), radius: 10, y: 4)
}
.buttonStyle(RadialPressStyle())
.accessibilityLabel(expanded ? Text("메뉴 닫기") : Text("탭 메뉴 열기"))
}
// MARK:
private func arcItem(_ tab: AppTab, index: Int, count: Int, radius: CGFloat) -> some View {
// (180°) (90°) (0°)
let t = count > 1 ? Double(index) / Double(count - 1) : 0.5
let angle = Double.pi - t * Double.pi // π 0
let dx = CGFloat(cos(angle)) * radius
let dy = -CGFloat(sin(angle)) * radius // +Y
let isCurrent = tab == currentTab
return Button {
select(tab)
} label: {
// ZStack = (itemSize),
// offset .
ZStack {
//
ZStack {
Circle()
.fill(.ultraThinMaterial)
.overlay(
Circle().fill(AppTheme.green.opacity(isCurrent ? 0.22 : 0))
)
.overlay(
Circle().strokeBorder(
isCurrent ? AppTheme.green.opacity(0.9) : .white.opacity(0.16),
lineWidth: isCurrent ? 2 : 1
)
)
Image(systemName: tab.symbol)
.font(.system(size: 20, weight: .semibold))
.foregroundStyle(isCurrent ? AppTheme.green : .primary)
}
.frame(width: itemSize, height: itemSize)
.shadow(color: .black.opacity(0.18), radius: 6, y: 3)
// ( , )
Text(tab.label)
.font(.system(size: 11, weight: .semibold))
.lineLimit(1)
.fixedSize()
.foregroundStyle(isCurrent ? AppTheme.green : .primary)
.padding(.horizontal, 7)
.padding(.vertical, 2.5)
.background(Capsule().fill(.ultraThinMaterial))
.overlay(Capsule().strokeBorder(.white.opacity(0.14), lineWidth: 0.5))
.shadow(color: .black.opacity(0.12), radius: 3, y: 1)
.offset(y: labelOffset)
}
}
.buttonStyle(RadialPressStyle())
.accessibilityLabel(Text(tab.label))
// (FAB) , .
.offset(x: expanded ? dx : 0, y: expanded ? dy : 0)
.scaleEffect(expanded ? 1 : 0.3)
.opacity(expanded ? 1 : 0)
.animation(
.spring(response: 0.42, dampingFraction: 0.72)
.delay(expanded ? Double(index) * 0.035 : 0),
value: expanded
)
// FAB .
.allowsHitTesting(expanded)
}
// MARK:
private func toggle() {
withAnimation(.spring(response: 0.42, dampingFraction: 0.72)) {
expanded.toggle()
}
}
private func close() {
withAnimation(.spring(response: 0.42, dampingFraction: 0.72)) {
expanded = false
}
}
private func select(_ tab: AppTab) {
// : .
selection = tab.rawValue
close()
}
}
/// FAB· ( )
private struct RadialPressStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.9 : 1)
.animation(.spring(response: 0.25, dampingFraction: 0.6), value: configuration.isPressed)
}
}