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 👇🏽
![Screenshot 2023-09-05 at 2 03 42 PM](https://private-user-images.githubusercontent.com/4394910/265825977-720ee641-6826-4cf6-a2e9-b113e22ab1a6.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk1NzA5ODksIm5iZiI6MTcxOTU3MDY4OSwicGF0aCI6Ii80Mzk0OTEwLzI2NTgyNTk3Ny03MjBlZTY0MS02ODI2LTRjZjYtYTJlOS1iMTEzZTIyYWIxYTYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjhUMTAzMTI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9Y2EyM2FkMTFjYTkwMWIwYmRmN2FlOTU4OTZjNmEzZjJhODFiNWQzMjY0NTFmZGY4NDZjODEzZWQzZWMwODRhOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.LTYfeMZjpEQk65N2S3NqANJqr80_jDuhRvUwkkk3ioA)
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
![Screenshot 2023-09-05 at 2 58 31 PM](https://private-user-images.githubusercontent.com/4394910/265835485-ddb5564e-f9fd-4129-a657-fff3fb399885.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MTk1NzA5ODksIm5iZiI6MTcxOTU3MDY4OSwicGF0aCI6Ii80Mzk0OTEwLzI2NTgzNTQ4NS1kZGI1NTY0ZS1mOWZkLTQxMjktYTY1Ny1mZmYzZmIzOTk4ODUucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDYyOCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA2MjhUMTAzMTI5WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MWUzMjQxMTU1NTdhNzE0MjRlZTI0MjQzNDg0MzVhNjA1NDg2NjBhMWIyOTRlOWUzMzM2OTM2NmUxYjM1YjEyMiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.WaghFJgU7BDEXCn4SbMoWheDoj2Le4weLvrwRVJ4vaI)
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.