The vertical capsule stack reached ~414pt up the screen, putting the top tabs out of thumb range. Replace it with 'Glass Bubbles': liquid-glass orbs that fan out from the FAB along a semicircular arc whose radius (~152pt, clamped to screen width) keeps every tab inside the natural thumb sweep from the bottom-center pivot. - Each bubble: ultraThinMaterial circle + top white gradient (specular light) + white 0.4 hairline + soft shadow; label with shadow below. Current tab rendered as green glass with white symbol. - Entrance: bubbles fly from the FAB to their arc slot while rotating -40deg -> 0 with a snappy spring (response 0.32, damping 0.72) and a per-item 0.03s stagger, like droplets bursting in sequence; collapse snaps back with no delay. All transform-only (offset/scale/opacity/ rotation) so no per-frame blur recomputation. - Struct renamed FloatingCapsuleMenu -> GlassBubbleMenu; storage key and NavStyle.radial rawValue unchanged for compatibility. - Settings copy updated: nav style now '글래스 버블 메뉴' with a description of the fan-out and one-handed reach; order editor renamed '버블 메뉴 순서' with left-to-right arc wording. Verified: clean rebuild (stale incremental link produced an old binary despite BUILD SUCCEEDED; wiped DerivedData), expanded-arc screenshot shows all 7 bubbles within thumb radius with legible labels, and the settings screen shows the new name/description. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013yKDMhuF39GVYy3FMcGHh7
254 lines
11 KiB
Swift
254 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.allCases) { 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)
|
|
.shadow(color: .black.opacity(0.15), radius: 2, y: 1)
|
|
.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)
|
|
}
|
|
}
|