From 62ff4f47e426551a352178481e8227aeb7b7b57c Mon Sep 17 00:00:00 2001 From: Aleksandras Kostarevas Date: Mon, 14 Aug 2023 17:44:08 +0300 Subject: [PATCH] Fix theme update bug --- .../keyboard/KeyboardSwitcher.java | 5 ++-- .../org/futo/inputmethod/latin/LatinIME.kt | 28 ++++++++++++++++--- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/java/src/org/futo/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/org/futo/inputmethod/keyboard/KeyboardSwitcher.java index 1143e4a89..7970f8587 100644 --- a/java/src/org/futo/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/org/futo/inputmethod/keyboard/KeyboardSwitcher.java @@ -32,6 +32,7 @@ import org.futo.inputmethod.keyboard.emoji.EmojiPalettesView; import org.futo.inputmethod.keyboard.internal.KeyboardState; import org.futo.inputmethod.keyboard.internal.KeyboardTextsSet; import org.futo.inputmethod.latin.InputView; +import org.futo.inputmethod.latin.LatinIME; import org.futo.inputmethod.latin.LatinIMELegacy; import org.futo.inputmethod.latin.R; import org.futo.inputmethod.latin.RichInputMethodManager; @@ -92,8 +93,8 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions { final boolean themeUpdated = updateKeyboardThemeAndContextThemeWrapper( displayContext, KeyboardTheme.getKeyboardTheme(displayContext /* context */)); if (themeUpdated && mKeyboardView != null) { - mLatinIMELegacy.setInputView( - onCreateInputView(displayContext, mIsHardwareAcceleratedDrawingEnabled)); + ((LatinIME)mLatinIMELegacy.getInputMethodService()).updateLegacyView(onCreateInputView( + displayContext, mIsHardwareAcceleratedDrawingEnabled)); } } diff --git a/java/src/org/futo/inputmethod/latin/LatinIME.kt b/java/src/org/futo/inputmethod/latin/LatinIME.kt index ca88c4b22..b0ed92e21 100644 --- a/java/src/org/futo/inputmethod/latin/LatinIME.kt +++ b/java/src/org/futo/inputmethod/latin/LatinIME.kt @@ -13,6 +13,11 @@ import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Spacer import androidx.compose.material3.MaterialTheme import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.key +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember import androidx.compose.ui.Modifier import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.platform.ComposeView @@ -105,6 +110,12 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save this@LatinIME.setOwners() } + setContent() + + return composeView!! + } + + private fun setContent() { composeView?.setContent { Column { Spacer(modifier = Modifier.weight(1.0f)) @@ -112,15 +123,24 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save touchableHeight = it.height }, color = MaterialTheme.colorScheme.surface) { Column { - AndroidView(factory = { - legacyInputView!! - }, update = { }) + key(legacyInputView) { + AndroidView(factory = { + legacyInputView!! + }, update = { }) + } } } } } + } - return composeView!! + // necessary for when KeyboardSwitcher updates the theme + fun updateLegacyView(newView: View) { + legacyInputView = newView + setContent() + + latinIMELegacy.setComposeInputView(composeView!!) + latinIMELegacy.setInputView(legacyInputView) } override fun setInputView(view: View?) {