fix: action button on Reader now toggles auto-scroll (not food assistant)
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

Bug: when action tab (value=3) was tapped, selectedTab was already 3
by the time handleActionTap ran. The check 'if selectedTab == 2'
always failed, falling through to food assistant.

Fix: use onChange(of: selectedTab) oldValue to capture which tab the
user was on BEFORE tapping the action button. Pass that to
handleActionTap(from:). If from Reader (2), toggle auto-scroll.
If from Home/Fitness, open food assistant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Yusuf Suleman
2026-04-04 08:00:43 -05:00
parent e2fc87b6aa
commit 395cca08dd

View File

@@ -30,6 +30,7 @@ struct MainTabView: View {
@State private var readerVM = ReaderViewModel()
@State private var isAutoScrolling = false
@State private var scrollSpeed: Double = 1.0
@State private var previousTab = 0
private var showReader: Bool {
auth.currentUser?.id != 4
@@ -64,11 +65,7 @@ struct MainTabView: View {
// Home/Fitness: quick add food (+)
// Reader: play/pause auto-scroll
Tab(value: 3, role: .search) {
// This view shows briefly when tapped immediately redirect
Color.clear
.onAppear {
handleActionTap()
}
} label: {
Label("Action", systemImage: actionIcon)
}
@@ -146,23 +143,28 @@ struct MainTabView: View {
renderer.attachToWindow()
await readerVM.loadInitial()
}
.onChange(of: selectedTab) { _, newTab in
.onChange(of: selectedTab) { oldTab, newTab in
if newTab == 3 {
// Action tab tapped handle based on previous tab
handleActionTap(from: oldTab)
} else {
previousTab = newTab
if newTab != 2 { isAutoScrolling = false }
}
}
}
private func handleActionTap() {
if selectedTab == 2 {
// Reader: toggle auto-scroll, stay on Reader
private func handleActionTap(from sourceTab: Int) {
if sourceTab == 2 {
// Reader: toggle auto-scroll, return to Reader
withAnimation(.spring(duration: 0.3)) {
isAutoScrolling.toggle()
}
selectedTab = 2 // stay on Reader (don't switch to the "action" tab)
selectedTab = 2
} else {
// Home/Fitness: open food assistant, return to previous tab
let returnTab = selectedTab
showAssistant = true
selectedTab = returnTab
selectedTab = sourceTab
}
}