mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-09-02 02:43:07 +00:00
Web app improvements
This commit is contained in:
parent
596a3f037f
commit
dc9677fafd
@ -303,14 +303,15 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
||||
let viewportFrame = 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)))
|
||||
|
||||
if previousLayout != nil && (previousLayout?.inputHeight ?? 0.0).isZero, let inputHeight = layout.inputHeight, inputHeight > 44.0, transition.isAnimated {
|
||||
webView.scrollToActiveElement(layout: layout, transition: transition)
|
||||
webView.scrollToActiveElement(layout: layout, completion: { [weak self] contentOffset in
|
||||
self?.targetContentOffset = contentOffset
|
||||
}, transition: transition)
|
||||
Queue.mainQueue().after(0.4, {
|
||||
let contentOffset = webView.scrollView.contentOffset
|
||||
transition.updateFrame(view: webView, frame: frame)
|
||||
webView.scrollView.contentOffset = contentOffset
|
||||
self.targetContentOffset = contentOffset
|
||||
Queue.mainQueue().after(0.1) {
|
||||
self.targetContentOffset = nil
|
||||
if let inputHeight = self.validLayout?.0.inputHeight, inputHeight > 44.0 {
|
||||
transition.updateFrame(view: webView, frame: frame)
|
||||
Queue.mainQueue().after(0.1) {
|
||||
self.targetContentOffset = nil
|
||||
}
|
||||
}
|
||||
})
|
||||
} else {
|
||||
|
@ -68,6 +68,8 @@ final class WebAppWebView: WKWebView {
|
||||
|
||||
super.init(frame: CGRect(), configuration: configuration)
|
||||
|
||||
self.disablesInteractiveKeyboardGestureRecognizer = true
|
||||
|
||||
self.isOpaque = false
|
||||
self.backgroundColor = .clear
|
||||
if #available(iOSApplicationExtension 9.0, iOS 9.0, *) {
|
||||
@ -130,23 +132,24 @@ final class WebAppWebView: WKWebView {
|
||||
self.didTouchOnce = true
|
||||
}
|
||||
|
||||
func scrollToActiveElement(layout: ContainerViewLayout, transition: ContainedViewLayoutTransition) {
|
||||
func scrollToActiveElement(layout: ContainerViewLayout, completion: @escaping (CGPoint) -> Void, transition: ContainedViewLayoutTransition) {
|
||||
self.evaluateJavaScript(findActiveElementY, completionHandler: { result, _ in
|
||||
if let result = result as? CGFloat {
|
||||
Queue.mainQueue().async {
|
||||
let convertedY = result - self.scrollView.contentOffset.y
|
||||
let viewportHeight = self.frame.height - (layout.inputHeight ?? 0.0)
|
||||
if convertedY < 0.0 || convertedY > viewportHeight {
|
||||
let viewportHeight = self.frame.height - (layout.inputHeight ?? 0.0) + 26.0
|
||||
if convertedY < 0.0 || (convertedY + 44.0) > viewportHeight {
|
||||
let targetOffset: CGFloat
|
||||
if convertedY < 0.0 {
|
||||
targetOffset = max(0.0, result - 36.0)
|
||||
} else {
|
||||
targetOffset = max(0.0, result + 60.0 - viewportHeight)
|
||||
}
|
||||
let contentOffset = CGPoint(x: 0.0, y: targetOffset)
|
||||
completion(contentOffset)
|
||||
transition.animateView({
|
||||
self.scrollView.contentOffset = CGPoint(x: 0.0, y: targetOffset)
|
||||
self.scrollView.contentOffset = contentOffset
|
||||
})
|
||||
// transition.updateBounds(layer: self.scrollView.layer, bounds: CGRect(x: 0.0, y: targetOffset, width: self.scrollView.layer.bounds.width, height: self.scrollView.layer.bounds.height))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user