diff --git a/MarkdownViewer/ViewModels/DocumentState.swift b/MarkdownViewer/ViewModels/DocumentState.swift index 9f593cf..ce6871f 100644 --- a/MarkdownViewer/ViewModels/DocumentState.swift +++ b/MarkdownViewer/ViewModels/DocumentState.swift @@ -2,6 +2,7 @@ import Combine import CoreGraphics import Foundation import Markdown +import SwiftUI class DocumentState: ObservableObject { @Published var htmlContent: String = "" @@ -134,7 +135,9 @@ class DocumentState: ObservableObject { guard let self = self else { return } let newModDate = try? FileManager.default.attributesOfItem(atPath: url.path)[.modificationDate] as? Date if newModDate != self.lastModificationDate { - self.fileChanged = true + self.lastModificationDate = newModDate + self.reload() + withAnimation(.easeInOut(duration: 0.2)) { self.fileChanged = true } } } diff --git a/MarkdownViewer/Views/ContentView.swift b/MarkdownViewer/Views/ContentView.swift index 2d83e10..70d2233 100644 --- a/MarkdownViewer/Views/ContentView.swift +++ b/MarkdownViewer/Views/ContentView.swift @@ -80,7 +80,9 @@ struct ContentView: View { } } .onExitCommand { - if documentState.isShowingFindBar { + if documentState.fileChanged { + withAnimation(.easeInOut(duration: 0.2)) { documentState.fileChanged = false } + } else if documentState.isShowingFindBar { documentState.hideFindBar() } } @@ -110,22 +112,24 @@ struct ContentView: View { if documentState.fileChanged || documentState.isShowingFindBar { VStack(alignment: .trailing, spacing: 8) { if documentState.fileChanged { - Button(action: { - documentState.reload() - }) { - HStack(spacing: 4) { - Image(systemName: "arrow.clockwise") - .font(.system(size: 11, weight: .medium)) - Text("File changed") - .font(.system(size: 11, weight: .medium)) - } - .padding(.horizontal, 10) - .padding(.vertical, 6) - .background(Color.orange.opacity(0.9)) - .foregroundColor(.white) - .cornerRadius(6) + HStack(spacing: 6) { + Image(systemName: "arrow.triangle.2.circlepath") + .font(.system(size: 11, weight: .medium)) + Text("File updated") + .font(.system(size: 11, weight: .medium)) + Text("esc to dismiss") + .font(.system(size: 10)) + .opacity(0.7) + } + .padding(.horizontal, 10) + .padding(.vertical, 6) + .background(Color.accentColor.opacity(0.85)) + .foregroundColor(.white) + .cornerRadius(6) + .onTapGesture { + withAnimation(.easeInOut(duration: 0.2)) { documentState.fileChanged = false } } - .buttonStyle(.plain) + .transition(.opacity.combined(with: .move(edge: .top))) } if documentState.isShowingFindBar {