mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
bundle all reader preferences cahnges into a single transaction
This commit is contained in:
parent
1bfe7ff18a
commit
fb361096fa
4 changed files with 18 additions and 67 deletions
|
|
@ -11,11 +11,7 @@ struct WebReader: PlatformViewRepresentable {
|
|||
let webViewActionHandler: (WKScriptMessage, WKScriptMessageReplyHandler?) -> Void
|
||||
let navBarVisibilityRatioUpdater: (Double) -> Void
|
||||
|
||||
@Binding var updateFontFamilyActionID: UUID?
|
||||
@Binding var updateFontActionID: UUID?
|
||||
@Binding var updateTextContrastActionID: UUID?
|
||||
@Binding var updateMaxWidthActionID: UUID?
|
||||
@Binding var updateLineHeightActionID: UUID?
|
||||
@Binding var readerSettingsChangedTransactionID: UUID?
|
||||
@Binding var annotationSaveTransactionID: UUID?
|
||||
@Binding var showNavBarActionID: UUID?
|
||||
@Binding var shareActionID: UUID?
|
||||
|
|
@ -79,35 +75,18 @@ struct WebReader: PlatformViewRepresentable {
|
|||
return webView
|
||||
}
|
||||
|
||||
// swiftlint:disable:next cyclomatic_complexity
|
||||
private func updatePlatformView(_ webView: WKWebView, context: Context) {
|
||||
if annotationSaveTransactionID != context.coordinator.lastSavedAnnotationID {
|
||||
context.coordinator.lastSavedAnnotationID = annotationSaveTransactionID
|
||||
(webView as? OmnivoreWebView)?.dispatchEvent(.saveAnnotation(annotation: annotation))
|
||||
}
|
||||
|
||||
if updateFontFamilyActionID != context.coordinator.previousUpdateFontFamilyActionID {
|
||||
context.coordinator.previousUpdateFontFamilyActionID = updateFontFamilyActionID
|
||||
if readerSettingsChangedTransactionID != context.coordinator.previousReaderSettingsChangedTransactionID {
|
||||
context.coordinator.previousReaderSettingsChangedTransactionID = readerSettingsChangedTransactionID
|
||||
(webView as? OmnivoreWebView)?.updateFontFamily()
|
||||
}
|
||||
|
||||
if updateFontActionID != context.coordinator.previousUpdateFontActionID {
|
||||
context.coordinator.previousUpdateFontActionID = updateFontActionID
|
||||
(webView as? OmnivoreWebView)?.updateFontSize()
|
||||
}
|
||||
|
||||
if updateTextContrastActionID != context.coordinator.previousUpdateTextContrastActionID {
|
||||
context.coordinator.previousUpdateTextContrastActionID = updateTextContrastActionID
|
||||
(webView as? OmnivoreWebView)?.updateTextContrast()
|
||||
}
|
||||
|
||||
if updateMaxWidthActionID != context.coordinator.previousUpdateMaxWidthActionID {
|
||||
context.coordinator.previousUpdateMaxWidthActionID = updateMaxWidthActionID
|
||||
(webView as? OmnivoreWebView)?.updateMaxWidthPercentage()
|
||||
}
|
||||
|
||||
if updateLineHeightActionID != context.coordinator.previousUpdateLineHeightActionID {
|
||||
context.coordinator.previousUpdateLineHeightActionID = updateLineHeightActionID
|
||||
(webView as? OmnivoreWebView)?.updateLineHeight()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -15,11 +15,7 @@ struct WebReaderContainerView: View {
|
|||
@State private var navBarVisibilityRatio = 1.0
|
||||
@State private var showDeleteConfirmation = false
|
||||
@State private var progressViewOpacity = 0.0
|
||||
@State var updateFontFamilyActionID: UUID?
|
||||
@State var updateFontActionID: UUID?
|
||||
@State var updateTextContrastActionID: UUID?
|
||||
@State var updateMaxWidthActionID: UUID?
|
||||
@State var updateLineHeightActionID: UUID?
|
||||
@State var readerSettingsChangedTransactionID: UUID?
|
||||
@State var annotationSaveTransactionID: UUID?
|
||||
@State var showNavBarActionID: UUID?
|
||||
@State var shareActionID: UUID?
|
||||
|
|
@ -162,11 +158,7 @@ struct WebReaderContainerView: View {
|
|||
#if os(iOS)
|
||||
var webPreferencesPopoverView: some View {
|
||||
WebPreferencesPopoverView(
|
||||
updateFontFamilyAction: { updateFontFamilyActionID = UUID() },
|
||||
updateFontAction: { updateFontActionID = UUID() },
|
||||
updateTextContrastAction: { updateTextContrastActionID = UUID() },
|
||||
updateMaxWidthAction: { updateMaxWidthActionID = UUID() },
|
||||
updateLineHeightAction: { updateLineHeightActionID = UUID() },
|
||||
updateReaderPreferences: { readerSettingsChangedTransactionID = UUID() },
|
||||
dismissAction: { showPreferencesPopover = false }
|
||||
)
|
||||
}
|
||||
|
|
@ -189,11 +181,7 @@ struct WebReaderContainerView: View {
|
|||
navBarVisibilityRatioUpdater: {
|
||||
navBarVisibilityRatio = $0
|
||||
},
|
||||
updateFontFamilyActionID: $updateFontFamilyActionID,
|
||||
updateFontActionID: $updateFontActionID,
|
||||
updateTextContrastActionID: $updateTextContrastActionID,
|
||||
updateMaxWidthActionID: $updateMaxWidthActionID,
|
||||
updateLineHeightActionID: $updateLineHeightActionID,
|
||||
readerSettingsChangedTransactionID: $readerSettingsChangedTransactionID,
|
||||
annotationSaveTransactionID: $annotationSaveTransactionID,
|
||||
showNavBarActionID: $showNavBarActionID,
|
||||
shareActionID: $shareActionID,
|
||||
|
|
|
|||
|
|
@ -15,11 +15,7 @@ final class WebReaderCoordinator: NSObject {
|
|||
var linkHandler: (URL) -> Void = { _ in }
|
||||
var needsReload = false
|
||||
var lastSavedAnnotationID: UUID?
|
||||
var previousUpdateFontFamilyActionID: UUID?
|
||||
var previousUpdateFontActionID: UUID?
|
||||
var previousUpdateTextContrastActionID: UUID?
|
||||
var previousUpdateMaxWidthActionID: UUID?
|
||||
var previousUpdateLineHeightActionID: UUID?
|
||||
var previousReaderSettingsChangedTransactionID: UUID?
|
||||
var previousShowNavBarActionID: UUID?
|
||||
var previousShareActionID: UUID?
|
||||
var updateNavBarVisibilityRatio: (Double) -> Void = { _ in }
|
||||
|
|
|
|||
|
|
@ -26,11 +26,7 @@ public enum WebFont: String, CaseIterable {
|
|||
|
||||
#if os(iOS)
|
||||
public struct WebPreferencesPopoverView: View {
|
||||
let updateFontFamilyAction: () -> Void
|
||||
let updateFontAction: () -> Void
|
||||
let updateTextContrastAction: () -> Void
|
||||
let updateMaxWidthAction: () -> Void
|
||||
let updateLineHeightAction: () -> Void
|
||||
let updateReaderPreferences: () -> Void
|
||||
let dismissAction: () -> Void
|
||||
|
||||
@AppStorage(UserDefaultKey.preferredWebFontSize.rawValue) var storedFontSize: Int =
|
||||
|
|
@ -41,18 +37,10 @@ public enum WebFont: String, CaseIterable {
|
|||
@AppStorage(UserDefaultKey.prefersHighContrastWebFont.rawValue) var prefersHighContrastText = true
|
||||
|
||||
public init(
|
||||
updateFontFamilyAction: @escaping () -> Void,
|
||||
updateFontAction: @escaping () -> Void,
|
||||
updateTextContrastAction: @escaping () -> Void,
|
||||
updateMaxWidthAction: @escaping () -> Void,
|
||||
updateLineHeightAction: @escaping () -> Void,
|
||||
updateReaderPreferences: @escaping () -> Void,
|
||||
dismissAction: @escaping () -> Void
|
||||
) {
|
||||
self.updateFontFamilyAction = updateFontFamilyAction
|
||||
self.updateFontAction = updateFontAction
|
||||
self.updateTextContrastAction = updateTextContrastAction
|
||||
self.updateMaxWidthAction = updateMaxWidthAction
|
||||
self.updateLineHeightAction = updateLineHeightAction
|
||||
self.updateReaderPreferences = updateReaderPreferences
|
||||
self.dismissAction = dismissAction
|
||||
}
|
||||
|
||||
|
|
@ -62,7 +50,7 @@ public enum WebFont: String, CaseIterable {
|
|||
Button(
|
||||
action: {
|
||||
preferredFont = font.rawValue
|
||||
updateFontFamilyAction()
|
||||
updateReaderPreferences()
|
||||
},
|
||||
label: {
|
||||
HStack {
|
||||
|
|
@ -90,11 +78,11 @@ public enum WebFont: String, CaseIterable {
|
|||
labelText: "Font Size:",
|
||||
onIncrement: {
|
||||
storedFontSize = min(storedFontSize + 2, 28)
|
||||
updateFontAction()
|
||||
updateReaderPreferences()
|
||||
},
|
||||
onDecrement: {
|
||||
storedFontSize = max(storedFontSize - 2, 10)
|
||||
updateFontAction()
|
||||
updateReaderPreferences()
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -102,11 +90,11 @@ public enum WebFont: String, CaseIterable {
|
|||
labelText: "Margin:",
|
||||
onIncrement: {
|
||||
storedMaxWidthPercentage = max(storedMaxWidthPercentage - 10, 40)
|
||||
updateMaxWidthAction()
|
||||
updateReaderPreferences()
|
||||
},
|
||||
onDecrement: {
|
||||
storedMaxWidthPercentage = min(storedMaxWidthPercentage + 10, 100)
|
||||
updateMaxWidthAction()
|
||||
updateReaderPreferences()
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -114,11 +102,11 @@ public enum WebFont: String, CaseIterable {
|
|||
labelText: "Line Spacing:",
|
||||
onIncrement: {
|
||||
storedLineSpacing = min(storedLineSpacing + 25, 300)
|
||||
updateLineHeightAction()
|
||||
updateReaderPreferences()
|
||||
},
|
||||
onDecrement: {
|
||||
storedLineSpacing = max(storedLineSpacing - 25, 100)
|
||||
updateLineHeightAction()
|
||||
updateReaderPreferences()
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -126,7 +114,7 @@ public enum WebFont: String, CaseIterable {
|
|||
.frame(height: 40)
|
||||
.padding(.trailing, 6)
|
||||
.onChange(of: prefersHighContrastText) { _ in
|
||||
updateTextContrastAction()
|
||||
updateReaderPreferences()
|
||||
}
|
||||
|
||||
HStack {
|
||||
|
|
|
|||
Loading…
Reference in a new issue