Web app improvements

This commit is contained in:
Ilya Laktyushin 2022-04-08 18:38:04 +04:00
parent 845cc48c61
commit af9dcd2f19
3 changed files with 35 additions and 18 deletions

View File

@ -3363,6 +3363,10 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
let openWebView = {
if fromMenu {
strongSelf.interfaceInteraction?.updateShowWebView { _ in
return true
}
let params = WebAppParameters(peerId: peerId, botId: peerId, botName: botName, url: url, queryId: nil, payload: nil, buttonText: buttonText, keepAliveSignal: nil, fromMenu: true)
let controller = standaloneWebAppController(context: strongSelf.context, updatedPresentationData: strongSelf.updatedPresentationData, params: params, openUrl: { [weak self] url in
self?.openUrl(url, concealed: true, forceExternal: true)

View File

@ -2565,13 +2565,13 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate {
return !value
}
} else if case let .webView(title, url) = presentationInterfaceState.botMenuButton {
var show = false
self.interfaceInteraction?.updateShowWebView { value in
show = !value
return show
}
if show {
let willShow = !(self.presentationInterfaceState?.showWebView ?? false)
if willShow {
self.interfaceInteraction?.openWebView(title, url, false, true)
} else {
self.interfaceInteraction?.updateShowWebView { _ in
return false
}
}
} else {
self.interfaceInteraction?.updateShowCommands { value in

View File

@ -298,21 +298,32 @@ public final class WebAppController: ViewController, AttachmentContainable {
}
return nil
}
var didTransitionIn = false
private func animateTransitionIn() {
guard !self.didTransitionIn, let webView = self.webView else {
return
}
self.didTransitionIn = true
let transition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .linear)
transition.updateAlpha(layer: webView.layer, alpha: 1.0)
if let placeholderNode = self.placeholderNode {
self.placeholderNode = nil
transition.updateAlpha(node: placeholderNode, alpha: 0.0, completion: { [weak placeholderNode] _ in
placeholderNode?.removeFromSupernode()
})
}
if let (layout, navigationBarHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
}
}
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
Queue.mainQueue().after(0.6, {
let transition = ContainedViewLayoutTransition.animated(duration: 0.2, curve: .linear)
transition.updateAlpha(layer: webView.layer, alpha: 1.0)
if let placeholderNode = self.placeholderNode {
self.placeholderNode = nil
transition.updateAlpha(node: placeholderNode, alpha: 0.0, completion: { [weak placeholderNode] _ in
placeholderNode?.removeFromSupernode()
})
}
if let (layout, navigationBarHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
}
self.animateTransitionIn()
})
}
@ -402,6 +413,8 @@ public final class WebAppController: ViewController, AttachmentContainable {
}
switch eventName {
case "web_app_ready":
self.animateTransitionIn()
case "web_app_data_send":
if let eventData = body["eventData"] as? String {
self.handleSendData(data: eventData)