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.
This commit is contained in:
Jackson Harper 2022-10-13 15:37:34 +08:00
parent fe1f4ee51d
commit d9c91c3137

View file

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