mycode/myApp/HaruDanim/IOS/Views/RadialNavigationView.swift
songyc macbook dc9434a241 refactor(ui): aggressively prune widget config parameters and optimize floating menu performance/glass styling
Widget configuration — delete the multi-slot pickers entirely
--------------------------------------------------------------
Every home/lock widget exposed 3–4 separate entity slots (action1–4,
goal1–4, quest1–4, secondGoal) regardless of family, cluttering the
long-press config screen with slots a given size never renders. Replaced
that with a single anchor selection per widget that self-configures by size
family (the view already prefixes by family; providers now build the
candidate list from one selection):

- ActionRun (A): one anchor Action → fills following actions (main-tab order)
  up to the family's count.
- GoalBars (B): one anchor Goal → fills following goals up to the count.
- QuestRing (C): one Goal → renders that goal's quests, sized by family.
- GoalQuestGrid (D): one Goal (dropped secondGoal) → its quests; large now
  shows up to 16 rings of the single goal.
- Stats: one anchor Action → plus following actions on the same chart.

New WidgetStore helpers actionsFrom/goalsFrom/questsOfGoal centralize the
"anchor + following / goal's quests" logic; the None sentinel is ignored
gracefully so clearing falls back to sensible defaults. No @Model, timeline,
or reload/sync logic touched.

Floating radial menu (iPhone) — performance + glassmorphism
-----------------------------------------------------------
Each of the ~7 icons and ~7 labels had its own .ultraThinMaterial, so the
expanded menu ran ~15 separate blur passes that re-rendered every frame as
content scrolled behind them — the source of the progressive frame drops.
Now a single unified glass dome (one DomeShape filled with .ultraThinMaterial)
sits behind the whole fan and is the only blur; icons are lightweight symbols
(only the current tab gets a solid green chip) and labels are plain text with
a legibility shadow. The dome is styled per glassmorphism: a soft white
top-to-bottom gradient overlay, a thin white.opacity(0.2) border, and a soft
shadow; the FAB gets the same gradient/border treatment.

Animation is snappier and lighter: the per-item implicit spring animations
with staggered delays are gone — one withAnimation(.easeOut ~0.24 open /
.easeIn ~0.18 close) drives the whole fan, and the press style uses a short
easeOut instead of a spring.

Verified in the simulator: build succeeds; the expanded menu renders the
single glass dome with all tabs and no crash (light/dark, expanded/collapsed);
the refactored C/D widgets render from a single selected goal, self-sized by
family.

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

280 lines
12 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
/// ( , )
@AppStorage(SettingsKeys.radialTabOrder) private var radialOrderRaw = ""
//
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.radialOrder(from: radialOrderRaw) }
private var currentTab: AppTab {
AppTab(rawValue: selection) ?? .main
}
/// / . easeOut .
private var openCurve: Animation { .easeOut(duration: 0.24) }
private var closeCurve: Animation { .easeIn(duration: 0.18) }
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 {
// ' ' .
// ( · ultraThinMaterial 15
// )
if expanded {
glassFan(radius: radius)
.transition(.scale(scale: 0.4, anchor: .bottom).combined(with: .opacity))
}
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: ( )
/// . (ultraThinMaterial) +
/// + . .
private func glassFan(radius: CGFloat) -> some View {
let r = radius + itemSize / 2 + 12 //
let skirt = itemSize / 2 + 8 // ( )
return DomeShape(skirt: skirt)
.fill(.ultraThinMaterial)
.overlay(
DomeShape(skirt: skirt).fill(
LinearGradient(
colors: [.white.opacity(0.30), .white.opacity(0.05)],
startPoint: .top, endPoint: .bottom
)
)
)
.overlay(DomeShape(skirt: skirt).stroke(.white.opacity(0.2), lineWidth: 1))
.frame(width: 2 * r, height: r + skirt)
// FAB .
.offset(y: -(r - skirt) / 2)
.shadow(color: .black.opacity(0.18), radius: 14, y: 6)
.allowsHitTesting(false)
}
// 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.22), 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 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 {
// . ( ).
ZStack {
if isCurrent {
Circle()
.fill(AppTheme.green.opacity(0.9))
.overlay(Circle().strokeBorder(.white.opacity(0.3), lineWidth: 1))
}
Image(systemName: tab.symbol)
.font(.system(size: 20, weight: .semibold))
.foregroundStyle(isCurrent ? .white : .primary)
}
.frame(width: itemSize, height: itemSize)
// +
Text(tab.label)
.font(.system(size: 11, weight: .semibold))
.lineLimit(1)
.fixedSize()
.foregroundStyle(isCurrent ? AppTheme.green : .primary)
.shadow(color: .black.opacity(0.15), radius: 2, y: 1)
.offset(y: labelOffset)
}
}
.buttonStyle(RadialPressStyle())
.accessibilityLabel(Text(tab.label))
// (FAB) , .
// (per-item · withAnimation )
.offset(x: expanded ? dx : 0, y: expanded ? dy : 0)
.scaleEffect(expanded ? 1 : 0.3)
.opacity(expanded ? 1 : 0)
// FAB .
.allowsHitTesting(expanded)
}
// 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()
}
}
/// () + . .
private struct DomeShape: Shape {
/// ( )
var skirt: CGFloat = 0
func path(in rect: CGRect) -> Path {
var p = Path()
let r = rect.width / 2
let cx = rect.midX
let baseY = rect.maxY - skirt
p.addArc(
center: CGPoint(x: cx, y: baseY), radius: r,
startAngle: .degrees(180), endAngle: .degrees(360), clockwise: false
)
p.addLine(to: CGPoint(x: cx + r, y: rect.maxY))
p.addLine(to: CGPoint(x: cx - r, y: rect.maxY))
p.closeSubpath()
return p
}
}
/// 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)
}
}