From 395cca08dd0fd17b0041c90d34127e0ea9a2c752 Mon Sep 17 00:00:00 2001 From: Yusuf Suleman Date: Sat, 4 Apr 2026 08:00:43 -0500 Subject: [PATCH] fix: action button on Reader now toggles auto-scroll (not food assistant) 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) --- ios/Platform/Platform/ContentView.swift | 26 +++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/ios/Platform/Platform/ContentView.swift b/ios/Platform/Platform/ContentView.swift index efa170f..3c2fbb2 100644 --- a/ios/Platform/Platform/ContentView.swift +++ b/ios/Platform/Platform/ContentView.swift @@ -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 - if newTab != 2 { isAutoScrolling = false } + .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 } }