- TabBarState ObservableObject 管理可见性 - ContentView 用 .toolbar(hidden)+animation 驱动动画 - 子页面 hideTabBarWithAnimation() 替代静态 toolbar hidden - 0.28s easeInOut 淡入淡出 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
158 lines
6.0 KiB
Swift
158 lines
6.0 KiB
Swift
import SwiftUI
|
|
|
|
// MARK: - TabBar visibility state
|
|
|
|
class TabBarState: ObservableObject {
|
|
@Published var isHidden = false
|
|
}
|
|
|
|
extension View {
|
|
func hideTabBarWithAnimation() -> some View {
|
|
modifier(HideTabBarModifier())
|
|
}
|
|
}
|
|
|
|
struct HideTabBarModifier: ViewModifier {
|
|
@EnvironmentObject private var tabBarState: TabBarState
|
|
|
|
func body(content: Content) -> some View {
|
|
content
|
|
.onAppear {
|
|
withAnimation(.easeInOut(duration: 0.28)) {
|
|
tabBarState.isHidden = true
|
|
}
|
|
}
|
|
.onDisappear {
|
|
withAnimation(.easeInOut(duration: 0.28)) {
|
|
tabBarState.isHidden = false
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// MARK: - ContentView
|
|
|
|
struct ContentView: View {
|
|
@State private var selectedTab = "study"
|
|
@StateObject private var tabBarState = TabBarState()
|
|
|
|
var body: some View {
|
|
TabView(selection: $selectedTab) {
|
|
NavigationStack {
|
|
StudyHomeView()
|
|
.background(Color.zxCanvas.ignoresSafeArea())
|
|
}
|
|
.tabItem {
|
|
Label("学习", image: selectedTab == "study" ? "tab-learn-active" : "tab-learn")
|
|
}
|
|
.tag("study")
|
|
|
|
NavigationStack {
|
|
LibraryHomeView()
|
|
.background(Color.zxCanvas.ignoresSafeArea())
|
|
}
|
|
.tabItem {
|
|
Label("知识库", image: selectedTab == "library" ? "tab-library-active" : "tab-library")
|
|
}
|
|
.tag("library")
|
|
|
|
NavigationStack {
|
|
AnalysisHomeView()
|
|
.background(Color.zxCanvas.ignoresSafeArea())
|
|
}
|
|
.tabItem {
|
|
Label("分析", image: selectedTab == "analysis" ? "tab-analysis-active" : "tab-analysis")
|
|
}
|
|
.tag("analysis")
|
|
|
|
NavigationStack {
|
|
ProfileView()
|
|
.background(Color.zxCanvas.ignoresSafeArea())
|
|
}
|
|
.tabItem {
|
|
Label("我的", image: selectedTab == "profile" ? "tab-profile-active" : "tab-profile")
|
|
}
|
|
.tag("profile")
|
|
}
|
|
.environmentObject(tabBarState)
|
|
.tint(Color.zxPrimary)
|
|
.toolbar(tabBarState.isHidden ? .hidden : .visible, for: .tabBar)
|
|
.animation(.easeInOut(duration: 0.28), value: tabBarState.isHidden)
|
|
}
|
|
}
|
|
|
|
// MARK: - Shared Components
|
|
|
|
struct ZXIconBtn: View {
|
|
let icon: String; let size: CGFloat; var branded = false; let action: () -> Void
|
|
var body: some View {
|
|
Button(action: action) {
|
|
Image(systemName: icon).font(.system(size: size * 0.44)).frame(width: size, height: size)
|
|
}
|
|
.foregroundColor(branded ? .white : Color.zxF05)
|
|
.background(branded ? AnyView(ZXGradient.brand) : AnyView(Color(hex: "#FFFFFF", opacity: 0.05)))
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
.overlay {
|
|
if !branded {
|
|
RoundedRectangle(cornerRadius: 10).stroke(Color.zxBorder008, lineWidth: 1)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
struct ZXScoreBox: View {
|
|
let score: Int; let bg: Color; let fg: Color
|
|
var body: some View {
|
|
Text("\(score)")
|
|
.font(.system(size: 12, weight: .heavy))
|
|
.foregroundColor(fg)
|
|
.frame(width: 36, height: 36)
|
|
.background(bg)
|
|
.clipShape(RoundedRectangle(cornerRadius: 10))
|
|
}
|
|
}
|
|
|
|
struct ZXWeakRow: View {
|
|
let score: Int; let topic: String; let lib: String; let priority: String
|
|
var body: some View {
|
|
HStack(spacing: 12) {
|
|
Text("\(score)").font(.system(size: 13, weight: .heavy)).foregroundColor(Color.zxYellow)
|
|
.frame(width: 40, height: 40).background(Color.zxYellowBG(0.15)).clipShape(RoundedRectangle(cornerRadius: 12))
|
|
VStack(alignment: .leading, spacing: 2) {
|
|
Text(topic).font(.system(size: 13, weight: .semibold)).foregroundColor(Color.zxF0)
|
|
Text(lib).font(.system(size: 11)).foregroundColor(Color.zxF04)
|
|
}.frame(maxWidth: .infinity, alignment: .leading)
|
|
Text("\(priority)优先").font(.system(size: 11, weight: .bold))
|
|
.foregroundColor(priority == "高" ? Color.zxRed : Color.zxYellow)
|
|
.padding(.horizontal, 8).padding(.vertical, 3)
|
|
.background((priority == "高" ? Color.zxRedBG(0.15) : Color.zxYellowBG(0.15))).clipShape(Capsule())
|
|
}
|
|
.padding(.horizontal, 16).padding(.vertical, 12)
|
|
.background(Color.zxYellowBG(0.06))
|
|
.overlay(RoundedRectangle(cornerRadius: 14).stroke(Color(hex: "#F59E0B", opacity: 0.15), lineWidth: 1))
|
|
.clipShape(RoundedRectangle(cornerRadius: 14))
|
|
}
|
|
}
|
|
|
|
struct ZXAIInputBar: View {
|
|
@Binding var text: String; let onSend: () -> Void
|
|
var body: some View {
|
|
HStack(spacing: 10) {
|
|
Image(systemName: "sparkles").font(.system(size: 16)).foregroundColor(Color.zxPurple)
|
|
TextField("问 AI 任何学习问题…", text: $text).font(.system(size: 14)).tint(Color.zxPurple).accessibilityLabel("AI 学习问题输入框")
|
|
Spacer()
|
|
Image(systemName: "mic.fill").font(.system(size: 18)).foregroundColor(Color.zxF03).accessibilityLabel("语音输入")
|
|
Button(action: onSend) {
|
|
Image(systemName: "arrow.up").font(.system(size: 14, weight: .bold)).foregroundColor(.white)
|
|
.frame(width: 30, height: 30).background(ZXGradient.brand).clipShape(RoundedRectangle(cornerRadius: 9))
|
|
}
|
|
.zxPressable()
|
|
.disabled(text.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty)
|
|
.accessibilityLabel("发送消息")
|
|
}
|
|
.padding(.horizontal, 14).padding(.vertical, 10)
|
|
.background(.ultraThinMaterial).background(Color.zxFill004)
|
|
.overlay(RoundedRectangle(cornerRadius: 20).stroke(Color.zxBorder008, lineWidth: 1))
|
|
.clipShape(RoundedRectangle(cornerRadius: 20))
|
|
}
|
|
} |