Want to use savedInstanceState extension in a Comp...
# compose
a
Want to use savedInstanceState extension in a Compose fragment and realized it doesn’t work. Anyone who tried it and made it work?
Writing compose fragments this way. This works fine with Activity.setContent
m
Why do you want to use Fragments with Compose?
a
I’m trying to make it work with Jetpack Navigation and the suggestion around here is to wrap screens in Fragments
m
Thw beauty of Compose is that you don't need neither navigation component nor fragments if you're using compose. There are a couple of samples showing how navigation can be implemented with Compose. For example this one https://proandroiddev.com/implementing-back-navigation-with-jetpack-compose-550b544e4205
a
I figured it out. I just needed to add an id to the container. 🙂 Thanks for your input. I’m aware of all the available approaches in Navigation and fragments fits my situation best.
i
it can be
a
Depends on who you talk to 🙂 fragments make a pretty handy integration point for compose into existing codebases today and it's likely that those codebases will continue in a sort of hybrid state for some time. If you're writing a green field app with compose from the beginning, you probably won't have much use for fragments.
v
I don’t think the goal of compose is to replace fragments per se but it’s a fantastic side effect 😉 In most use cases, you shouldn’t need fragments at all in pure compose screens/apps. They will probably still add support for it for backward compatibility reasons to make the transition smoother.
ah Adam beat me to it 😄
😁 1
a
The intention is for compose to meet you and your codebase where you already are. If that means fragments, so be it. If it doesn't, that's fine too.
2
a
for me the most important one right now is the tooling available. fragments are already well supported, I can easily visualize the nav graphs in AS, type-safety with SafeArgs. Also it works well with navigation between modules.
e
Cant preview the composable in the nav graph can you? 🤔 (Most likely would come when nav component supports compose)
i
There's two bits: previewing composables in the context of a Activity/Fragment layout.xml (which would automatically make that available to the thumbnails in a fragment based navigation graph) and support for a Composable based navigation graph with full Preview support. Both are on the todo list
🔥 1
🎉 1
🆒 4
a
yep no preview yet, but I can visualize the graph with the fragments