Skip to content

Commit

Permalink
支持monterey
Browse files Browse the repository at this point in the history
  • Loading branch information
caol64 committed Oct 21, 2024
1 parent a987371 commit c0ec902
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
26 changes: 15 additions & 11 deletions WenYan/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import SwiftUI

struct ContentView: View {

@State private var markdownViewModel: MarkdownViewModel
@State private var htmlViewModel: HtmlViewModel
@State private var appState: AppState
@ObservedObject private var markdownViewModel: MarkdownViewModel
@ObservedObject private var htmlViewModel: HtmlViewModel
@ObservedObject private var appState: AppState

init(appState: AppState) {
_markdownViewModel = State(initialValue: MarkdownViewModel(appState: appState))
_htmlViewModel = State(initialValue: HtmlViewModel(appState: appState))
_markdownViewModel = ObservedObject(initialValue: MarkdownViewModel(appState: appState))
_htmlViewModel = ObservedObject(initialValue: HtmlViewModel(appState: appState))
self.appState = appState
}

Expand Down Expand Up @@ -129,8 +129,8 @@ struct ContentView: View {
.environment(\.colorScheme, .light)
}
}
.onChange(of: markdownViewModel.scrollFactor) {
htmlViewModel.scroll(scrollFactor: markdownViewModel.scrollFactor)
.onReceive(markdownViewModel.$scrollFactor) { newScrollFactor in
htmlViewModel.scroll(scrollFactor: newScrollFactor)
}
}
.background(.white)
Expand All @@ -141,8 +141,8 @@ struct ContentView: View {
htmlViewModel.content = markdownViewModel.content
}
}
.onChange(of: markdownViewModel.content) {
htmlViewModel.content = markdownViewModel.content
.onReceive(markdownViewModel.$content) { newContent in
htmlViewModel.content = newContent
htmlViewModel.onUpdate()
}
.toolbar() {
Expand All @@ -166,20 +166,24 @@ struct ContentView: View {

var body: some View {
VStack {
List(selection: $htmlViewModel.gzhTheme) {
List {
ForEach(Platform.gzh.themes, id: \.self) { theme in
HStack {
Text(theme.name)
Spacer()
Text(theme.author)
}
.background(htmlViewModel.gzhTheme == theme ? Color.gray.opacity(0.3) : Color.clear)
.onTapGesture {
htmlViewModel.gzhTheme = theme
}
}
}
.padding(5)
.listStyle(PlainListStyle())
.background(Color.clear)
.frame(width: menuWidth, height: menuHeight)
.onChange(of: htmlViewModel.gzhTheme) {
.onReceive(htmlViewModel.$gzhTheme) { _ in
htmlViewModel.changeTheme()
}
}
Expand Down
2 changes: 1 addition & 1 deletion WenYan/WenYanApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import SwiftData
@main
struct WenYanApp: App {

@State private var appState = AppState()
@ObservedObject private var appState = AppState()

var body: some Scene {
WindowGroup {
Expand Down

0 comments on commit c0ec902

Please sign in to comment.