Web app improvements

This commit is contained in:
Ilya Laktyushin 2022-04-08 00:01:01 +04:00
parent 7f7cb498bb
commit 30d5f9ddef
4 changed files with 60 additions and 50 deletions

View File

@ -161,7 +161,8 @@ public class AttachmentController: ViewController {
private let initialButton: AttachmentButtonType
private let fromMenu: Bool
public var dismissed: () -> Void = {}
public var willDismiss: () -> Void = {}
public var didDismiss: () -> Void = {}
public var mediaPickerContext: AttachmentMediaPickerContext? {
get {
@ -843,9 +844,8 @@ public class AttachmentController: ViewController {
self.displayNodeDidLoad()
}
private var didDismiss = false
private var dismissedFlag = false
public func _dismiss() {
self.dismissed()
super.dismiss(animated: false, completion: {})
}
@ -856,15 +856,17 @@ public class AttachmentController: ViewController {
self.view.endEditing(true)
}
if flag {
if !self.didDismiss {
self.didDismiss = true
self.dismissed()
if !self.dismissedFlag {
self.dismissedFlag = true
self.willDismiss()
self.node.animateOut(completion: { [weak self] in
self?.didDismiss()
self?._dismiss()
completion?()
})
}
} else {
self.didDismiss()
self._dismiss()
completion?()
}

View File

@ -14,6 +14,7 @@ import OverlayStatusController
import AccountContext
import AppBundle
import ZipArchive
import WebKit
@objc private final class DebugControllerMailComposeDelegate: NSObject, MFMailComposeViewControllerDelegate {
public func mailComposeController(_ controller: MFMailComposeViewController, didFinishWith result: MFMailComposeResult, error: Error?) {
@ -74,6 +75,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
case resetHoles(PresentationTheme)
case reindexUnread(PresentationTheme)
case resetBiometricsData(PresentationTheme)
case resetWebViewCache(PresentationTheme)
case optimizeDatabase(PresentationTheme)
case photoPreview(PresentationTheme, Bool)
case knockoutWallpaper(PresentationTheme, Bool)
@ -103,7 +105,7 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return DebugControllerSection.logging.rawValue
case .enableRaiseToSpeak, .keepChatNavigationStack, .skipReadHistory, .crashOnSlowQueries:
return DebugControllerSection.experiments.rawValue
case .clearTips, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetBiometricsData, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .playerEmbedding, .playlistPlayback, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .experimentalBackground, .snow:
case .clearTips, .crash, .resetData, .resetDatabase, .resetDatabaseAndCache, .resetHoles, .reindexUnread, .resetBiometricsData, .resetWebViewCache, .optimizeDatabase, .photoPreview, .knockoutWallpaper, .playerEmbedding, .playlistPlayback, .voiceConference, .experimentalCompatibility, .enableDebugDataDisplay, .acceleratedStickers, .experimentalBackground, .snow:
return DebugControllerSection.experiments.rawValue
case .preferredVideoCodec:
return DebugControllerSection.videoExperiments.rawValue
@ -160,30 +162,32 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return 20
case .resetBiometricsData:
return 21
case .optimizeDatabase:
case .resetWebViewCache:
return 22
case .photoPreview:
case .optimizeDatabase:
return 23
case .knockoutWallpaper:
case .photoPreview:
return 24
case .knockoutWallpaper:
return 25
case .experimentalCompatibility:
return 26
case .enableDebugDataDisplay:
return 27
case .acceleratedStickers:
return 29
return 28
case .experimentalBackground:
return 30
return 29
case .snow:
return 31
return 30
case .playerEmbedding:
return 32
return 31
case .playlistPlayback:
return 33
return 32
case .voiceConference:
return 34
return 33
case let .preferredVideoCodec(index, _, _, _):
return 35 + index
return 34 + index
case .disableVideoAspectScaling:
return 100
case .enableVoipTcp:
@ -777,6 +781,10 @@ private enum DebugControllerEntry: ItemListNodeEntry {
return settings.withUpdatedBiometricsDomainState(nil).withUpdatedShareBiometricsDomainState(nil)
}).start()
})
case .resetWebViewCache:
return ItemListActionItem(presentationData: presentationData, title: "Clear Web View Cache", kind: .destructive, alignment: .natural, sectionId: self.section, style: .blocks, action: {
WKWebsiteDataStore.default().removeData(ofTypes: [WKWebsiteDataTypeDiskCache, WKWebsiteDataTypeMemoryCache], modifiedSince: Date(timeIntervalSince1970: 0), completionHandler:{ })
})
case .optimizeDatabase:
return ItemListActionItem(presentationData: presentationData, title: "Optimize Database", kind: .generic, alignment: .natural, sectionId: self.section, style: .blocks, action: {
guard let context = arguments.context else {
@ -968,6 +976,7 @@ private func debugControllerEntries(sharedContext: SharedAccountContext, present
entries.append(.resetHoles(presentationData.theme))
if isMainApp {
entries.append(.reindexUnread(presentationData.theme))
entries.append(.resetWebViewCache(presentationData.theme))
}
entries.append(.optimizeDatabase(presentationData.theme))
if isMainApp {

View File

@ -3376,14 +3376,17 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
}
}, completion: { [weak self] in
self?.chatDisplayNode.historyNode.scrollToEndOfHistory()
}, dismissed: { [weak self] in
}, willDismiss: { [weak self] in
self?.interfaceInteraction?.updateShowWebView { _ in
return false
}
let isFocused = strongSelf.chatDisplayNode.textInputPanelNode?.isFocused ?? false
strongSelf.chatDisplayNode.insertSubnode(strongSelf.chatDisplayNode.inputPanelContainerNode, aboveSubnode: strongSelf.chatDisplayNode.historyNodeContainer)
if isFocused {
strongSelf.chatDisplayNode.textInputPanelNode?.ensureFocused()
}, didDismiss: { [weak self] in
if let strongSelf = self {
let isFocused = strongSelf.chatDisplayNode.textInputPanelNode?.isFocused ?? false
strongSelf.chatDisplayNode.insertSubnode(strongSelf.chatDisplayNode.inputPanelContainerNode, aboveSubnode: strongSelf.chatDisplayNode.historyNodeContainer)
if isFocused {
strongSelf.chatDisplayNode.textInputPanelNode?.ensureFocused()
}
}
})
strongSelf.present(controller, in: .window(.root))
@ -6792,7 +6795,14 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
return value
})
})
if updatedInputMode == .text {
var dismissWebView = false
switch updatedInputMode {
case .text, .media, .inputButtons:
dismissWebView = true
default:
break
}
if dismissWebView {
updated = updated.updatedShowWebView(false)
}
return updated
@ -6802,9 +6812,6 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G
guard let strongSelf = self else {
return
}
strongSelf.interfaceInteraction?.updateShowWebView { _ in
return false
}
strongSelf.chatDisplayNode.openStickers()
strongSelf.mediaRecordingModeTooltipController?.dismissImmediately()
}, editMessage: { [weak self] in

View File

@ -260,31 +260,22 @@ public final class WebAppController: ViewController, AttachmentContainable {
}
return nil
}
func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) {
Queue.mainQueue().after(0.65, {
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()
})
}
private var loadCount = 0
func webView(_ webView: WKWebView, didStartProvisionalNavigation navigation: WKNavigation!) {
self.loadCount += 1
}
func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
self.loadCount -= 1
Queue.mainQueue().after(0.1, {
if self.loadCount == 0, let webView = self.webView {
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)
}
})
if let (layout, navigationBarHeight) = self.validLayout {
self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate)
}
}
@available(iOSApplicationExtension 15.0, iOS 15.0, *)
@ -677,7 +668,7 @@ private final class WebAppContextReferenceContentSource: ContextReferenceContent
}
}
public func standaloneWebAppController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, params: WebAppParameters, openUrl: @escaping (String) -> Void, getInputContainerNode: @escaping () -> (CGFloat, ASDisplayNode, () -> AttachmentController.InputPanelTransition?)? = { return nil }, completion: @escaping () -> Void = {}, dismissed: @escaping () -> Void = {}) -> ViewController {
public func standaloneWebAppController(context: AccountContext, updatedPresentationData: (initial: PresentationData, signal: Signal<PresentationData, NoError>)? = nil, params: WebAppParameters, openUrl: @escaping (String) -> Void, getInputContainerNode: @escaping () -> (CGFloat, ASDisplayNode, () -> AttachmentController.InputPanelTransition?)? = { return nil }, completion: @escaping () -> Void = {}, willDismiss: @escaping () -> Void = {}, didDismiss: @escaping () -> Void = {}) -> ViewController {
let controller = AttachmentController(context: context, updatedPresentationData: updatedPresentationData, chatLocation: .peer(id: params.peerId), buttons: [.standalone], initialButton: .standalone, fromMenu: params.fromMenu)
controller.getInputContainerNode = getInputContainerNode
controller.requestController = { _, present in
@ -686,6 +677,7 @@ public func standaloneWebAppController(context: AccountContext, updatedPresentat
webAppController.completion = completion
present(webAppController, webAppController.mediaPickerContext)
}
controller.dismissed = dismissed
controller.willDismiss = willDismiss
controller.didDismiss = didDismiss
return controller
}