mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
create a web prefs form sheet
This commit is contained in:
parent
b32db17dbc
commit
f04621a8fa
2 changed files with 61 additions and 12 deletions
|
|
@ -26,13 +26,6 @@ import WebKit
|
|||
@Environment(\.presentationMode) var presentationMode: Binding<PresentationMode>
|
||||
@StateObject var viewModel = WebReaderViewModel()
|
||||
|
||||
var fontAdjustmentPopoverView: some View {
|
||||
FontSizeAdjustmentPopoverView(
|
||||
increaseFontAction: { increaseFontActionID = UUID() },
|
||||
decreaseFontAction: { decreaseFontActionID = UUID() }
|
||||
)
|
||||
}
|
||||
|
||||
func webViewActionHandler(message: WKScriptMessage, replyHandler: WKScriptMessageReplyHandler?) {
|
||||
if let replyHandler = replyHandler {
|
||||
viewModel.webViewActionWithReplyHandler(
|
||||
|
|
@ -150,9 +143,6 @@ import WebKit
|
|||
},
|
||||
webViewActionHandler: webViewActionHandler,
|
||||
navBarVisibilityRatioUpdater: {
|
||||
// if $0 < 1 {
|
||||
// showPreferencesPopover = false
|
||||
// }
|
||||
navBarVisibilityRatio = $0
|
||||
},
|
||||
increaseFontActionID: $increaseFontActionID,
|
||||
|
|
@ -202,8 +192,11 @@ import WebKit
|
|||
Spacer()
|
||||
}
|
||||
}
|
||||
.popover(isPresented: $showPreferencesPopover) {
|
||||
Text("Popover")
|
||||
.formSheet(isPresented: $showPreferencesPopover) {
|
||||
WebPreferencesPopoverView(
|
||||
increaseFontAction: { increaseFontActionID = UUID() },
|
||||
decreaseFontAction: { decreaseFontActionID = UUID() }
|
||||
)
|
||||
}
|
||||
.onDisappear {
|
||||
// Clear the shared webview content when exiting
|
||||
|
|
|
|||
|
|
@ -1,6 +1,62 @@
|
|||
import SwiftUI
|
||||
import Utils
|
||||
|
||||
public struct WebPreferencesPopoverView: View {
|
||||
let increaseFontAction: () -> Void
|
||||
let decreaseFontAction: () -> Void
|
||||
|
||||
static let preferredWebFontSizeKey = UserDefaultKey.preferredWebFontSize.rawValue
|
||||
#if os(macOS)
|
||||
@AppStorage(preferredWebFontSizeKey) var storedFontSize = Int(NSFont.userFont(ofSize: 16)?.pointSize ?? 16)
|
||||
#else
|
||||
@AppStorage(preferredWebFontSizeKey) var storedFontSize: Int = UITraitCollection.current.preferredWebFontSize
|
||||
#endif
|
||||
|
||||
public init(
|
||||
increaseFontAction: @escaping () -> Void,
|
||||
decreaseFontAction: @escaping () -> Void
|
||||
) {
|
||||
self.increaseFontAction = increaseFontAction
|
||||
self.decreaseFontAction = decreaseFontAction
|
||||
}
|
||||
|
||||
public var body: some View {
|
||||
HStack(alignment: .center, spacing: 0) {
|
||||
Button(
|
||||
action: {
|
||||
storedFontSize = max(storedFontSize - 2, 10)
|
||||
decreaseFontAction()
|
||||
},
|
||||
label: {
|
||||
Image(systemName: "minus")
|
||||
#if os(iOS)
|
||||
.foregroundColor(.systemLabel)
|
||||
.padding()
|
||||
#endif
|
||||
}
|
||||
)
|
||||
.frame(width: 55, height: 40, alignment: .center)
|
||||
Divider()
|
||||
.frame(height: 30)
|
||||
.background(Color.systemLabel)
|
||||
Button(
|
||||
action: {
|
||||
storedFontSize = min(storedFontSize + 2, 28)
|
||||
increaseFontAction()
|
||||
},
|
||||
label: {
|
||||
Image(systemName: "plus")
|
||||
#if os(iOS)
|
||||
.foregroundColor(.systemLabel)
|
||||
.padding()
|
||||
#endif
|
||||
}
|
||||
)
|
||||
.frame(width: 55, height: 40, alignment: .center)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public struct FontSizeAdjustmentPopoverView: View {
|
||||
let increaseFontAction: () -> Void
|
||||
let decreaseFontAction: () -> Void
|
||||
|
|
|
|||
Loading…
Reference in a new issue