SwiftUI Color doesn't update on main page

227 views Asked by At

All my text in my app use the color Color.textColor which changes due to a UserDefault setting:

extension Color {
    public static var textColor: Color {
        let color = UserDefaults.standard.bool(forKey: "redText") ? Color.red : Color.white
        return color
    }
}

This is changed via a toggle in my settings section. The problem is, when I toggle this it successfully changes all text colours all my views, apart from the main view.

I've made a gif here to showcase the problem: https://i.stack.imgur.com/a2nKr.jpg
The bug is there in both simulation and preview.

Edit: When I switch off/on the preview the main page colours actually update to the correct colour.

0

There are 0 answers