iOS18 SwiftUI Bug: Theme Change Issue

Yet another bug, I suppose, on iOS 18. This time it relates to the SwiftUI framework, and to be precise, it's about the theme change functionality. It no longer works properly on iOS 18, while it’s not an issue on iOS 17.

Demo app available at: https://github.com/m4rqs/iOS18ThemeIssue

Steps to reproduce:

  • Assume the system is set to use the light theme.
  • Go to the Settings tab.
  • Switch the colour scheme to Dark.
  • Switch the colour scheme to System (this no longer works).
  • Switch the colour scheme to Light (the tab bar is not updated if the content page is long enough and go beyond current view).
  • Switch between tabs (tab bar icons are greyed)

enum Theme: Int {
    case system
    case light
    case dark
}

struct SettingsView: View {
    @State private var theme: Theme = .system
    @State private var colorScheme: ColorScheme? = nil

    var body: some View {
        Form {
            Section(header: Text("General")) {
                Picker("Colour Scheme", selection: $theme) {
                    Text("System").tag(Theme.system)
                    Text("Light").tag(Theme.light)
                    Text("Dark").tag(Theme.dark)
                }
                .preferredColorScheme(colorScheme)
                .onChange(of: theme) {
                    switch theme {
                        case .light: colorScheme = .light
                        case .dark: colorScheme = .dark
                        default: colorScheme = nil
                    }
                }
            }
        }
    }
}
iOS18 SwiftUI Bug: Theme Change Issue
 
 
Q