Comments (6)
I'm looking into https://airbnb.io/mavericks/#/fragment-arguments?id=using-fragment-args-in-the-initial-value-for-mavericksstate
The following might work:
LoginFragmentDirections.actionLoginFragmentToHome(userFullName = it.userFullName)
data class HomeState(
val userFullName: String,
val paymentList: Async<List<Payment>> = Uninitialized,
val coarseLocationPermissionGranted: Boolean = false,
val deviceLastLocationCoordinates: Pair<Double, Double> = Pair(0.0, 0.0),
val count: Int = 0
) : MavericksState {
constructor(homeFragmentArgs: HomeFragmentArgs) : this(userFullName = homeFragmentArgs.userFullName.orEmpty())
from mavericks.
I'm looking into https://airbnb.io/mavericks/#/fragment-arguments?id=using-fragment-args-in-the-initial-value-for-mavericksstate
The following might work:
LoginFragmentDirections.actionLoginFragmentToHome(userFullName = it.userFullName)data class HomeState( val userFullName: String, val paymentList: Async<List<Payment>> = Uninitialized, val coarseLocationPermissionGranted: Boolean = false, val deviceLastLocationCoordinates: Pair<Double, Double> = Pair(0.0, 0.0), val count: Int = 0 ) : MavericksState { constructor(homeFragmentArgs: HomeFragmentArgs) : this(userFullName = homeFragmentArgs.userFullName.orEmpty())
Nah, that alternate constructor
setup didn't work. Not sure whether or not it's because I'm not doing the steps 👇🏽
from mavericks.
Well things ARE working when I follow the steps above
However, this process seems opposite to using the arguments declared in the Navigation Component nav graph XML file. I still have to create custom Parcelizable argument data classes 😕 I'm unable to use generated _____Directions
and do something like
findNavController().navigate(LoginFragmentDirections.actionLoginFragmentToHome(userFullName = it.userFullName))
I know that custom Parcelable
objects can be passed through as arguments
However, this doesn't really help me from avoiding having to create these custom args classes in the first place 😕
from mavericks.
Any thoughts on this @gpeal @elihart ?
from mavericks.
Doesn't really address this ticket's topic/question, but another option I just thought of was to save the full name to repo-level persistence in LoginViewModel
and just fetch it in HomeViewModel
instead of passing it at Navigation Component arguments from one fragment/VM to another.
from mavericks.
Closing the loop here. This is what I've ultimately ended up with and I'm posting it here mainly so that others might benefit from it.
I created a setAsMavericksArgs
extension function, which has made things pretty easy and minimal when going from one fragment/VM to another.
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
@Parcelize
class ParcelableClassWithArgs(
var stringValue: String? = "",
var booleanValue: Boolean? = false,
): Parcelable
Parcelable
extension function 👇🏽
fun Parcelable.setAsMavericksArgs(fragment: Fragment): Bundle {
this.asMavericksArgs().let {
fragment.arguments = it
return it
}
}
Fragment
extension function 👇🏽
fun Fragment.navigate(actionInt: Int, optionalArgs: Bundle? = null) =
findNavController().navigate(actionInt, optionalArgs)
Navigating in the Fragment
👇🏽
navigate(
NavGraphDirections.actionToNextFragment().actionId,
ParcelableClassWithArgs(
...various values
).setAsMavericksArgs(this)
)
Setup in the ViewModel
of the Fragment
that has been navigated to
data class ReceivingViewModelState(
val args: ParcelableClassWithArgs? = null,
) : MavericksState {
constructor(parcelableClassWithArgs: ParcelableClassWithArgs) : this(args = parcelableClassWithArgs)
}
from mavericks.
Related Issues (20)
- how to use stateflow in MavericksViewModel HOT 2
- How can I use MavericksView in a View or a Layout
- compare with mvc,mvp,mvvm HOT 2
- The viewModel() method may be missing the postInvalidate() logic. HOT 2
- Exploration of the correct way to update state with List<Data> in state HOT 1
- Ensure that your state properties properly implement hashCode. HOT 7
- I wanted to use the latest version of Epoxy, Mavericks, Paging3 (Epoxy Paging3), but couldn't find the Demo. Is it possible to combine all three?
- java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified
- java.lang.IllegalStateException HOT 1
- Value classes break State class no zero argument constructor usage HOT 1
- Discuss whenStarted function deprecation HOT 7
- I am using MavericksViewModel on Compose, I want to get the LifecycleOwner object in ViewModel how do I need to get this? HOT 3
- Crash when creating MavericksViewModel HOT 6
- Combining Mavericks with "custom" network response and error handling HOT 1
- Question - collectAsStateWithLifecycle HOT 4
- how to use maverik on activity ?
- Complex ViewModels can cause unstable Composables HOT 3
- Unable to resolve - hiltMavericksViewModelFactory HOT 3
- MavericksView invalidate not being called
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mavericks.