If trying to integrate Compose into existing applications that use something like Single Activity Multiple Fragments, would you continue with creating new fragments when a new view/screen is needed and just inflating a composable view with setContent{} instead of an xml layout?
Or would you end up creating a 'root' fragment somewhere that hosts navigation for any new composable views, similar to how JetNews uses JetNewsApp & Status?
Sorry if that doesn't really make sense. I'll try to clarify if needed.
a
Adam Powell
12/31/2019, 10:02 PM
I've done it by creating a
ComposableFragment
that hosts compose content as its view; works pretty well
b
Bryan Lee
12/31/2019, 10:04 PM
Is this out in dev03 or do we have to wait for a later release?
a
Adam Powell
12/31/2019, 10:14 PM
basically just this:
Copy code
abstract class ComposableFragment : Fragment() {
final override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View? = FrameLayout(container?.context ?: requireContext()).apply {
setContent {
Content(savedInstanceState)
}
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
}
final override fun onDestroyView() {
super.onDestroyView()
(view as? ViewGroup)?.setContent { }
}
@Composable
abstract fun Content(savedInstanceState: Bundle?)
}