Two iOS bugs with the same shape: unconditional rebuilds where a conditional check belongs. The audio graph was torn down on every unintentional disconnect and every foreground transition. A lost connection ran the same teardown as an explicit disconnect, deactivating the AVAudioSession and so dropping the Bluetooth HFP link for a transport blip, and foregrounding always called Reconfigure even though the `audio` background mode keeps the graph live. Both cost seconds of dead audio on a headset. Split "session ended" from "transport blipped". Detach unbinds the client but keeps the session, graph, and route, so a reconnect rebinds to a live HFP link; the route is parked on stream id 0 so capture cannot feed the next connection a stream it never announced. StartListening reuses a running graph, StartMicrophone reuses a running tap of the same width, and Reconfigure gained a non-forcing mode that no-ops when tap presence, channel width, and voice processing all still match. Foregrounding now ensures the graph is running and only reconfigures if it actually stopped. Route changes, media-services resets, and the stall watchdog still force a full rebuild. Every list also reloaded on a model event raised 20 times a second by the microphone level timer. ReloadData recreates the accessibility element tree, so VoiceOver explore mode re-announced the row under a dragging finger and a double tap landed on an element that no longer existed. No controller ever unsubscribed, so popped controllers kept reloading too. Move the level to its own LevelChanged event, and reload lists through ListRefresher, which subscribes only while on screen and only reloads when the rendered content signature changed. The voice bar publishes its accessibility value on 5% steps, MoveUserController reloads just its two checkmark rows, and the chat transcripts skip reassigning identical text. The changed logic sits on UIKit and AVFoundation types the net10.0 test project cannot reference, so this carries no tests; the Bluetooth reconnect and foreground paths need device verification.
59 lines
2.4 KiB
C#
59 lines
2.4 KiB
C#
using UIKit;
|
|
|
|
namespace VoiceCat.iOS;
|
|
|
|
internal static class UiHelpers
|
|
{
|
|
internal static void ShowError(UIViewController owner, Exception exception) => ShowMessage(owner, "VoiceCat", exception.Message);
|
|
internal static void ShowMessage(UIViewController owner, string title, string message)
|
|
{
|
|
UIAlertController alert = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
|
|
alert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); owner.PresentViewController(alert, true, null);
|
|
}
|
|
|
|
internal static UITextField Field(string placeholder, bool secure = false)
|
|
{
|
|
var field = new UITextField { Placeholder = placeholder, BorderStyle = UITextBorderStyle.RoundedRect,
|
|
SecureTextEntry = secure, TranslatesAutoresizingMaskIntoConstraints = false };
|
|
field.AccessibilityLabel = placeholder; return field;
|
|
}
|
|
}
|
|
|
|
// VoiceOver rebuilds its element tree from scratch on every UITableView.ReloadData. The model
|
|
// notifies far more often than any list's content actually changes - the microphone level timer
|
|
// alone ticks at 20 Hz - so reloading unconditionally re-announces the row under an exploring
|
|
// finger and destroys the element a double tap was aimed at. Reload only when the rendered text
|
|
// actually differs, and only while the view is on screen, so an off-screen or popped controller
|
|
// stops reloading instead of holding a subscription for the lifetime of the connection.
|
|
internal sealed class ListRefresher(UITableViewController owner, Func<string> signature, Action<Action> subscribe, Action<Action> unsubscribe)
|
|
{
|
|
// Null means nothing has been rendered yet. A signature is never null, so the first
|
|
// Refresh after Start or Invalidate always reloads.
|
|
private string? rendered;
|
|
private bool observing;
|
|
|
|
internal void Start()
|
|
{
|
|
if (observing) return;
|
|
observing = true; subscribe(Refresh); Refresh();
|
|
}
|
|
|
|
internal void Stop()
|
|
{
|
|
if (!observing) return;
|
|
observing = false; unsubscribe(Refresh);
|
|
}
|
|
|
|
// Forces the next Refresh to reload even when the signature is unchanged, for state the
|
|
// signature cannot see.
|
|
internal void Invalidate() => rendered = null;
|
|
|
|
internal void Refresh()
|
|
{
|
|
if (!observing || !owner.IsViewLoaded) return;
|
|
string next = signature();
|
|
if (next == rendered) return;
|
|
rendered = next; owner.TableView.ReloadData();
|
|
}
|
|
}
|