mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
WiP
This commit is contained in:
parent
e929c5d1a1
commit
ea93f3926e
3 changed files with 91 additions and 72 deletions
|
|
@ -29,7 +29,7 @@ import WebKit
|
|||
let webView = WebView(frame: CGRect.zero)
|
||||
let contentController = WKUserContentController()
|
||||
|
||||
webView.scrollView.isScrollEnabled = true
|
||||
webView.scrollView.contentInset.top = LinkItemDetailView.navBarHeight
|
||||
webView.navigationDelegate = context.coordinator
|
||||
webView.isOpaque = false
|
||||
webView.backgroundColor = UIColor.clear
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ final class WebAppViewCoordinator: NSObject {
|
|||
var navBarVisibilityRatio: Double = 1.0 {
|
||||
didSet {
|
||||
isNavBarHidden = navBarVisibilityRatio == 0
|
||||
print(navBarVisibilityRatio)
|
||||
updateNavBarVisibilityRatio(navBarVisibilityRatio)
|
||||
}
|
||||
}
|
||||
|
|
@ -48,24 +49,31 @@ extension WebAppViewCoordinator: WKNavigationDelegate {
|
|||
extension WebAppViewCoordinator: UIScrollViewDelegate {
|
||||
func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
|
||||
hasDragged = true
|
||||
yOffsetAtStartOfDrag = scrollView.contentOffset.y
|
||||
yOffsetAtStartOfDrag = scrollView.contentOffset.y + scrollView.contentInset.top
|
||||
}
|
||||
|
||||
func scrollViewDidScroll(_ scrollView: UIScrollView) {
|
||||
guard hasDragged else { return }
|
||||
|
||||
let yOffset = scrollView.contentOffset.y
|
||||
let yOffset = scrollView.contentOffset.y + scrollView.contentInset.top
|
||||
|
||||
if yOffset == 0 {
|
||||
let additionalOffset = (1 - navBarVisibilityRatio) * navBarHeight
|
||||
scrollView.contentOffset.y += additionalOffset
|
||||
scrollView.contentInset.top = navBarHeight
|
||||
navBarVisibilityRatio = 1
|
||||
return
|
||||
}
|
||||
|
||||
if yOffset < 0 {
|
||||
navBarVisibilityRatio = 1
|
||||
scrollView.contentInset.top = navBarHeight
|
||||
return
|
||||
}
|
||||
|
||||
if yOffset < navBarHeight {
|
||||
let isScrollingUp = yOffsetAtStartOfDrag ?? 0 > yOffset
|
||||
navBarVisibilityRatio = isScrollingUp ? 1 : 1 - (yOffset / navBarHeight)
|
||||
navBarVisibilityRatio = isScrollingUp || yOffset < 0 ? 1 : min(1, 1 - (yOffset / navBarHeight))
|
||||
print("parkour!", navBarVisibilityRatio, isScrollingUp, yOffsetAtStartOfDrag, yOffset)
|
||||
scrollView.contentInset.top = navBarVisibilityRatio * navBarHeight
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -74,22 +82,22 @@ extension WebAppViewCoordinator: UIScrollViewDelegate {
|
|||
if yOffset > yOffsetAtStartOfDrag, !isNavBarHidden {
|
||||
let translation = yOffset - yOffsetAtStartOfDrag
|
||||
let ratio = translation < navBarHeight ? 1 - (translation / navBarHeight) : 0
|
||||
navBarVisibilityRatio = ratio
|
||||
navBarVisibilityRatio = min(ratio, 1)
|
||||
// print("bike!", navBarVisibilityRatio)
|
||||
scrollView.contentInset.top = navBarVisibilityRatio * navBarHeight
|
||||
}
|
||||
}
|
||||
|
||||
func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
|
||||
if decelerate, scrollView.contentOffset.y < (yOffsetAtStartOfDrag ?? 0) {
|
||||
let additionalOffset = (1 - navBarVisibilityRatio) * navBarHeight
|
||||
scrollView.contentOffset.y += additionalOffset
|
||||
if decelerate, scrollView.contentOffset.y + scrollView.contentInset.top < (yOffsetAtStartOfDrag ?? 0) {
|
||||
scrollView.contentInset.top = navBarHeight
|
||||
navBarVisibilityRatio = 1
|
||||
}
|
||||
yOffsetAtStartOfDrag = nil
|
||||
}
|
||||
|
||||
func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool {
|
||||
let additionalOffset = (1 - navBarVisibilityRatio) * navBarHeight
|
||||
scrollView.contentOffset.y += additionalOffset
|
||||
scrollView.contentInset.top = navBarHeight
|
||||
navBarVisibilityRatio = 1
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,73 +73,84 @@ public struct LinkItemDetailView: View {
|
|||
#endif
|
||||
}
|
||||
|
||||
@ViewBuilder private var compactInnerBody: some View {
|
||||
VStack(spacing: 0) {
|
||||
withAnimation {
|
||||
HStack(alignment: .center) {
|
||||
Button(
|
||||
action: { self.presentationMode.wrappedValue.dismiss() },
|
||||
label: {
|
||||
Image(systemName: "chevron.backward")
|
||||
.font(.appTitleTwo)
|
||||
.foregroundColor(.appGrayTextContrast)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
)
|
||||
.scaleEffect(navBarVisibilityRatio)
|
||||
Spacer()
|
||||
Button(
|
||||
action: { showFontSizePopover.toggle() },
|
||||
label: {
|
||||
Image(systemName: "textformat.size")
|
||||
.font(.appTitleTwo)
|
||||
}
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio)
|
||||
var navBar: some View {
|
||||
HStack(alignment: .center) {
|
||||
Button(
|
||||
action: { self.presentationMode.wrappedValue.dismiss() },
|
||||
label: {
|
||||
Image(systemName: "chevron.backward")
|
||||
.font(.appTitleTwo)
|
||||
.foregroundColor(.appGrayTextContrast)
|
||||
.padding(.horizontal)
|
||||
}
|
||||
.frame(height: LinkItemDetailView.navBarHeight * navBarVisibilityRatio)
|
||||
.opacity(navBarVisibilityRatio)
|
||||
}
|
||||
if let webAppWrapperViewModel = viewModel.webAppWrapperViewModel {
|
||||
ZStack {
|
||||
WebAppWrapperView(
|
||||
viewModel: webAppWrapperViewModel,
|
||||
navBarVisibilityRatioUpdater: {
|
||||
if $0 < 1 {
|
||||
)
|
||||
.scaleEffect(navBarVisibilityRatio)
|
||||
Spacer()
|
||||
Button(
|
||||
action: { showFontSizePopover.toggle() },
|
||||
label: {
|
||||
Image(systemName: "textformat.size")
|
||||
.font(.appTitleTwo)
|
||||
}
|
||||
)
|
||||
.padding(.horizontal)
|
||||
.scaleEffect(navBarVisibilityRatio)
|
||||
}
|
||||
.frame(height: LinkItemDetailView.navBarHeight * navBarVisibilityRatio)
|
||||
.opacity(navBarVisibilityRatio)
|
||||
.background(Color.systemBackground)
|
||||
}
|
||||
|
||||
@ViewBuilder private var compactInnerBody: some View {
|
||||
if let webAppWrapperViewModel = viewModel.webAppWrapperViewModel {
|
||||
ZStack {
|
||||
WebAppWrapperView(
|
||||
viewModel: webAppWrapperViewModel,
|
||||
navBarVisibilityRatioUpdater: {
|
||||
if $0 < 1 {
|
||||
showFontSizePopover = false
|
||||
}
|
||||
navBarVisibilityRatio = $0
|
||||
}
|
||||
)
|
||||
if showFontSizePopover {
|
||||
VStack {
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.frame(height: LinkItemDetailView.navBarHeight)
|
||||
HStack {
|
||||
Spacer()
|
||||
fontAdjustmentPopoverView
|
||||
.background(Color.appButtonBackground)
|
||||
.cornerRadius(8)
|
||||
.padding(.trailing, 5)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.background(
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
showFontSizePopover = false
|
||||
}
|
||||
navBarVisibilityRatio = $0
|
||||
}
|
||||
)
|
||||
if showFontSizePopover {
|
||||
VStack {
|
||||
HStack {
|
||||
Spacer()
|
||||
fontAdjustmentPopoverView
|
||||
.background(Color.appButtonBackground)
|
||||
.cornerRadius(8)
|
||||
.padding(.trailing, 5)
|
||||
}
|
||||
Spacer()
|
||||
}
|
||||
.background(
|
||||
Color.clear
|
||||
.contentShape(Rectangle())
|
||||
.onTapGesture {
|
||||
showFontSizePopover = false
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
Spacer()
|
||||
.onAppear {
|
||||
viewModel.performActionSubject.send(.load)
|
||||
}
|
||||
VStack(spacing: 0) {
|
||||
navBar
|
||||
Spacer()
|
||||
}
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
} else {
|
||||
VStack(spacing: 0) {
|
||||
navBar
|
||||
Spacer()
|
||||
}
|
||||
.onAppear {
|
||||
viewModel.performActionSubject.send(.load)
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
}
|
||||
.navigationBarHidden(true)
|
||||
}
|
||||
|
||||
@ViewBuilder private var innerBody: some View {
|
||||
|
|
|
|||
Loading…
Reference in a new issue