mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-23 06:35:51 +00:00
Don't send main_button_pressed event if button is inactive
This commit is contained in:
@@ -371,12 +371,12 @@ private final class LoadingProgressNode: ASDisplayNode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public struct AttachmentMainButtonState {
|
public struct AttachmentMainButtonState {
|
||||||
let text: String?
|
public let text: String?
|
||||||
let backgroundColor: UIColor
|
public let backgroundColor: UIColor
|
||||||
let textColor: UIColor
|
public let textColor: UIColor
|
||||||
let isVisible: Bool
|
public let isVisible: Bool
|
||||||
let isLoading: Bool
|
public let isLoading: Bool
|
||||||
let isEnabled: Bool
|
public let isEnabled: Bool
|
||||||
|
|
||||||
public init(
|
public init(
|
||||||
text: String?,
|
text: String?,
|
||||||
|
|||||||
@@ -199,6 +199,12 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
private var placeholderNode: ShimmerEffectNode?
|
private var placeholderNode: ShimmerEffectNode?
|
||||||
|
|
||||||
fileprivate let loadingProgressPromise = Promise<CGFloat?>(nil)
|
fileprivate let loadingProgressPromise = Promise<CGFloat?>(nil)
|
||||||
|
|
||||||
|
fileprivate var mainButtonState: AttachmentMainButtonState? {
|
||||||
|
didSet {
|
||||||
|
self.mainButtonStatePromise.set(.single(self.mainButtonState))
|
||||||
|
}
|
||||||
|
}
|
||||||
fileprivate let mainButtonStatePromise = Promise<AttachmentMainButtonState?>(nil)
|
fileprivate let mainButtonStatePromise = Promise<AttachmentMainButtonState?>(nil)
|
||||||
|
|
||||||
private let context: AccountContext
|
private let context: AccountContext
|
||||||
@@ -397,6 +403,9 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@objc fileprivate func mainButtonPressed() {
|
@objc fileprivate func mainButtonPressed() {
|
||||||
|
if let mainButtonState = self.mainButtonState, !mainButtonState.isVisible || !mainButtonState.isEnabled {
|
||||||
|
return
|
||||||
|
}
|
||||||
self.webView?.lastTouchTimestamp = CACurrentMediaTime()
|
self.webView?.lastTouchTimestamp = CACurrentMediaTime()
|
||||||
self.webView?.sendEvent(name: "main_button_pressed", data: nil)
|
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 isLoading = json["is_progress_visible"] as? Bool
|
||||||
let isEnabled = json["is_active"] 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)
|
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":
|
case "web_app_request_viewport":
|
||||||
@@ -971,7 +980,7 @@ public final class WebAppController: ViewController, AttachmentContainable {
|
|||||||
if let id = id {
|
if let id = id {
|
||||||
paramsString = "{button_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?) {
|
fileprivate func sendPhoneRequestedEvent(phone: String?) {
|
||||||
|
|||||||
Reference in New Issue
Block a user