mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Various fixes
This commit is contained in:
parent
8e8b8b7a3e
commit
2ea60be3da
@ -18,6 +18,7 @@ import MinimizedContainer
|
|||||||
import InstantPageUI
|
import InstantPageUI
|
||||||
import NavigationStackComponent
|
import NavigationStackComponent
|
||||||
import LottieComponent
|
import LottieComponent
|
||||||
|
import WebKit
|
||||||
|
|
||||||
private let settingsTag = GenericComponentViewTag()
|
private let settingsTag = GenericComponentViewTag()
|
||||||
|
|
||||||
@ -489,13 +490,13 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
case expand
|
case expand
|
||||||
}
|
}
|
||||||
|
|
||||||
fileprivate final class Node: ViewControllerTracingNode {
|
final class Node: ViewControllerTracingNode {
|
||||||
private weak var controller: BrowserScreen?
|
private weak var controller: BrowserScreen?
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
|
|
||||||
private let contentContainerView = UIView()
|
private let contentContainerView = UIView()
|
||||||
fileprivate let contentNavigationContainer = ComponentView<Empty>()
|
fileprivate let contentNavigationContainer = ComponentView<Empty>()
|
||||||
fileprivate var content: [BrowserContent] = []
|
private(set) var content: [BrowserContent] = []
|
||||||
fileprivate var contentState: BrowserContentState?
|
fileprivate var contentState: BrowserContentState?
|
||||||
private var contentStateDisposable = MetaDisposable()
|
private var contentStateDisposable = MetaDisposable()
|
||||||
|
|
||||||
@ -785,13 +786,14 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
let browserContent: BrowserContent
|
let browserContent: BrowserContent
|
||||||
switch content {
|
switch content {
|
||||||
case let .webPage(url):
|
case let .webPage(url):
|
||||||
let webContent = BrowserWebContent(context: self.context, presentationData: self.presentationData, url: url)
|
let webContent = BrowserWebContent(context: self.context, presentationData: self.presentationData, url: url, preferredConfiguration: self.controller?.preferredConfiguration)
|
||||||
webContent.cancelInteractiveTransitionGestures = { [weak self] in
|
webContent.cancelInteractiveTransitionGestures = { [weak self] in
|
||||||
if let self, let view = self.controller?.view {
|
if let self, let view = self.controller?.view {
|
||||||
cancelInteractiveTransitionGestures(view: view)
|
cancelInteractiveTransitionGestures(view: view)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
browserContent = webContent
|
browserContent = webContent
|
||||||
|
self.controller?.preferredConfiguration = nil
|
||||||
case let .instantPage(webPage, anchor, sourceLocation):
|
case let .instantPage(webPage, anchor, sourceLocation):
|
||||||
let instantPageContent = BrowserInstantPageContent(context: self.context, presentationData: self.presentationData, webPage: webPage, anchor: anchor, url: webPage.content.url ?? "", sourceLocation: sourceLocation)
|
let instantPageContent = BrowserInstantPageContent(context: self.context, presentationData: self.presentationData, webPage: webPage, anchor: anchor, url: webPage.content.url ?? "", sourceLocation: sourceLocation)
|
||||||
instantPageContent.openPeer = { [weak self] peer in
|
instantPageContent.openPeer = { [weak self] peer in
|
||||||
@ -846,7 +848,9 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if controller.isMinimized {
|
if controller.isMinimized {
|
||||||
|
if let navigationController = controller.navigationController as? NavigationController, let minimizedContainer = navigationController.minimizedContainer {
|
||||||
|
minimizedContainer.removeController(controller)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
controller.dismiss()
|
controller.dismiss()
|
||||||
}
|
}
|
||||||
@ -1373,7 +1377,7 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
|
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
private let subject: Subject
|
private let subject: Subject
|
||||||
|
private var preferredConfiguration: WKWebViewConfiguration?
|
||||||
private var openPreviousOnClose = false
|
private var openPreviousOnClose = false
|
||||||
|
|
||||||
private var validLayout: ContainerViewLayout?
|
private var validLayout: ContainerViewLayout?
|
||||||
@ -1390,7 +1394,7 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
// "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
// "application/vnd.openxmlformats-officedocument.presentationml.presentation"
|
||||||
]
|
]
|
||||||
|
|
||||||
public init(context: AccountContext, subject: Subject, openPreviousOnClose: Bool = false) {
|
public init(context: AccountContext, subject: Subject, preferredConfiguration: WKWebViewConfiguration? = nil, openPreviousOnClose: Bool = false) {
|
||||||
var subject = subject
|
var subject = subject
|
||||||
if case let .webPage(url) = subject, let parsedUrl = URL(string: url) {
|
if case let .webPage(url) = subject, let parsedUrl = URL(string: url) {
|
||||||
if parsedUrl.host?.hasSuffix(".ton") == true {
|
if parsedUrl.host?.hasSuffix(".ton") == true {
|
||||||
@ -1403,6 +1407,7 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
}
|
}
|
||||||
self.context = context
|
self.context = context
|
||||||
self.subject = subject
|
self.subject = subject
|
||||||
|
self.preferredConfiguration = preferredConfiguration
|
||||||
self.openPreviousOnClose = openPreviousOnClose
|
self.openPreviousOnClose = openPreviousOnClose
|
||||||
|
|
||||||
super.init(navigationBarPresentationData: nil)
|
super.init(navigationBarPresentationData: nil)
|
||||||
@ -1420,7 +1425,7 @@ public class BrowserScreen: ViewController, MinimizableController {
|
|||||||
preconditionFailure()
|
preconditionFailure()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var node: Node {
|
var node: Node {
|
||||||
return self.displayNode as! Node
|
return self.displayNode as! Node
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,13 +203,18 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
|||||||
|
|
||||||
private var tempFile: TempBoxFile?
|
private var tempFile: TempBoxFile?
|
||||||
|
|
||||||
init(context: AccountContext, presentationData: PresentationData, url: String) {
|
init(context: AccountContext, presentationData: PresentationData, url: String, preferredConfiguration: WKWebViewConfiguration? = nil) {
|
||||||
self.context = context
|
self.context = context
|
||||||
self.uuid = UUID()
|
self.uuid = UUID()
|
||||||
self.presentationData = presentationData
|
self.presentationData = presentationData
|
||||||
|
|
||||||
let configuration = WKWebViewConfiguration()
|
var handleScriptMessageImpl: ((WKScriptMessage) -> Void)?
|
||||||
|
|
||||||
|
let configuration: WKWebViewConfiguration
|
||||||
|
if let preferredConfiguration {
|
||||||
|
configuration = preferredConfiguration
|
||||||
|
} else {
|
||||||
|
configuration = WKWebViewConfiguration()
|
||||||
var proxyServerHost = "magic.org"
|
var proxyServerHost = "magic.org"
|
||||||
if let data = context.currentAppConfiguration.with({ $0 }).data, let hostValue = data["ton_proxy_address"] as? String {
|
if let data = context.currentAppConfiguration.with({ $0 }).data, let hostValue = data["ton_proxy_address"] as? String {
|
||||||
proxyServerHost = hostValue
|
proxyServerHost = hostValue
|
||||||
@ -227,16 +232,17 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
|||||||
contentController.addUserScript(videoScript)
|
contentController.addUserScript(videoScript)
|
||||||
let touchScript = WKUserScript(source: setupTouchObservers, injectionTime: .atDocumentStart, forMainFrameOnly: false)
|
let touchScript = WKUserScript(source: setupTouchObservers, injectionTime: .atDocumentStart, forMainFrameOnly: false)
|
||||||
contentController.addUserScript(touchScript)
|
contentController.addUserScript(touchScript)
|
||||||
configuration.userContentController = contentController
|
|
||||||
configuration.applicationNameForUserAgent = computedUserAgent()
|
|
||||||
|
|
||||||
var handleScriptMessageImpl: ((WKScriptMessage) -> Void)?
|
|
||||||
let eventProxyScript = WKUserScript(source: eventProxySource, injectionTime: .atDocumentStart, forMainFrameOnly: false)
|
let eventProxyScript = WKUserScript(source: eventProxySource, injectionTime: .atDocumentStart, forMainFrameOnly: false)
|
||||||
contentController.addUserScript(eventProxyScript)
|
contentController.addUserScript(eventProxyScript)
|
||||||
contentController.add(WeakScriptMessageHandler { message in
|
contentController.add(WeakScriptMessageHandler { message in
|
||||||
handleScriptMessageImpl?(message)
|
handleScriptMessageImpl?(message)
|
||||||
}, name: "performAction")
|
}, name: "performAction")
|
||||||
|
|
||||||
|
configuration.userContentController = contentController
|
||||||
|
configuration.applicationNameForUserAgent = computedUserAgent()
|
||||||
|
}
|
||||||
|
|
||||||
self.webView = WebView(frame: CGRect(), configuration: configuration)
|
self.webView = WebView(frame: CGRect(), configuration: configuration)
|
||||||
self.webView.allowsLinkPreview = true
|
self.webView.allowsLinkPreview = true
|
||||||
|
|
||||||
@ -786,7 +792,7 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
|||||||
self.minimize()
|
self.minimize()
|
||||||
self.openAppUrl(url)
|
self.openAppUrl(url)
|
||||||
} else {
|
} else {
|
||||||
self.open(url: url, new: true)
|
return self.open(url: url, configuration: configuration, new: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -927,17 +933,19 @@ final class BrowserWebContent: UIView, BrowserContent, WKNavigationDelegate, WKU
|
|||||||
self.present(alertController, nil)
|
self.present(alertController, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
private func open(url: String, new: Bool) {
|
@discardableResult private func open(url: String, configuration: WKWebViewConfiguration? = nil, new: Bool) -> WKWebView? {
|
||||||
let subject: BrowserScreen.Subject = .webPage(url: url)
|
let subject: BrowserScreen.Subject = .webPage(url: url)
|
||||||
if new, let navigationController = self.getNavigationController() {
|
if new, let navigationController = self.getNavigationController() {
|
||||||
navigationController._keepModalDismissProgress = true
|
navigationController._keepModalDismissProgress = true
|
||||||
self.minimize()
|
self.minimize()
|
||||||
let controller = BrowserScreen(context: self.context, subject: subject, openPreviousOnClose: true)
|
let controller = BrowserScreen(context: self.context, subject: subject, preferredConfiguration: configuration, openPreviousOnClose: true)
|
||||||
navigationController._keepModalDismissProgress = true
|
navigationController._keepModalDismissProgress = true
|
||||||
navigationController.pushViewController(controller)
|
navigationController.pushViewController(controller)
|
||||||
|
return (controller.node.content.last as? BrowserWebContent)?.webView
|
||||||
} else {
|
} else {
|
||||||
self.pushContent(subject)
|
self.pushContent(subject)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
private func share(url: String) {
|
private func share(url: String) {
|
||||||
|
@ -12,6 +12,7 @@ public protocol MinimizedContainer: ASDisplayNode {
|
|||||||
var statusBarStyleUpdated: (() -> Void)? { get set }
|
var statusBarStyleUpdated: (() -> Void)? { get set }
|
||||||
|
|
||||||
func addController(_ viewController: MinimizableController, topEdgeOffset: CGFloat?, beforeMaximize: @escaping (NavigationController, @escaping () -> Void) -> Void, transition: ContainedViewLayoutTransition)
|
func addController(_ viewController: MinimizableController, topEdgeOffset: CGFloat?, beforeMaximize: @escaping (NavigationController, @escaping () -> Void) -> Void, transition: ContainedViewLayoutTransition)
|
||||||
|
func removeController(_ viewController: MinimizableController)
|
||||||
func maximizeController(_ viewController: MinimizableController, animated: Bool, completion: @escaping (Bool) -> Void)
|
func maximizeController(_ viewController: MinimizableController, animated: Bool, completion: @escaping (Bool) -> Void)
|
||||||
func collapse()
|
func collapse()
|
||||||
func dismissAll(completion: @escaping () -> Void)
|
func dismissAll(completion: @escaping () -> Void)
|
||||||
|
@ -558,6 +558,15 @@ public class MinimizedContainerImpl: ASDisplayNode, MinimizedContainer, ASScroll
|
|||||||
self.requestUpdate(transition: transition)
|
self.requestUpdate(transition: transition)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public func removeController(_ viewController: MinimizableController) {
|
||||||
|
guard let item = self.items.first(where: { $0.controller === viewController }) else {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
self.items.removeAll(where: { $0.id == item.id })
|
||||||
|
self.requestUpdate(transition: .animated(duration: 0.25, curve: .easeInOut))
|
||||||
|
}
|
||||||
|
|
||||||
private enum Transition: Equatable {
|
private enum Transition: Equatable {
|
||||||
case minimize(itemId: AnyHashable)
|
case minimize(itemId: AnyHashable)
|
||||||
case maximize(itemId: AnyHashable)
|
case maximize(itemId: AnyHashable)
|
||||||
|
@ -73,7 +73,7 @@ final class MinimizedHeaderNode: ASDisplayNode {
|
|||||||
guard let self else {
|
guard let self else {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let titles = titles.compactMap { $0 }
|
let titles = titles.compactMap { $0 }.filter { !$0.isEmpty }
|
||||||
if titles.count == 1, let title = titles.first {
|
if titles.count == 1, let title = titles.first {
|
||||||
self.title = title
|
self.title = title
|
||||||
} else if let title = titles.last {
|
} else if let title = titles.last {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user