I have a simple "compose" application that contains bottom navigation and two screens. The second screen has custom android view
@Composable
fun ScreenTwo() {
Box(modifier = Modifier.fillMaxSize()) {
AndroidView(
modifier = Modifier.fillMaxSize(),
factory = { context ->
MyCustomView(context)
},
)
}
}
class MyCustomView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
) : androidx.appcompat.widget.AppCompatTextView(context, attrs) {
init {
text = "MyCustomView"
}
}
By clicking the bottom menu tabs screens detach and recreate again as supposed to be. But the reference to my custom view remains and is not being erased from memory.
What am I doing wrong? A github link to the source.
