Files
platform/ios/Platform/Platform/ContentView.swift
Yusuf Suleman e9373ceac3
All checks were successful
Security Checks / dependency-audit (push) Successful in 13s
Security Checks / secret-scanning (push) Successful in 4s
Security Checks / dockerfile-lint (push) Successful in 4s
fix: context-dependent FAB — play/pause on Reader, + on other tabs
Removed Tab(role: .search) — it was always visible on all tabs.
Now the floating action button changes based on selected tab:

- Home/Fitness: FAB (+) → opens food assistant (same as before)
- Reader: Play/Pause circle → toggles auto-scroll
  - Idle: play.fill icon, warm accent background
  - Playing: pause.fill icon, red background
  - Tapping toggles between play/pause

Speed controls appear as glass capsule above the FAB when playing.
Auto-scroll stops when switching away from Reader tab.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-04 07:41:50 -05:00

229 lines
8.4 KiB
Swift

import SwiftUI
import ConfettiSwiftUI
struct ContentView: View {
@Environment(AuthManager.self) private var auth
var body: some View {
Group {
if auth.isCheckingAuth {
ProgressView()
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color.canvas)
} else if auth.isLoggedIn {
MainTabView()
} else {
LoginView()
}
}
.task {
await auth.checkAuth()
}
}
}
struct MainTabView: View {
@Environment(AuthManager.self) private var auth
@State private var selectedTab = 0
@State private var showAssistant = false
@State private var confettiTrigger = 0
@State private var readerVM = ReaderViewModel()
@State private var isAutoScrolling = false
@State private var scrollSpeed: Double = 1.0
private var showReader: Bool {
auth.currentUser?.id != 4
}
var body: some View {
ZStack {
TabView(selection: $selectedTab) {
Tab("Home", systemImage: "house.fill", value: 0) {
HomeView(selectedTab: $selectedTab)
}
Tab("Fitness", systemImage: "flame.fill", value: 1) {
FitnessTabView()
}
if showReader {
Tab("Reader", systemImage: "newspaper.fill", value: 2) {
ReaderTabView(vm: readerVM, isAutoScrolling: $isAutoScrolling, scrollSpeed: $scrollSpeed)
}
}
}
.tint(Color.accentWarm)
.tabBarMinimizeBehavior(.onScrollDown)
// Floating action button context-dependent
VStack {
Spacer()
HStack(alignment: .bottom) {
if selectedTab != 2 {
FeedbackButton()
.padding(.leading, 20)
}
Spacer()
if selectedTab == 2 && showReader {
// Reader: play/pause auto-scroll
Button {
withAnimation(.spring(duration: 0.3)) {
isAutoScrolling.toggle()
}
} label: {
Image(systemName: isAutoScrolling ? "pause.fill" : "play.fill")
.font(.system(size: 18))
.foregroundStyle(.white)
.frame(width: 56, height: 56)
.background(isAutoScrolling ? Color.red.opacity(0.85) : Color.accentWarm)
.clipShape(Circle())
.shadow(color: .black.opacity(0.2), radius: 8, y: 4)
}
.padding(.trailing, 20)
} else {
// Home/Fitness: FAB (+) for food
Button { showAssistant = true } label: {
Image(systemName: "plus")
.font(.title2.weight(.semibold))
.foregroundStyle(.white)
.frame(width: 56, height: 56)
.background(Color.accentWarm)
.clipShape(Circle())
.shadow(color: .black.opacity(0.2), radius: 8, y: 4)
}
.padding(.trailing, 20)
}
}
.padding(.bottom, 70)
}
// Auto-scroll speed controls (overlay when playing)
if isAutoScrolling && selectedTab == 2 {
VStack {
Spacer()
HStack(spacing: 12) {
Button {
scrollSpeed = max(0.25, scrollSpeed - 0.25)
} label: {
Image(systemName: "minus")
.font(.caption.weight(.bold))
.foregroundStyle(Color.accentWarm)
.frame(width: 32, height: 32)
}
Text(String(format: "%.2fx", scrollSpeed))
.font(.system(size: 13, weight: .bold, design: .monospaced))
.foregroundStyle(Color.textPrimary)
Button {
scrollSpeed = min(3.0, scrollSpeed + 0.25)
} label: {
Image(systemName: "plus")
.font(.caption.weight(.bold))
.foregroundStyle(Color.accentWarm)
.frame(width: 32, height: 32)
}
}
.padding(.horizontal, 14)
.padding(.vertical, 8)
.background(.ultraThinMaterial, in: Capsule())
.shadow(color: .black.opacity(0.1), radius: 8, y: 2)
.padding(.bottom, 140)
.transition(.move(edge: .bottom).combined(with: .opacity))
}
.animation(.spring(duration: 0.3), value: isAutoScrolling)
}
}
.confettiCannon(
trigger: $confettiTrigger,
num: 80,
confettis: [.shape(.circle), .shape(.roundedCross), .shape(.slimRectangle)],
colors: [.red, .orange, .yellow, .green, .blue, .purple, .pink],
confettiSize: 8,
rainHeight: 600,
openingAngle: Angle.degrees(40),
closingAngle: Angle.degrees(140),
radius: 300
)
.sheet(isPresented: $showAssistant) {
AssistantSheetView(onFoodAdded: foodAdded)
}
.task {
guard showReader else { return }
let renderer = ArticleRenderer.shared
renderer.attachToWindow()
await readerVM.loadInitial()
}
.onChange(of: selectedTab) { _, newTab in
// Stop auto-scroll when leaving Reader
if newTab != 2 { isAutoScrolling = false }
}
}
private func foodAdded() {
showAssistant = false
selectedTab = 1
confettiTrigger += 1
UINotificationFeedbackGenerator().notificationOccurred(.success)
}
}
// MARK: - Assistant Sheet
struct AssistantSheetView: View {
@State private var selectedMode = 0
var onFoodAdded: () -> Void = {}
var body: some View {
VStack(spacing: 0) {
VStack(spacing: 12) {
Capsule()
.fill(Color.textTertiary.opacity(0.3))
.frame(width: 36, height: 5)
.padding(.top, 8)
Text("Add Food")
.font(.headline)
.foregroundStyle(Color.textPrimary)
HStack(spacing: 4) {
tabButton("AI Chat", icon: "sparkles", index: 0)
tabButton("Quick Add", icon: "magnifyingglass", index: 1)
}
.padding(4)
.background(Color.textTertiary.opacity(0.08))
.clipShape(Capsule())
.padding(.horizontal, 40)
}
.padding(.bottom, 12)
.background(Color.canvas)
if selectedMode == 0 {
AssistantChatView(onFoodAdded: onFoodAdded)
} else {
FoodSearchView(isSheet: true, onFoodAdded: onFoodAdded)
}
}
.background(Color.canvas)
.presentationDetents([.large])
}
private func tabButton(_ title: String, icon: String, index: Int) -> some View {
Button {
withAnimation(.easeInOut(duration: 0.2)) { selectedMode = index }
} label: {
HStack(spacing: 5) {
Image(systemName: icon).font(.caption2)
Text(title).font(.subheadline.weight(selectedMode == index ? .semibold : .regular))
}
.foregroundStyle(selectedMode == index ? Color.textPrimary : Color.textTertiary)
.padding(.horizontal, 16)
.padding(.vertical, 8)
.background(selectedMode == index ? Color.surfaceCard : Color.clear)
.clipShape(Capsule())
}
}
}