Skip to content Skip to sidebar Skip to footer

Keyboard With Jetpack Compose Was Broken By Compose Beta-01 (viewtreelifecycleowner Not Found From Decorview)

This is related to this question As described here I was able to create a keyboard with Jetpack Compose. Now after I upgrade the project from alpha-11 to alpha-12 the code broke (a

Solution 1:

The error message says:

ViewTreeLifecycleOwner not found from DecorView@aaf805f[InputMethod]

Compose looks for a ViewTreeLifecycleOwner set on the DecorView of your whole Window, not the one set on your View itself.

Therefore instead of setting the ViewTrees on the ComposeKeyboardView you return, instead use the InputMethodService API of getWindow() with getDecorView() to get the DecorView of your window.

overridefunonCreateInputView(): View {
    val view = ComposeKeyboardView(this)
    window?.window?.decorView?.let { decorView ->
        ViewTreeLifecycleOwner.set(decorView, this)
        ViewTreeViewModelStoreOwner.set(decorView, this)
        ViewTreeSavedStateRegistryOwner.set(decorView, this)
    }
    return view
}

Post a Comment for "Keyboard With Jetpack Compose Was Broken By Compose Beta-01 (viewtreelifecycleowner Not Found From Decorview)"