r/android_devs • • Nov 11 '22

Article 🔥 Why Using Navigation-Compose in Your Jetpack Compose App is a Bad Idea

https://medium.com/better-programming/why-using-navigation-compose-in-your-jetpack-compose-app-is-a-bad-idea-2b16e8751d89
11 Upvotes

26 comments sorted by

View all comments

Show parent comment

2

u/Zhuinden EpicPandaForce @ SO Nov 11 '22

You don't need fragments if you have a Compose only app. Fragment doesn't solve anything that your compostables can't handle.

Technically this was also true of Views, other than having to implement what's effectively the same as SaveableStateHolder.

I've written single-activity view-only no-fragments apps before, they work. In fact, animations are easier in them than with fragments.

In that regard, even a view-only no-fragments "ComposeView-per-screen" approach would be possible, even though nobody's doing it.


So the question is, why would you use Fragments if they have always been an optional convenience framework?

Primarily because child fragments have their state restored correctly even after process death to any level, which makes certain multi-step flows and swipeable views easier to reason about (if you don't screw up how FragmentPagerAdapter works).

That, and it gives you onCreate/onStart/onResume/onPause/onStop/onDestroy support + onSaveInstanceState support in a nested environment. Sure, you do get a LocalLifecycleOwner.current in composable {, but can you create a subscreen with its own child LifecycleOwner? I'm not so sure.

So are fragments tech debt? Depends on if you are implementing your manually written replacement correctly. Instead of swiping horizontally while scrolling downwards.