mycode/myApp/HaruDanim/IOS/Views/RadialNavigationView.swift
songyc macbook daf4fc3157 fix(radial): add glass pill background behind bubble tab labels
글래스 버블 메뉴의 탭 이름이 맨 글자(그림자만)라 라이트 모드 밝은 배경
위에서 잘 안 보였음 → 구슬과 같은 ultraThinMaterial 캡슐 배경 + 화이트
보더 + 소프트 섀도를 붙여 라이트/다크 어디서나 읽히게 함.

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

259 lines
11 KiB
Swift

//
// RadialNavigationView.swift
// Haru_Danim
//
// [] iPhone ( ).
//
// :
// - TabView 7 ·
// ( FAB ),
// - (ZStack ) .
// FAB/ · .
//
// UI: ' (Glass Bubbles)'.
// - FAB () FAB
// . () .
// - (~150pt) .
// - : ultraThinMaterial + ( ) + + .
// offset·scale·opacity·rotation ( ) .
//
// 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.phoneCases) { tab in
Tab(tab.label, systemImage: tab.symbol, value: tab.rawValue) {
NavigationStack {
tab.rootView
}
.toolbar(.hidden, for: .tabBar)
}
}
}
// 2) . collapsed FAB .
GlassBubbleMenu(
expanded: $menuExpanded,
selection: $router.tabSelection
)
}
.environment(router)
}
}
// MARK: -
struct GlassBubbleMenu: 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 bubbleSize: CGFloat = 56
/// FAB . .
private let desiredRadius: CGFloat = 152
private let bottomInset: CGFloat = 42
private let edgePadding: CGFloat = 16
/// ( )
private let labelOffset: CGFloat = 42
/// ( )
private var tabs: [AppTab] { AppTab.radialOrder(from: radialOrderRaw) }
private var currentTab: AppTab {
AppTab(rawValue: selection) ?? .main
}
var body: some View {
GeometryReader { geo in
//
let radius = min(desiredRadius, geo.size.width / 2 - bubbleSize / 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
bubble(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:
/// . FAB
/// , .
private func bubble(_ 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 {
Circle()
.fill(.ultraThinMaterial)
.overlay(
//
Circle().fill(
LinearGradient(
colors: [.white.opacity(0.35), .white.opacity(0.03)],
startPoint: .top, endPoint: .bottom
)
)
)
.overlay(
//
Circle().fill(AppTheme.green.opacity(isCurrent ? 0.82 : 0))
)
.overlay(Circle().strokeBorder(.white.opacity(0.4), lineWidth: 1))
Image(systemName: tab.symbol)
.font(.system(size: 20, weight: .semibold))
.foregroundStyle(isCurrent ? AnyShapeStyle(.white) : AnyShapeStyle(.primary))
}
.frame(width: bubbleSize, height: bubbleSize)
.shadow(color: .black.opacity(0.15), radius: 8, x: 0, y: 4)
//
// ( )
Text(tab.label)
.font(.system(size: 11, weight: .semibold))
.lineLimit(1)
.fixedSize()
.foregroundStyle(isCurrent ? AppTheme.green : .primary)
.padding(.horizontal, 9)
.padding(.vertical, 3.5)
.background(.ultraThinMaterial, in: Capsule())
.overlay(Capsule().strokeBorder(.white.opacity(0.35), lineWidth: 0.8))
.shadow(color: .black.opacity(0.12), radius: 4, y: 2)
.offset(y: labelOffset)
}
}
.buttonStyle(RadialPressStyle())
.accessibilityLabel(Text(tab.label))
// : FAB (-40°0°) . : FAB .
// .
.rotationEffect(.degrees(expanded ? 0 : -40))
.offset(x: expanded ? dx : 0, y: expanded ? dy : 0)
.scaleEffect(expanded ? 1 : 0.1)
.opacity(expanded ? 1 : 0)
// . .
.animation(
expanded
? .spring(response: 0.32, dampingFraction: 0.72).delay(Double(index) * 0.03)
: .spring(response: 0.24, dampingFraction: 0.9),
value: expanded
)
// 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() {
// per-item , /FAB .
withAnimation(.easeOut(duration: 0.2)) {
expanded.toggle()
}
}
private func close() {
withAnimation(.easeOut(duration: 0.18)) {
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)
}
}