From 11c4c1a87be8252dc020928236bd4462e098a232 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Fri, 3 Jun 2022 18:39:20 -0700 Subject: [PATCH 1/3] embed reder pref popover in a nav view --- .../Views/FontSizeAdjustmentPopoverView.swift | 139 ++++++++++-------- 1 file changed, 76 insertions(+), 63 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift index e27e03035..24643deaa 100644 --- a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift +++ b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift @@ -41,74 +41,87 @@ public struct WebPreferencesPopoverView: View { self.dismissAction = dismissAction } - public var body: some View { - VStack(alignment: .center) { - Text("Reader Preferences") - .foregroundColor(.appGrayText) - .font(Font.system(size: 17, weight: .semibold)) - - List { - Section("Sizing") { - LabelledStepper( - labelText: "Font Size:", - onIncrement: { - storedFontSize = min(storedFontSize + 2, 28) - updateFontAction() - }, - onDecrement: { - storedFontSize = max(storedFontSize - 2, 10) - updateFontAction() - } - ) - - if UIDevice.isIPad { - LabelledStepper( - labelText: "Margin:", - onIncrement: { - storedMargin = min(storedMargin + 45, 560) - updateMarginAction() - }, - onDecrement: { - storedMargin = max(storedMargin - 45, 200) - updateMarginAction() + var fontList: some View { + List { + ForEach(WebFont.allCases, id: \.self) { font in + Button( + action: { + preferredFont = font.rawValue + updateFontFamilyAction() + }, + label: { + HStack { + Text(font.rawValue).foregroundColor(.appGrayTextContrast) + Spacer() + if font.rawValue == preferredFont { + Image(systemName: "checkmark").foregroundColor(.appGrayTextContrast) } - ) - } - - LabelledStepper( - labelText: "Line Spacing:", - onIncrement: { - storedLineSpacing = min(storedLineSpacing + 25, 300) - updateLineHeightAction() - }, - onDecrement: { - storedLineSpacing = max(storedLineSpacing - 25, 100) - updateLineHeightAction() } - ) - } - Section("Font Family") { - ForEach(WebFont.allCases, id: \.self) { font in - Button( - action: { - preferredFont = font.rawValue - updateFontFamilyAction() - }, - label: { - HStack { - Text(font.rawValue).foregroundColor(.appGrayTextContrast) - Spacer() - if font.rawValue == preferredFont { - Image(systemName: "checkmark").foregroundColor(.appGrayTextContrast) - } - } - } - ) } - } + ) } } - .padding() + } + + public var body: some View { + NavigationView { + VStack(alignment: .center) { + Text("Reader Preferences") + .foregroundColor(.appGrayText) + .font(Font.system(size: 17, weight: .semibold)) + + LabelledStepper( + labelText: "Font Size:", + onIncrement: { + storedFontSize = min(storedFontSize + 2, 28) + updateFontAction() + }, + onDecrement: { + storedFontSize = max(storedFontSize - 2, 10) + updateFontAction() + } + ) + + if UIDevice.isIPad { + LabelledStepper( + labelText: "Margin:", + onIncrement: { + storedMargin = min(storedMargin + 45, 560) + updateMarginAction() + }, + onDecrement: { + storedMargin = max(storedMargin - 45, 200) + updateMarginAction() + } + ) + } + + LabelledStepper( + labelText: "Line Spacing:", + onIncrement: { + storedLineSpacing = min(storedLineSpacing + 25, 300) + updateLineHeightAction() + }, + onDecrement: { + storedLineSpacing = max(storedLineSpacing - 25, 100) + updateLineHeightAction() + } + ) + + HStack { + NavigationLink(destination: fontList) { + Text("Change Reader Font") + } + Image(systemName: "chevron.right") + Spacer() + } + .frame(height: 40) + + Spacer() + } + .padding() + } + .accentColor(.appGrayTextContrast) } } From 2991549413ade039a562c2632e28c71933a3a591 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Fri, 3 Jun 2022 18:52:26 -0700 Subject: [PATCH 2/3] attempt to adjust form sheet size --- .../Views/WebReader/WebReaderContainer.swift | 2 +- .../Views/FontSizeAdjustmentPopoverView.swift | 2 ++ .../Sources/Views/FormSheetWrapper.swift | 25 ++++++++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift index 8564e9a44..5d33b577b 100644 --- a/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift +++ b/apple/OmnivoreKit/Sources/App/Views/WebReader/WebReaderContainer.swift @@ -196,7 +196,7 @@ import WebKit Spacer() } } - .formSheet(isPresented: $showPreferencesPopover) { + .formSheet(isPresented: $showPreferencesPopover, useSmallDetent: false) { WebPreferencesPopoverView( updateFontFamilyAction: { updateFontFamilyActionID = UUID() }, updateFontAction: { updateFontActionID = UUID() }, diff --git a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift index 24643deaa..75baa2afa 100644 --- a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift +++ b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift @@ -122,6 +122,8 @@ public struct WebPreferencesPopoverView: View { .padding() } .accentColor(.appGrayTextContrast) + .navigationTitle("kmlm") + .navigationBarTitleDisplayMode(.inline) } } diff --git a/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift b/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift index dfd0776bb..ae6e3ef10 100644 --- a/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift +++ b/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift @@ -13,25 +13,31 @@ import SwiftUI var content: () -> Content var onDismiss: (() -> Void)? var modalSize: CGSize + let useSmallDetent: Bool private var hostVC: UIHostingController? @available(*, unavailable) required init?(coder _: NSCoder) { fatalError("") } - init(content: @escaping () -> Content, modalSize: CGSize) { + init(content: @escaping () -> Content, modalSize: CGSize, useSmallDetent: Bool) { self.content = content self.modalSize = modalSize + self.useSmallDetent = useSmallDetent super.init(nibName: nil, bundle: nil) } func show() { guard hostVC == nil else { return } - // WIP: use subclass to control a max height we pass in for iphone -// let controller = FormSheetHostingController(rootView: content(), height: 100) - let controller = UIHostingController(rootView: content()) + let controller: UIHostingController = { + if UIDevice.isIPhone, useSmallDetent { + return FormSheetHostingController(rootView: content(), height: 100) + } else { + return UIHostingController(rootView: content()) + } + }() - if controller.traitCollection.userInterfaceIdiom == .phone { + if UIDevice.isIPhone { if let sheet = controller.sheetPresentationController { // sheet.preferredCornerRadius = 32 sheet.prefersGrabberVisible = true @@ -68,12 +74,17 @@ import SwiftUI @Binding var show: Bool let modalSize: CGSize + let useSmallDetent: Bool let content: () -> Content func makeUIViewController( context _: UIViewControllerRepresentableContext> ) -> FormSheetWrapper { - let controller = FormSheetWrapper(content: content, modalSize: modalSize) + let controller = FormSheetWrapper( + content: content, + modalSize: modalSize, + useSmallDetent: useSmallDetent + ) controller.onDismiss = { self.show = false } return controller } @@ -94,12 +105,14 @@ import SwiftUI func formSheet( isPresented: Binding, modalSize: CGSize = CGSize(width: 320, height: 320), + useSmallDetent: Bool = false, @ViewBuilder content: @escaping () -> Content ) -> some View { background( FormSheet( show: isPresented, modalSize: modalSize, + useSmallDetent: useSmallDetent, content: content ) ) From 5de414fae9cf6b85263c4df588cce0b7fffd8453 Mon Sep 17 00:00:00 2001 From: Satindar Dhillon Date: Fri, 3 Jun 2022 20:35:15 -0700 Subject: [PATCH 3/3] hide nav bar in reader pres view --- .../Sources/Views/FontSizeAdjustmentPopoverView.swift | 5 +++-- apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift | 3 +-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift index 75baa2afa..6ec7d051c 100644 --- a/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift +++ b/apple/OmnivoreKit/Sources/Views/FontSizeAdjustmentPopoverView.swift @@ -60,7 +60,9 @@ public struct WebPreferencesPopoverView: View { } ) } + .padding() } + .navigationBarTitleDisplayMode(.inline) } public var body: some View { @@ -120,10 +122,9 @@ public struct WebPreferencesPopoverView: View { Spacer() } .padding() + .navigationBarHidden(true) } .accentColor(.appGrayTextContrast) - .navigationTitle("kmlm") - .navigationBarTitleDisplayMode(.inline) } } diff --git a/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift b/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift index ae6e3ef10..4bab1d0d8 100644 --- a/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift +++ b/apple/OmnivoreKit/Sources/Views/FormSheetWrapper.swift @@ -39,8 +39,7 @@ import SwiftUI if UIDevice.isIPhone { if let sheet = controller.sheetPresentationController { - // sheet.preferredCornerRadius = 32 - sheet.prefersGrabberVisible = true + sheet.prefersGrabberVisible = false sheet.detents = [.medium()] sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true }