folks I have an issue with the nav3 library just (...
# compose-android
b
folks I have an issue with the nav3 library just (2 months or so ago ) dropped by the android team It concerns the sharedviewmodels that was a great performance management technique to scope shared state across screen boundaries since many years now , even before compose Now as per the new nav3 introduction , they have sort of buried the idea of a "nested nav graph" , and in effect that would also mean we cannot scope a viewmodel across multiple destinations . Any idea guys how about should we do that now ? Strangely the official docs are silent about this . There is a way to use the sharedViewModel in nav3 too , like posited here , but this suffers from the issue that any destination that takes in a sharedViewModel , CANNOT use a viewmodel that is scoped to itself as mentioned in an issue here. Sooo yeah , any inkling as to how should we go about sharing data across a few composables guys if not for sharedviewmodel ?
p
Video for CMP but applies to plain Android too:

https://youtu.be/8jZ0O5fZ5DU?si=Emt_F7qhDsoFRTcm

Honestly, SharedVM is not an appealing pattern. A Composable screen that takes more than one VM just doesn't look appealing. Even though in John Gossman articles he did not talk explicitly bad about sharing one VM from different Views. In practicality makes the screen input look complex for no reason. If you want to share something between 2 or more screens. It is better to have a UiSharedDataManager scoped to your Nav3 root graph, which instance is reused in every screen, either using VM constructor Dependency Injection or manually being passed to the ViewModels via property setter.
⬆️ 3
b
@Pablichjenkov this video posts an amazing idea but doesn't work with multistack applications , meaning where each bottombar destination is a stack , this approach would fail . I am more interested in your very eye opening observations about the concept of sharedviewmodels and why they appear "less appealing" to you . I think you have a point here and i would agree that perhaps we need to shift how we viewed nested graphs and sharedviewmodels since perhaps the android team is also looking at the situation like you are . TY mate
👍 1
p
I wonder 🤔 why the solution in Video doesn't work for you. Can't you have a SharedViewModel scoped to the same scope each of your stacks is scoped to.