From c74df3960c12f17e627d02446136fa6eaac2c677 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 19 Apr 2022 15:14:59 +0600 Subject: [PATCH] fixes in viewport changed events --- .../jsMain/kotlin/dev/inmo/tgbotapi/webapps/EventHandler.kt | 2 +- .../kotlin/dev/inmo/tgbotapi/webapps/ViewportChangedData.kt | 5 +++++ .../src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/WebApp.kt | 6 +++--- 3 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 tgbotapi.webapps/src/jsMain/kotlin/dev/inmo/tgbotapi/webapps/ViewportChangedData.kt 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(