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

This commit is contained in:
Tienson Qin
2025-11-26 16:17:16 +08:00
parent e3054f5197
commit d6ddabbc74
3 changed files with 33 additions and 3 deletions

View File

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

View File

@@ -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)))

View File

@@ -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 []