From a6d98de90e93e4caf46779cd30e8ab93a1d04648 Mon Sep 17 00:00:00 2001 From: jack Date: Sat, 13 Sep 2025 22:41:21 +0200 Subject: [PATCH] Notes counter UX: avoid grey flicker when closing sheet\n\n- Preserve last count during resubscribe to prevent brief 0 state.\n- Keep existing subscription when building geohash temporarily unavailable; only cancel if none or permission revoked. --- bitchat/Services/LocationNotesCounter.swift | 3 ++- bitchat/Views/ContentView.swift | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/bitchat/Services/LocationNotesCounter.swift b/bitchat/Services/LocationNotesCounter.swift index 787bd97c..5fb443a5 100644 --- a/bitchat/Services/LocationNotesCounter.swift +++ b/bitchat/Services/LocationNotesCounter.swift @@ -17,9 +17,10 @@ final class LocationNotesCounter: ObservableObject { func subscribe(geohash gh: String) { let norm = gh.lowercased() if geohash == norm { return } + // Do not clear count immediately to avoid UI flicker; keep last known + // value until initial load completes on the new subscription. cancel() geohash = norm - count = 0 noteIDs.removeAll() initialLoadComplete = false diff --git a/bitchat/Views/ContentView.swift b/bitchat/Views/ContentView.swift index 463930ef..42f0f0bc 100644 --- a/bitchat/Views/ContentView.swift +++ b/bitchat/Views/ContentView.swift @@ -1530,8 +1530,16 @@ extension ContentView { if locationManager.permissionState == .authorized { LocationChannelManager.shared.refreshChannels() } - if let building = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash { - LocationNotesCounter.shared.subscribe(geohash: building) + if locationManager.permissionState == .authorized { + if let building = LocationChannelManager.shared.availableChannels.first(where: { $0.level == .building })?.geohash { + LocationNotesCounter.shared.subscribe(geohash: building) + } else { + // Keep existing subscription if we had one to avoid flicker + // Only cancel if we have no known geohash + if LocationNotesCounter.shared.geohash == nil { + LocationNotesCounter.shared.cancel() + } + } } else { LocationNotesCounter.shared.cancel() }