Web app improvements

This commit is contained in:
Ilya Laktyushin 2022-04-01 14:36:12 +04:00
parent 1dd34bb4a8
commit c24af412cc
2 changed files with 22 additions and 8 deletions

View File

@ -336,13 +336,11 @@ public final class WebAppController: ViewController, AttachmentContainable {
self.controller?.navigationBar?.updateBackgroundAlpha(min(30.0, contentOffset) / 30.0, transition: .immediate)
}
private var animationProgress: CGFloat = 0.0
private var floatSnapshotView: UIView?
private var validLayout: (ContainerViewLayout, CGFloat)?
func containerLayoutUpdated(_ layout: ContainerViewLayout, navigationBarHeight: CGFloat, transition: ContainedViewLayoutTransition) {
let previous = self.validLayout?.0
self.validLayout = (layout, navigationBarHeight)
if let webView = self.webView, let controller = self.controller {
let frame = CGRect(origin: CGPoint(x: layout.safeInsets.left, y: navigationBarHeight), size: CGSize(width: layout.size.width - layout.safeInsets.left - layout.safeInsets.right, height: max(1.0, layout.size.height - navigationBarHeight - layout.intrinsicInsets.bottom - layout.additionalInsets.bottom)))
@ -366,6 +364,10 @@ public final class WebAppController: ViewController, AttachmentContainable {
let loadingProgressHeight: CGFloat = 2.0
transition.updateFrame(node: self.loadingProgressNode, frame: CGRect(origin: CGPoint(x: 0.0, y: height - loadingProgressHeight), size: CGSize(width: layout.size.width, height: loadingProgressHeight)))
}
if let previous = previous, (previous.inputHeight ?? 0.0).isZero, let inputHeight = layout.inputHeight, inputHeight > 44.0 {
self.controller?.requestAttachmentMenuExpansion()
}
}
override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {

View File

@ -112,15 +112,27 @@ final class WebAppWebView: WKWebView {
if panning {
let fixedPositionViews = findFixedPositionViews(webView: self, classes: self.fixedPositionClasses)
if fixedPositionViews.count != self.currentFixedViews.count {
reset()
var existing: [String: (UIView, UIView)] = [:]
for (className, originalView, snapshotView) in self.currentFixedViews {
existing[className] = (originalView, snapshotView)
}
var updatedFixedViews: [(String, UIView, UIView)] = []
for (className, view) in fixedPositionViews {
if let snapshotView = view.snapshotView(afterScreenUpdates: false) {
if let (_, existingSnapshotView) = existing[className] {
updatedFixedViews.append((className, view, existingSnapshotView))
existing[className] = nil
} else if let snapshotView = view.snapshotView(afterScreenUpdates: false) {
updatedFixedViews.append((className, view, snapshotView))
self.addSubview(snapshotView)
}
}
for (_, originalAndSnapshotView) in existing {
originalAndSnapshotView.0.isHidden = false
originalAndSnapshotView.1.removeFromSuperview()
}
self.currentFixedViews = updatedFixedViews
}
transition.updateFrame(view: self, frame: frame)