Hello, I am facing an issue with recomposition. `T...
# compose
a
Hello, I am facing an issue with recomposition.
TabContent
composable only works first time, when the
index
changes I can see the call going into the
TabContent
composable but with the new
element
value the recomposition is not triggered.
Copy code
binding.composeView.setContent {                        
     TabView(topics) { index ->
          val element = topics[index].name
          TabContent(binding, element)
     }
}

@Composable
    private fun TabContent(
        binding: ActivityDiscoverTopicsBinding,
        element: String
    ) {
        AndroidView(
            factory = cb@{ context ->
                val view = binding.fragmentContainer
                if (view.parent != null) {
                    // View already has a parent, handle it (e.g., remove it)
                    (view.parent as ViewGroup).removeView(view)
                }
                view.id = ViewCompat.generateViewId()
                val selfId = view.id

                val fragment = MyFragment.newInstance(
                    list(element)
                )
                supportFragmentManager.commit {
                    setReorderingAllowed(true)
                    add(
                        selfId,
                        fragment
                    )
                }
                return@cb view
            },
        )
    }
j
Use the composable AndroidFragment to commit your fragments in a Composable...
a
So I wrapped this inside a
column's
key modifier. That seems to have worked.