Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ sealed class WebAppEvent {
data object RequestTheme : WebAppEvent()
data class SetBackgroundColor(val color: String) : WebAppEvent()
data class SetHeaderColor(val colorKey: String?, val color: String?) : WebAppEvent()
data class SetHeaderText(val text: String) : WebAppEvent()
data class SetBottomBarColor(val color: String) : WebAppEvent()
data class SetupMainButton(
val isVisible: Boolean,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class MiniAppState(
var backgroundColor by mutableStateOf(initialThemeParams.backgroundColor?.let { Color(it.toColorInt()) })
var bottomBarColor by mutableStateOf(initialThemeParams.bottomBarBackgroundColor?.let { Color(it.toColorInt()) })

var headerText by mutableStateOf(botName)

var isExpanded by mutableStateOf(false)
var isFullscreen by mutableStateOf(false)

Expand Down Expand Up @@ -619,10 +617,6 @@ class MiniAppState(
topBarColor = themeParams.headerBackgroundColor?.let { Color(it.toColorInt()) }
}

override fun onSetHeaderText(text: String) {
headerText = text
}

override fun onSetBottomBarColor(color: Int) {
bottomBarColor = Color(color)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ fun MiniAppViewer(
Column(modifier = Modifier.fillMaxSize()) {
if (!state.isFullscreen) {
MiniAppTopBar(
headerText = state.headerText,
headerText = botName,
isBackButtonVisible = state.isBackButtonVisible,
isSettingsButtonVisible = state.isSettingsButtonVisible,
isInitializing = state.isInitializing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ interface TelegramWebAppHost {
fun onSetBackgroundColor(color: Int)
fun onSetHeaderColor(colorKey: String?, customColor: Int?)
fun onResetHeaderColor()
fun onSetHeaderText(text: String)
fun onSetBottomBarColor(color: Int)
fun onResetBottomBarColor()
fun onSetupClosingBehavior(needConfirmation: Boolean)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ class TelegramWebviewProxy(
data.optString("color_key").takeIf { it.isNotEmpty() },
data.optString("color").takeIf { it.isNotEmpty() })

"web_app_set_header_text" -> WebAppEvent.SetHeaderText(data.optString("text"))
"web_app_set_bottom_bar_color" -> WebAppEvent.SetBottomBarColor(data.optString("color"))
"web_app_setup_main_button" -> WebAppEvent.SetupMainButton(
data.optBoolean("is_visible"), data.optBoolean("is_active"),
Expand Down Expand Up @@ -305,7 +304,6 @@ class TelegramWebviewProxy(

is WebAppEvent.SetBackgroundColor -> host.onSetBackgroundColor(parseColor(event.color))
is WebAppEvent.SetHeaderColor -> host.onSetHeaderColor(event.colorKey, event.color?.let { parseColor(it) })
is WebAppEvent.SetHeaderText -> host.onSetHeaderText(event.text)
is WebAppEvent.SetBottomBarColor -> host.onSetBottomBarColor(parseColor(event.color))
is WebAppEvent.SetupMainButton -> host.onSetupMainButton(
event.isVisible,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import android.view.ViewGroup
import android.webkit.*
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.toArgb
import androidx.compose.ui.viewinterop.AndroidView
Expand All @@ -34,6 +38,8 @@ fun MiniAppWebView(
onLoadingChanged: (Boolean) -> Unit,
modifier: Modifier = Modifier
) {
var lastLoadedUrl by remember { mutableStateOf(url) }

AndroidView(
factory = { ctx ->
WebView(ctx).apply {
Expand Down Expand Up @@ -130,8 +136,9 @@ fun MiniAppWebView(
view.setBackgroundColor(
backgroundColor?.toArgb() ?: themeParams.backgroundColor?.toColorInt() ?: Color.TRANSPARENT
)
if (url.isNotEmpty() && view.url != url) {
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, this would reload page every time on background color change, because Theme Params page in playground has different url and url is fixed to base url + init data query

if (url.isNotEmpty() && url != lastLoadedUrl) {
view.loadUrl(url, mapOf("Accept-Language" to acceptLanguage))
lastLoadedUrl = url
}
}
)
Expand Down