Leo N
Jan 3, 2025

--

I don't think passing the NavControllers down to compose tree is a good practice.

1. Encourages Coupling:

- Using CompositionLocal for NavController can tightly couple your composables to the navigation implementation.

- This makes testing and reuse harder because the composables assume the presence of a NavController.

2. Lifecycle Mismatch: NavController is tied to the lifecycle of a NavHost and the activity/fragment it resides in. Providing it via CompositionLocal risks introducing lifecycle mismatches or unintended behaviors.

...

I think you should check android documents deeper: https://developer.android.com/develop/ui/compose/compositionlocal

--

--

Leo N
Leo N

Written by Leo N

πŸ‡»πŸ‡³ πŸ‡ΈπŸ‡¬ πŸ‡²πŸ‡Ύ πŸ‡¦πŸ‡Ί πŸ‡ΉπŸ‡­ Engineer @ GXS Bank, Singapore | MSc πŸŽ“ | Technical Writer . https://github.com/nphausg

No responses yet