Fix theme update bug

This commit is contained in:
Aleksandras Kostarevas 2023-08-14 17:44:08 +03:00
parent d81d79ea67
commit 62ff4f47e4
2 changed files with 27 additions and 6 deletions

View File

@ -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));
}
}

View File

@ -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,6 +123,7 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
touchableHeight = it.height
}, color = MaterialTheme.colorScheme.surface) {
Column {
key(legacyInputView) {
AndroidView(factory = {
legacyInputView!!
}, update = { })
@ -119,8 +131,16 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
}
}
}
}
}
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?) {