Web app improvements

This commit is contained in:
Ilya Laktyushin
2022-04-10 15:07:07 +04:00
parent ee86f431d7
commit 1a93f976a7
10 changed files with 64 additions and 28 deletions

View File

@@ -75,7 +75,8 @@ public final class WebAppController: ViewController, AttachmentContainable {
public var updateTabBarAlpha: (CGFloat, ContainedViewLayoutTransition) -> Void = { _, _ in }
public var cancelPanGesture: () -> Void = { }
public var isContainerPanning: () -> Bool = { return false }
public var isContainerExpanded: () -> Bool = { return false }
fileprivate class Node: ViewControllerTracingNode, WKNavigationDelegate, WKUIDelegate, UIScrollViewDelegate {
private weak var controller: WebAppController?
@@ -348,6 +349,12 @@ public final class WebAppController: ViewController, AttachmentContainable {
}
}
fileprivate func isContainerPanningUpdated(_ isPanning: Bool) {
if let (layout, navigationBarHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
}
}
private var validLayout: (ContainerViewLayout, CGFloat)?
func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
let previousLayout = self.validLayout?.0
@@ -373,7 +380,9 @@ public final class WebAppController: ViewController, AttachmentContainable {
transition.updateFrame(view: webView, frame: frame)
}
webView.updateFrame(frame: viewportFrame, transition: transition)
if let controller = self.controller {
webView.updateMetrics(height: viewportFrame.height, isExpanded: controller.isContainerExpanded(), isStable: !controller.isContainerPanning(), transition: transition)
}
}
if let placeholderNode = self.placeholderNode {
@@ -664,6 +673,10 @@ public final class WebAppController: ViewController, AttachmentContainable {
self.navigationBar?.updateBackgroundAlpha(0.0, transition: .immediate)
self.updateTabBarAlpha(1.0, .immediate)
}
public func isContainerPanningUpdated(_ isPanning: Bool) {
self.controllerNode.isContainerPanningUpdated(isPanning)
}
override public func containerLayoutUpdated(_ layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
super.containerLayoutUpdated(layout, transition: transition)