Don't send main_button_pressed event if button is inactive

This commit is contained in:
Ilya Laktyushin
2023-02-10 19:30:35 +04:00
parent 5926b7f586
commit a02ece5c0e
2 changed files with 17 additions and 8 deletions

View File

@@ -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?,

View File

@@ -199,6 +199,12 @@ public final class WebAppController: ViewController, AttachmentContainable {
private var placeholderNode: ShimmerEffectNode?
fileprivate let loadingProgressPromise = Promise<CGFloat?>(nil)
fileprivate var mainButtonState: AttachmentMainButtonState? {
didSet {
self.mainButtonStatePromise.set(.single(self.mainButtonState))
}
}
fileprivate let mainButtonStatePromise = Promise<AttachmentMainButtonState?>(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?) {