diff --git a/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift b/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift index 79bd6c40b..4eca657e8 100644 --- a/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift +++ b/apple/OmnivoreKit/Sources/Views/Article/WebAppViewCoordinator.swift @@ -2,6 +2,7 @@ import SwiftUI import WebKit final class WebAppViewCoordinator: NSObject { + let navBarHeight = LinkItemDetailView.navBarHeight var webViewActionHandler: (WKScriptMessage) -> Void = { _ in } var linkHandler: (URL) -> Void = { _ in } var needsReload = true @@ -54,9 +55,9 @@ extension WebAppViewCoordinator: UIScrollViewDelegate { return } - if yOffset < 30 { + if yOffset < navBarHeight { let isScrollingUp = yOffsetAtStartOfDrag ?? 0 > yOffset - updateNavBarVisibilityRatio(isScrollingUp ? 1 : 1 - (yOffset / 30)) + updateNavBarVisibilityRatio(isScrollingUp ? 1 : 1 - (yOffset / navBarHeight)) return } @@ -64,7 +65,7 @@ extension WebAppViewCoordinator: UIScrollViewDelegate { if yOffset > yOffsetAtStartOfDrag, !isNavBarHidden { let translation = yOffset - yOffsetAtStartOfDrag - let ratio = translation < 30 ? translation / 30 : 0 + let ratio = translation < navBarHeight ? 1 - (translation / navBarHeight) : 0 isNavBarHidden = ratio == 0 updateNavBarVisibilityRatio(ratio) } diff --git a/apple/OmnivoreKit/Sources/Views/LinkedItemDetail/LinkItemDetailView.swift b/apple/OmnivoreKit/Sources/Views/LinkedItemDetail/LinkItemDetailView.swift index 8c5a9d1f0..c3576ba81 100644 --- a/apple/OmnivoreKit/Sources/Views/LinkedItemDetail/LinkItemDetailView.swift +++ b/apple/OmnivoreKit/Sources/Views/LinkedItemDetail/LinkItemDetailView.swift @@ -27,6 +27,7 @@ public final class LinkItemDetailViewModel: ObservableObject { public struct LinkItemDetailView: View { @Environment(\.presentationMode) var presentationMode: Binding + static let navBarHeight = 50.0 @ObservedObject private var viewModel: LinkItemDetailViewModel @State private var showFontSizePopover = false @State private var navBarVisibilityRatio = 1.0 @@ -73,20 +74,22 @@ public struct LinkItemDetailView: View { action: { self.presentationMode.wrappedValue.dismiss() }, label: { Image(systemName: "chevron.backward") - .font(.appTitleThree) + .font(.appTitle) .foregroundColor(.appGrayTextContrast) .padding(.horizontal) - .padding(.bottom, 5) } ) + .scaleEffect(navBarVisibilityRatio) Spacer() Button( action: { showFontSizePopover = true }, label: { Image(systemName: "textformat.size") + .font(.appTitle) } ) .padding(.horizontal) + .scaleEffect(navBarVisibilityRatio) #if os(iOS) .fittedPopover(isPresented: $showFontSizePopover) { FontSizeAdjustmentPopoverView( @@ -96,15 +99,13 @@ public struct LinkItemDetailView: View { } #endif } - .frame(height: 30 * navBarVisibilityRatio) + .frame(height: LinkItemDetailView.navBarHeight * navBarVisibilityRatio) .opacity(navBarVisibilityRatio) - .offset(x: 0.0, y: -30 * (1 - navBarVisibilityRatio)) } if let webAppWrapperViewModel = viewModel.webAppWrapperViewModel { WebAppWrapperView( viewModel: webAppWrapperViewModel, navBarVisibilityRatioUpdater: { - print($0) navBarVisibilityRatio = $0 } ) @@ -164,3 +165,15 @@ public struct LinkItemDetailView: View { } } } + +// Enable swipe to go back behavior if nav bar is hidden +extension UINavigationController: UIGestureRecognizerDelegate { + override open func viewDidLoad() { + super.viewDidLoad() + interactivePopGestureRecognizer?.delegate = self + } + + public func gestureRecognizerShouldBegin(_: UIGestureRecognizer) -> Bool { + viewControllers.count > 1 + } +}