From d9c91c313719f7a91563f48fea9cf1c2b1322584 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 13 Oct 2022 15:37:34 +0800 Subject: [PATCH] Reset tabIndex when state is reset to loading We track the state of the current index in two places: the audio controller, which updates as audio as played, the tabView has its own binding of the current index, this is to allow scrolling. When the audio item being played changes, we need to reset the state of the tabIndex. We do this by watching for state loading which occurs when new audio is loaded. --- .../Sources/App/Views/AudioPlayer/MiniPlayer.swift | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift index e0a1626ee..875555c23 100644 --- a/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/AudioPlayer/MiniPlayer.swift @@ -361,6 +361,12 @@ .shadow(color: expanded ? .clear : .gray.opacity(0.33), radius: 8, x: 0, y: 4) .mask(Rectangle().padding(.top, -20)) ) + .onChange(of: audioController.state, perform: { state in + // Reset the tabIndex when we load a new audio item + if state == .loading { + tabIndex = 0 + } + }) .onTapGesture { withAnimation(.easeIn(duration: 0.08)) { expanded = true } }.sheet(isPresented: $showVoiceSheet) {