Separate bottom bar visibility so we dont display the top bar when scrolled to bottom

This commit is contained in:
Jackson Harper
2024-02-05 17:48:31 +08:00
parent 14811ee2d4
commit 839b364d13
3 changed files with 15 additions and 4 deletions

View File

@ -20,6 +20,7 @@ struct WebReader: PlatformViewRepresentable {
@Binding var showNavBarActionID: UUID?
@Binding var shareActionID: UUID?
@Binding var annotation: String
@Binding var showBottomBar: Bool
@Binding var showHighlightAnnotationModal: Bool
func makeCoordinator() -> WebReaderCoordinator {
@ -90,6 +91,9 @@ struct WebReader: PlatformViewRepresentable {
context.coordinator.webViewActionHandler = webViewActionHandler
context.coordinator.updateNavBarVisibility = navBarVisibilityUpdater
context.coordinator.scrollPercentHandler = scrollPercentHandler
context.coordinator.updateShowBottomBar = { newValue in
self.showBottomBar = newValue
}
context.coordinator.articleContentID = articleContent.id
loadContent(webView: webView)

View File

@ -21,6 +21,7 @@ struct WebReaderContainerView: View {
@State private var hasPerformedHighlightMutations = false
@State var showHighlightAnnotationModal = false
@State private var navBarVisible = true
@State var showBottomBar = true
@State private var progressViewOpacity = 0.0
@State var readerSettingsChangedTransactionID: UUID?
@State var annotationSaveTransactionID: UUID?
@ -86,6 +87,7 @@ struct WebReaderContainerView: View {
private func tapHandler() {
withAnimation(.easeIn(duration: 0.08)) {
navBarVisible = !navBarVisible
showBottomBar = navBarVisible
showNavBarActionID = UUID()
}
}
@ -114,6 +116,7 @@ struct WebReaderContainerView: View {
case "dismissNavBars":
withAnimation {
navBarVisible = false
showBottomBar = false
showNavBarActionID = UUID()
}
default:
@ -380,6 +383,7 @@ struct WebReaderContainerView: View {
navBarVisibilityUpdater: { visible in
withAnimation {
navBarVisible = visible
showBottomBar = visible
}
},
readerSettingsChangedTransactionID: $readerSettingsChangedTransactionID,
@ -387,6 +391,7 @@ struct WebReaderContainerView: View {
showNavBarActionID: $showNavBarActionID,
shareActionID: $shareActionID,
annotation: $annotation,
showBottomBar: $showBottomBar,
showHighlightAnnotationModal: $showHighlightAnnotationModal
)
.background(ThemeManager.currentBgColor)
@ -586,13 +591,13 @@ struct WebReaderContainerView: View {
if let audioProperties = audioController.itemAudioProperties {
MiniPlayerViewer(itemAudioProperties: audioProperties)
.padding(.top, 10)
.padding(.bottom, navBarVisible ? 10 : 40)
.padding(.bottom, showBottomBar ? 10 : 40)
.background(Color.themeTabBarColor)
.onTapGesture {
showExpandedAudioPlayer = true
}
}
if navBarVisible {
if showBottomBar {
CustomToolBar(
isFollowing: item.folder == "following",
isArchived: item.isArchived,

View File

@ -20,6 +20,7 @@ final class WebReaderCoordinator: NSObject {
var previousShowNavBarActionID: UUID?
var previousShareActionID: UUID?
var updateNavBarVisibility: (Bool) -> Void = { _ in }
var updateShowBottomBar: (Bool) -> Void = { _ in }
var articleContentID = UUID()
private var yOffsetAtStartOfDrag: Double?
private var lastYOffset: Double = 0
@ -123,8 +124,9 @@ extension WebReaderCoordinator: WKNavigationDelegate {
// if at bottom show the controls
if yOffset + scrollView.visibleSize.height > scrollView.contentSize.height - 140 {
navBarVisible = true
scrollView.contentInset.top = navBarVisible ? readerViewNavBarHeight : 0
updateShowBottomBar(true)
} else {
updateShowBottomBar(false)
}
let percent = Int(((yOffset + scrollView.visibleSize.height) / scrollView.contentSize.height) * 100)