Note: If I change the app to this, there's no more leak because now the toolbar doesn't get invalidated and recreated.
Swift
import SwiftUI
@main
struct TestApp: App {
var body: some Scene {
WindowGroup {
TestView()
.toolbar(content: {
ForEach(1...100, id: \.self) { _ in
Text("Hello World")
}
})
}
}
}
struct TestView: View {
@State var strings = ["Hello 1", "Hello 2"]
@State var bool = false
let timer = Timer.publish(every: 0.1, on: .main, in: .common).autoconnect()
@State var selected: Int?
var body: some View {
List(strings.indices, id: \.self, selection: $selected) { stringIndex in
Text(strings[stringIndex])
}
.onReceive(timer) { input in
if bool == true { selected = 0 }
else { selected = 1 }
bool = !bool
}
}
}
This is not possible for my original app though, because I need to dynamically switch the toolbar depending on context. This still seems like a pretty significant bug. How can I work around this?
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: