Skip to content

Commit

Permalink
Fixing Theme not updating on click (#1255)
Browse files Browse the repository at this point in the history
Updating themModel to be @StateObject
  • Loading branch information
bombardier200 authored May 1, 2023
1 parent f20f9dc commit 39fc8a7
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions CodeEdit/Features/CodeFile/CodeFileView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ struct CodeFileView: View {
@Environment(\.colorScheme)
private var colorScheme

@StateObject
private var themeModel: ThemeModel = .shared

private var cancellables = [AnyCancellable]()

private let isEditable: Bool
Expand Down Expand Up @@ -99,15 +102,15 @@ struct CodeFileView: View {
)
// minHeight zero fixes a bug where the app would freeze if the contents of the file are empty.
.frame(minHeight: .zero, maxHeight: .infinity)
.onChange(of: ThemeModel.shared.selectedTheme) { newValue in
.onChange(of: themeModel.selectedTheme) { newValue in
guard let theme = newValue else { return }
self.selectedTheme = theme
}
.onChange(of: colorScheme) { newValue in
if matchAppearance {
ThemeModel.shared.selectedTheme = newValue == .dark
? ThemeModel.shared.selectedDarkTheme!
: ThemeModel.shared.selectedLightTheme!
themeModel.selectedTheme = newValue == .dark
? themeModel.selectedDarkTheme
: themeModel.selectedLightTheme
}
}
.onChange(of: settingsFont) { _ in
Expand Down

0 comments on commit 39fc8a7

Please sign in to comment.