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 } }