diff --git a/submodules/AttachmentUI/Sources/AttachmentPanel.swift b/submodules/AttachmentUI/Sources/AttachmentPanel.swift index ac8c8bf667..15dfef93e9 100644 --- a/submodules/AttachmentUI/Sources/AttachmentPanel.swift +++ b/submodules/AttachmentUI/Sources/AttachmentPanel.swift @@ -371,12 +371,12 @@ private final class LoadingProgressNode: ASDisplayNode { } public struct AttachmentMainButtonState { - let text: String? - let backgroundColor: UIColor - let textColor: UIColor - let isVisible: Bool - let isLoading: Bool - let isEnabled: Bool + public let text: String? + public let backgroundColor: UIColor + public let textColor: UIColor + public let isVisible: Bool + public let isLoading: Bool + public let isEnabled: Bool public init( text: String?, diff --git a/submodules/WebUI/Sources/WebAppController.swift b/submodules/WebUI/Sources/WebAppController.swift index 7d7b62fcea..f00d536de3 100644 --- a/submodules/WebUI/Sources/WebAppController.swift +++ b/submodules/WebUI/Sources/WebAppController.swift @@ -199,6 +199,12 @@ public final class WebAppController: ViewController, AttachmentContainable { private var placeholderNode: ShimmerEffectNode? fileprivate let loadingProgressPromise = Promise(nil) + + fileprivate var mainButtonState: AttachmentMainButtonState? { + didSet { + self.mainButtonStatePromise.set(.single(self.mainButtonState)) + } + } fileprivate let mainButtonStatePromise = Promise(nil) private let context: AccountContext @@ -397,6 +403,9 @@ public final class WebAppController: ViewController, AttachmentContainable { } @objc fileprivate func mainButtonPressed() { + if let mainButtonState = self.mainButtonState, !mainButtonState.isVisible || !mainButtonState.isEnabled { + return + } self.webView?.lastTouchTimestamp = CACurrentMediaTime() self.webView?.sendEvent(name: "main_button_pressed", data: nil) } @@ -635,7 +644,7 @@ public final class WebAppController: ViewController, AttachmentContainable { let isLoading = json["is_progress_visible"] as? Bool let isEnabled = json["is_active"] as? Bool let state = AttachmentMainButtonState(text: text, backgroundColor: backgroundColor, textColor: textColor, isVisible: isVisible, isLoading: isLoading ?? false, isEnabled: isEnabled ?? true) - self.mainButtonStatePromise.set(.single(state)) + self.mainButtonState = state } } case "web_app_request_viewport": @@ -971,7 +980,7 @@ public final class WebAppController: ViewController, AttachmentContainable { if let id = id { paramsString = "{button_id: \"\(id)\"}" } - self.webView?.sendEvent(name: "popup_closed", data: paramsString) + self.webView?.sendEvent(name: "popup_closed", data: paramsString ?? "{}") } fileprivate func sendPhoneRequestedEvent(phone: String?) {