diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt index f56acf10d2..4d4e82a125 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt @@ -1,4 +1,4 @@ package dev.inmo.tgbotapi.webapps typealias EventHandler = WebApp.() -> Unit -typealias ViewportChangedEventHandler = WebApp.(Boolean) -> Unit +typealias ViewportChangedEventHandler = WebApp.(ViewportChangedData) -> Unit diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ViewportChangedData.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ViewportChangedData.kt new file mode 100644 index 0000000000..6f4dd3054a --- /dev/null +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ViewportChangedData.kt @@ -0,0 +1,5 @@ +package dev.inmo.tgbotapi.webapps + +external interface ViewportChangedData { + val isStateStable: Boolean +} diff --git a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt index fbba60f883..5422c340c2 100644 --- a/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt +++ b/tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt @@ -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(), it) }.also { onEventWithBoolean(