Browse Source

fix: set-tab! doesn't work on native module

Tienson Qin 1 week ago
parent
commit
d6ddabbc74

+ 25 - 0
ios/App/App/LiquidTabsRootView.swift

@@ -108,6 +108,17 @@ struct LiquidTabsRootView: View {
         }
     }
 
+
+    private func selection(forId id: String) -> TabSelection? {
+        if id == firstTab?.id { return .first }
+        if id == secondTab?.id { return .second }
+        if id == thirdTab?.id { return .third }
+        if id == fourthTab?.id { return .fourth }
+        if id == "search" { return .search }
+        return nil
+    }
+
+
     private func initialSelection() -> TabSelection {
         if let id = store.selectedId {
             if id == firstTab?.id { return .first }
@@ -239,6 +250,20 @@ struct LiquidTabsRootView: View {
                         hackShowKeyboard = false
                     }
                 }
+                .onChange(of: store.selectedId) { newId in
+                    guard let id = newId,
+                          let newSelection = selection(forId: id) else {
+                        return
+                    }
+
+                    // If it's already selected, treat it as a no-op for programmatic changes
+                    // (if you want programmatic re-tap behavior, you could call handleRetap here)
+                    if newSelection == selectedTab {
+                        return
+                    }
+
+                    selectedTab = newSelection
+                }
                 // Disable content animation on selection changes (only tab bar animates)
                 .animation(nil, value: selectedTab)
             }

+ 6 - 2
src/main/mobile/components/popup.cljs

@@ -53,8 +53,12 @@
 
       dismissing?
       (when (some? @mobile-state/*popup-data)
-        (state/pub-event! [:mobile/clear-edit])
-        (mobile-state/set-popup! nil))
+        (let [quick-add? (mobile-state/quick-add-open?)
+              current-tab @mobile-state/*tab]
+          (state/pub-event! [:mobile/clear-edit])
+          (mobile-state/set-popup! nil)
+          (when (and current-tab quick-add?)
+            (mobile-state/set-tab! current-tab))))
 
       :else
       nil)))

+ 2 - 1
src/main/mobile/state.cljs

@@ -4,7 +4,8 @@
             [frontend.state :as state]))
 
 (defonce *tab (atom "home"))
-(defn set-tab! [tab] (reset! *tab tab))
+(defn set-tab! [tab]
+  (reset! *tab tab))
 (defn use-tab [] (r/use-atom *tab))
 (defonce *search-input (atom ""))
 (defn use-search-input []