mycode/myApp/HaruDanim/IOS/Views/RadialNavigationView.swift
songyc macbook bd60697419 refactor(ui): redesign floating menu to detached glass capsules for better aesthetics and performance
Replace the single semicircle dome + arc-arranged icons (which distorted and
pushed labels outside the fan) with independent floating glass capsules that pop
up in a vertical stack from the FAB.

- Each tab is now a self-sizing Capsule: icon + label with generous padding so
  text can never overflow; ultraThinMaterial background, thin white translucent
  border (.stroke white 0.4), and a soft drop shadow for a floating glass look.
- Current tab gets a subtle green tint behind the content.
- Removed the heavy DomeShape glass fan and its scale/opacity blur transition
  plus all per-item arc math; appearance is driven purely by offset + scale +
  opacity under one snappy spring (response 0.3, damping 0.7), so no per-item
  blur passes and no progressive frame drops.
- Renamed RadialMenu -> FloatingCapsuleMenu; RadialTabView / settings keys /
  nav-style routing unchanged.

Verified: BUILD SUCCEEDED (iPhone 17 Pro sim) and expanded-state screenshot
confirms all 7 capsules render legibly with text fully inside each pill, no
distortion, current tab highlighted.

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

228 lines
9.3 KiB
Swift

//
// RadialNavigationView.swift
// Haru_Danim
//
// [] iPhone ( ).
//
// :
// - TabView 7 ·
// ( FAB ),
// - (ZStack ) .
// FAB/ · .
//
// UI: ' (Floating Glass Capsules)'.
// - , FAB (Capsule)
// . ultraThinMaterial + +
// , + .
// - offset·scale·opacity + .
//
// 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 .
FloatingCapsuleMenu(
expanded: $menuExpanded,
selection: $router.tabSelection
)
}
.environment(router)
}
}
// MARK: -
struct FloatingCapsuleMenu: View {
@Binding var expanded: Bool
/// AppTab.rawValue ( tabSelection )
@Binding var selection: String
/// ( , )
@AppStorage(SettingsKeys.radialTabOrder) private var radialOrderRaw = ""
//
private let fabSize: CGFloat = 62
private let bottomInset: CGFloat = 42
/// FAB ( )
private let firstItemGap: CGFloat = 78
///
private let itemSpacing: CGFloat = 56
/// ( )
private var tabs: [AppTab] { AppTab.radialOrder(from: radialOrderRaw) }
private var currentTab: AppTab {
AppTab(rawValue: selection) ?? .main
}
/// : (snappy) .
private var openCurve: Animation { .spring(response: 0.3, dampingFraction: 0.7, blendDuration: 0) }
/// : .
private var closeCurve: Animation { .spring(response: 0.25, dampingFraction: 0.9, blendDuration: 0) }
var body: some View {
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
capsuleItem(tab, index: index)
}
fab
}
.frame(width: fabSize, height: fabSize)
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)
.padding(.bottom, bottomInset)
}
.ignoresSafeArea(.keyboard)
}
// MARK: ( + )
/// . ultraThinMaterial
/// .
/// padding / .
private func capsuleItem(_ tab: AppTab, index: Int) -> some View {
// index 0( ) FAB , .
let restY = -(firstItemGap + CGFloat(index) * itemSpacing)
let isCurrent = tab == currentTab
return Button {
select(tab)
} label: {
HStack(spacing: 8) {
Image(systemName: tab.symbol)
.font(.system(size: 15, weight: .semibold))
Text(tab.label)
.font(.system(size: 15, weight: .semibold))
.lineLimit(1)
.fixedSize()
}
.foregroundStyle(isCurrent ? AppTheme.green : .primary)
.padding(.horizontal, 18)
.padding(.vertical, 12)
.background {
ZStack {
Capsule().fill(.ultraThinMaterial)
// ( )
Capsule().fill(AppTheme.green.opacity(isCurrent ? 0.16 : 0))
}
}
.overlay(
//
Capsule().stroke(Color.white.opacity(0.4), lineWidth: 1)
)
.shadow(color: .black.opacity(0.15), radius: 8, x: 0, y: 4)
}
.buttonStyle(RadialPressStyle())
.accessibilityLabel(Text(tab.label))
// : FAB (offset 0, ) .
// : FAB .
.offset(y: expanded ? restY : 0)
.scaleEffect(expanded ? 1 : 0.3, anchor: .bottom)
.opacity(expanded ? 1 : 0)
// FAB .
.allowsHitTesting(expanded)
}
// MARK:
private var fab: some View {
Button {
toggle()
} label: {
ZStack {
Circle()
.fill(.ultraThinMaterial)
.overlay(
Circle().fill(
LinearGradient(
colors: [.white.opacity(0.28), .white.opacity(0.02)],
startPoint: .top, endPoint: .bottom
)
)
)
.overlay(Circle().fill(AppTheme.green.opacity(expanded ? 0.0 : 0.14)))
.overlay(Circle().strokeBorder(.white.opacity(0.4), lineWidth: 1))
Image(systemName: expanded ? "xmark" : currentTab.symbol)
.font(.system(size: expanded ? 22 : 24, weight: .semibold))
.foregroundStyle(AppTheme.green)
.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 toggle() {
withAnimation(expanded ? closeCurve : openCurve) {
expanded.toggle()
}
}
private func close() {
withAnimation(closeCurve) {
expanded = false
}
}
private func select(_ tab: AppTab) {
// : .
selection = tab.rawValue
close()
}
}
/// FAB· ( ). easeOut .
private struct RadialPressStyle: ButtonStyle {
func makeBody(configuration: Configuration) -> some View {
configuration.label
.scaleEffect(configuration.isPressed ? 0.9 : 1)
.animation(.easeOut(duration: 0.14), value: configuration.isPressed)
}
}