1
0
mirror of https://github.com/InsanusMokrassar/TelegramBotAPI.git synced 2024-11-25 03:28:44 +00:00

fixes in viewport changed events

This commit is contained in:
InsanusMokrassar 2022-04-19 15:14:59 +06:00
parent f4b080cb45
commit c74df3960c
3 changed files with 9 additions and 4 deletions

View File

@ -1,4 +1,4 @@
package dev.inmo.tgbotapi.webapps
typealias EventHandler = WebApp.() -> Unit
typealias ViewportChangedEventHandler = WebApp.(Boolean) -> Unit
typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit

View File

@ -0,0 +1,5 @@
package dev.inmo.tgbotapi.webapps
external interface ViewportChangedData {
val isStateStable: Boolean
}

View File

@ -19,11 +19,11 @@ external class WebApp {
internal fun onEvent(type: String, callback: () -> Unit)
@JsName("onEvent")
internal fun onEventWithBoolean(type: String, callback: (Boolean) -> Unit)
internal fun onEventWithBoolean(type: String, callback: (ViewportChangedData) -> Unit)
fun offEvent(type: String, callback: () -> Unit)
@JsName("offEvent")
fun offEventWithBoolean(type: String, callback: (Boolean) -> Unit)
fun offEventWithBoolean(type: String, callback: (ViewportChangedData) -> Unit)
fun sendData(data: String)
@ -54,7 +54,7 @@ fun WebApp.onEvent(type: EventType, eventHandler: EventHandler) = {
/**
* @return The callback which should be used in case you want to turn off events handling
*/
fun WebApp.onEvent(type: EventType.ViewportChanged, eventHandler: ViewportChangedEventHandler) = { it: Boolean ->
fun WebApp.onEvent(type: EventType.ViewportChanged, eventHandler: ViewportChangedEventHandler) = { it: ViewportChangedData ->
eventHandler(js("this").unsafeCast<WebApp>(), it)
}.also {
onEventWithBoolean(