From 72a752b29aaedfa893a4650a5e3071c0ef6b448c Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 8 Apr 2022 18:15:07 +0400 Subject: [PATCH 1/3] Web app improvements --- submodules/PhotoResources/Sources/PhotoResources.swift | 8 +++++++- submodules/WebUI/Sources/WebAppController.swift | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/submodules/PhotoResources/Sources/PhotoResources.swift b/submodules/PhotoResources/Sources/PhotoResources.swift index 4da31297b2..903d223334 100644 --- a/submodules/PhotoResources/Sources/PhotoResources.swift +++ b/submodules/PhotoResources/Sources/PhotoResources.swift @@ -2311,7 +2311,13 @@ public func svgIconImageFile(account: Account, fileReference: FileMediaReference let imageOrientation: UIImage.Orientation = .up if fullSizeComplete, let data = try? Data(contentsOf: URL(fileURLWithPath: fullSizePath)) { - fullSizeImage = renderPreparedImage(data, CGSize.zero, .clear, UIScreenScale) + let renderSize: CGSize + if stickToTop { + renderSize = .zero + } else { + renderSize = CGSize(width: 90.0, height: 90.0) + } + fullSizeImage = renderPreparedImage(data, renderSize, .clear, UIScreenScale) if let image = fullSizeImage { fittedSize = image.size.aspectFitted(arguments.boundingSize) } diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 90707af704..b31f870420 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -300,7 +300,7 @@ public final class WebAppController: ViewController, AttachmentContainable { } func webView(_ webView: WKWebView, didCommit navigation: WKNavigation!) { - Queue.mainQueue().after(1.0, { + 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 { From af9dcd2f195bc2e20d7a2929bedc069a6f772b06 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 8 Apr 2022 18:38:04 +0400 Subject: [PATCH 2/3] Web app improvements --- .../TelegramUI/Sources/ChatController.swift | 4 ++ .../Sources/ChatTextInputPanelNode.swift | 12 +++--- .../WebUI/Sources/WebAppController.swift | 37 +++++++++++++------ 3 files changed, 35 insertions(+), 18 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 49f520475c..4c0cc94cbf 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -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) diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index 966467b241..bc285f0d3c 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -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 diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index b31f870420..6c9567672f 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -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) From 0d058348b0b96a30b3bb732a040364aa6eeafa93 Mon Sep 17 00:00:00 2001 From: Ilya Laktyushin Date: Fri, 8 Apr 2022 20:42:38 +0400 Subject: [PATCH 3/3] Web app improvements --- .../TelegramUI/Sources/ChatController.swift | 12 ++++++---- .../Sources/ChatTextInputPanelNode.swift | 22 ++++++++++++++++++- .../WebUI/Sources/WebAppController.swift | 4 ++++ submodules/WebUI/Sources/WebAppWebView.swift | 2 +- 4 files changed, 34 insertions(+), 6 deletions(-) diff --git a/submodules/TelegramUI/Sources/ChatController.swift b/submodules/TelegramUI/Sources/ChatController.swift index 4c0cc94cbf..51651432e5 100644 --- a/submodules/TelegramUI/Sources/ChatController.swift +++ b/submodules/TelegramUI/Sources/ChatController.swift @@ -12270,7 +12270,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G } } - private func sendMessages(_ messages: [EnqueueMessage], commit: Bool = false) { + private func sendMessages(_ messages: [EnqueueMessage], media: Bool = false, commit: Bool = false) { guard let peerId = self.chatLocation.peerId else { return } @@ -12294,7 +12294,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G self.updateChatPresentationInterfaceState(interactive: true, { $0.updatedShowCommands(false) }) } else { - self.presentScheduleTimePicker(dismissByTapOutside: false, completion: { [weak self] time in + self.presentScheduleTimePicker(style: media ? .media : .default, dismissByTapOutside: false, completion: { [weak self] time in if let strongSelf = self { strongSelf.sendMessages(strongSelf.transformEnqueueMessages(messages, silentPosting: false, scheduleTime: time), commit: true) } @@ -12319,7 +12319,7 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G var message = item.message if let uniqueId = item.uniqueId { let correlationId: Int64 - var addTransition = true + var addTransition = scheduleTime == nil if let groupingKey = message.groupingKey { if let existing = groupedCorrelationIds[groupingKey] { correlationId = existing @@ -12396,7 +12396,11 @@ public final class ChatControllerImpl: TelegramBaseController, ChatController, G completionImpl?() }, usedCorrelationId) - strongSelf.sendMessages(messages.map { $0.withUpdatedReplyToMessageId(replyMessageId) }) + strongSelf.sendMessages(messages.map { $0.withUpdatedReplyToMessageId(replyMessageId) }, media: true) + + if let _ = scheduleTime { + completion() + } } })) } diff --git a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift index bc285f0d3c..ecdf8f7c6d 100644 --- a/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift +++ b/submodules/TelegramUI/Sources/ChatTextInputPanelNode.swift @@ -877,6 +877,7 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { self.attachmentButton.accessibilityTraits = (!isSlowmodeActive || isMediaEnabled) ? [.button] : [.button, .notEnabled] self.attachmentButtonDisabledNode.isHidden = !isSlowmodeActive || isMediaEnabled + var buttonTitleUpdated = false var menuTextSize = self.menuButtonTextNode.frame.size if self.presentationInterfaceState != interfaceState { let previousState = self.presentationInterfaceState @@ -914,8 +915,19 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { buttonTitle = interfaceState.strings.Conversation_InputMenu } + buttonTitleUpdated = self.menuButtonTextNode.attributedText != nil && self.menuButtonTextNode.attributedText?.string != buttonTitle + self.menuButtonTextNode.attributedText = NSAttributedString(string: buttonTitle, font: Font.with(size: 16.0, design: .round, weight: .medium, traits: []), textColor: interfaceState.theme.chat.inputPanel.actionControlForegroundColor) self.menuButton.accessibilityLabel = self.menuButtonTextNode.attributedText?.string + + if buttonTitleUpdated, let buttonTextSnapshotView = self.menuButtonTextNode.view.snapshotView(afterScreenUpdates: false) { + buttonTextSnapshotView.frame = self.menuButtonTextNode.view.frame + self.menuButtonTextNode.view.superview?.addSubview(buttonTextSnapshotView) + buttonTextSnapshotView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak buttonTextSnapshotView] _ in + buttonTextSnapshotView?.removeFromSuperview() + }) + self.menuButtonTextNode.view.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2) + } menuTextSize = self.menuButtonTextNode.updateLayout(CGSize(width: width, height: 44.0)) var updateSendButtonIcon = false @@ -1212,6 +1224,10 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { } self.leftMenuInset = leftMenuInset + if buttonTitleUpdated && !transition.isAnimated { + transition = .animated(duration: 0.3, curve: .easeInOut) + } + let baseWidth = width - leftInset - leftMenuInset - rightInset let (accessoryButtonsWidth, textFieldHeight) = self.calculateTextFieldMetrics(width: baseWidth, maxHeight: maxHeight, metrics: metrics) let panelHeight = self.panelHeight(textFieldHeight: textFieldHeight, metrics: metrics) @@ -1220,7 +1236,11 @@ class ChatTextInputPanelNode: ChatInputPanelNode, ASEditableTextNodeDelegate { transition.updateFrameAsPositionAndBounds(node: self.menuButton, frame: menuButtonFrame) transition.updateFrame(node: self.menuButtonBackgroundNode, frame: CGRect(origin: CGPoint(), size: menuButtonFrame.size)) transition.updateFrame(node: self.menuButtonClippingNode, frame: CGRect(origin: CGPoint(x: 19.0, y: 0.0), size: CGSize(width: menuButtonWidth - 19.0, height: menuButtonFrame.height))) - transition.updateFrame(node: self.menuButtonTextNode, frame: CGRect(origin: CGPoint(x: 16.0, y: 7.0 - UIScreenPixel), size: menuTextSize)) + var buttonTitlteTransition = transition + if buttonTitleUpdated { + buttonTitlteTransition = .immediate + } + buttonTitlteTransition.updateFrame(node: self.menuButtonTextNode, frame: CGRect(origin: CGPoint(x: 16.0, y: 7.0 - UIScreenPixel), size: menuTextSize)) transition.updateAlpha(node: self.menuButtonTextNode, alpha: menuButtonExpanded ? 1.0 : 0.0) transition.updateFrame(node: self.menuButtonIconNode, frame: CGRect(x: isSendAsButton ? 1.0 + UIScreenPixel : (4.0 + UIScreenPixel), y: 1.0 + UIScreenPixel, width: 30.0, height: 30.0)) diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 6c9567672f..19bbc99b22 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -316,6 +316,10 @@ public final class WebAppController: ViewController, AttachmentContainable { }) } + Queue.mainQueue().after(1.0, { + webView.handleTap() + }) + if let (layout, navigationBarHeight) = self.validLayout { self.containerLayoutUpdated(layout, navigationBarHeight: navigationBarHeight, transition: .immediate) } diff --git a/submodules/WebUI/Sources/WebAppWebView.swift b/submodules/WebUI/Sources/WebAppWebView.swift index 51998d4b00..74fb72e74f 100644 --- a/submodules/WebUI/Sources/WebAppWebView.swift +++ b/submodules/WebUI/Sources/WebAppWebView.swift @@ -130,7 +130,7 @@ final class WebAppWebView: WKWebView { self.sendEvent(name: "viewport_changed", data: "{height:\(frame.height)}") } - private(set) var didTouchOnce = true + private(set) var didTouchOnce = false @objc func handleTap() { self.didTouchOnce = true }