Hello guys, I’m new to Android and Jetpack Compose...
# compose
s
Hello guys, I’m new to Android and Jetpack Compose and I was wondering if there is any way of having a global state of the application? Just like React-Native has Redux? I know there’s a library called ReduxKotlin, I was wondering if anybody else used it or have any suggestions about how this can be achieved. (not necessarily through the ReduxKotlin library)
g
A singleton pattern or global object works.
l
You can use a ViewModel with Compose I believe: https://developer.android.com/topic/libraries/architecture/viewmodel
s
@Laura Kelly That’s what I was confused about. Since I’m new to both Android and Jetpack Compose, I know the standard architecture is MVVM. But i’m not sure how that is affected when Jetpack Compose comes in. 😞
👆 1
l
TBH I think that style of architecture works even better with declarative UI, but I'm not sure if there are many examples out there yet
s
I still don’t know if I should try MVVM or just give ReduxKotlin a try. I’ll research this further and hopefully come to a decision. Thanks for the help
z
Compose really just affects the View part of MVVM (or any other architecture pattern). Doesn’t need to touch any other parts of your app.
s
What about the global state part? As far as I know (which is really not much on this subject) the View, Model, and ViewModel are somehow tied together. Like If Im logged in in my application. Can I get the loggedIn user’s data in another module of my application without having to write another ViewModel? Or without making the call to the database again?
z
Sure, but that has nothing to do with Compose
☝️ 3
👍 4
s
Alright, thanks
a
If you look at compose-samples you’ll see different state management patterns and architectural patterns applied for each sample. That showcases that compose is really architecture agnostic (although it facilitates best practices like unidirectional data flow).
But I get your question. I think the answer is that there is no really a mainstream Redux-like framework (or “library”) for Android AFAIK. There are some quite popular libraries porting Redux in Android, but generally Android is still using MVVM/MVP/Clean Architecture, sometimes with sprinkles of patterns inspired by Redux
Also some may argue that Android does not need a complete port of Redux, some ideas can be implemented in a more natural Android way