New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AppStorage + Toggle in Settings will cause a UI render issue #117
Comments
Suspect this is a bug introduced by SwiftUI with AnyView usage in Settings. Current workaround: (Move import SwiftUI
import Settings
struct ContentView: View {
@State private var s = S()
var body: some View {
Settings.Container(contentWidth: 600) {
Settings.Section {
Text("Hello")
} content: {
Section {
Toggle("Demo Toggle", isOn: $s.toggle)
Toggle("Demo Toggle2", isOn: $s.toggle2)
.padding()
}
}
}
}
}
@Observable
class S {
var toggle: Bool {
get {
access(keyPath: \.toggle)
return UserDefaults.standard.bool(forKey: "Test")
}
set {
withMutation(keyPath: \.toggle) {
UserDefaults.standard.setValue(newValue, forKey: "Test")
}
}
}
var toggle2 = false
} |
FThe mini reproductive ContentView(Platform independent) code. This is definitely a bug behavior on iOS 17 and macOS 14. But the bug's behavior is a little different ContentView.swift.zip @AppStorage("Test") private var toggle = false
@State private var toggle2 = false
Container {
Section {
Toggle("Demo Toggle", isOn: $toggle)
Toggle("Demo Toggle2", isOn: $toggle2)
}
}
Container2(sections: [
Section {
Toggle("Demo Toggle", isOn: $toggle)
Toggle("Demo Toggle2", isOn: $toggle2)
}
]) macOS 14:
iOS 17
Filed to Apple via FB13341321 |
Normally both toggle will work fine. But if we write such code under
Settings.Section
and build it with macOS 14 SDK(Xcode 15.0)The toggle2 will work while toggle will not. The value stored in UserDefaults is actually changed in both case, but the UI is not updating in the first case automatically unless we trigger an update for toggle2.
See screen recording below if my description is vague
2023-11-01.14.04.28.mov
The text was updated successfully, but these errors were encountered: