-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Jetpack navigation module #351
Conversation
@elihart @gpeal both #364 and #367 refactors were made to reduce the unnecessary code of inserted by this pull request. I would like to know if, once it is approved, you have any plans of merging it into MvRx project or if you will keep it as a suggestion. Maybe we could split @marukami code into two PRs (one fore Please let me know if you have any further questions. |
d6b3c80
to
02c586f
Compare
@jpventura #364 and #367 Look good to me thanks.
Getting it merged would be good. I update the PR to remove the example as
Yep, an example module a separate PR works. @elihart @gpeal let me know what you think about this revised PR. |
dependencies.gradle
Outdated
@@ -74,6 +73,7 @@ ext { | |||
kotlin : "org.jetbrains.kotlin:kotlin-stdlib-jdk8:${versions.kotlin}", | |||
kotlinReflect : "org.jetbrains.kotlin:kotlin-reflect:${versions.kotlin}", | |||
lifecycleExtensions : "androidx.lifecycle:lifecycle-extensions:${versions.lifecycle}", | |||
lifecycleCommonJava8 : "androidx.lifecycle:lifecycle-common-java8:${versions.lifecycle}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
All versions
, libraries
, testLibraries
, and androidTestLibraries
were lexicographically sorted. Also Java 8 should be the default compiler across all modules.
Maybe lifecycleCommon
would be more semantic/consistent name. Does it make sense @marukami?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
were lexicographically sorted
Ah, I see. lifecycleCommon
seems fine
dogs/build.gradle
Outdated
@@ -20,8 +20,8 @@ android { | |||
} | |||
|
|||
compileOptions { | |||
sourceCompatibility = 1.8 | |||
targetCompatibility = 1.8 | |||
sourceCompatibility JavaVersion.VERSION_1_8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice catch!
toolVersion = "0.8.2" | ||
} | ||
|
||
dependencies { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keep dependencies lexicographycally sorted 😉
dependencies {
implementation libraries.kotlin
implementation libraries.lifecycleCommon
implementation project(":mvrx")
implementation project(":testing")
testImplementation libraries.rxAndroid
testImplementation testLibraries.junit
testImplementation testLibraries.mockito
testImplementation testLibraries.roboeletric
}
mvrx-navigation/build.gradle
Outdated
|
||
// module specific dependencies | ||
dependencies { | ||
def nav_version = "2.3.0-alpha04" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marukami I also had hard times with alpha libraries from Google.
I've found the Androidx stuff to be fine and most issues you can workaround. Far as I can tell Stable and Alpha are mostly the same except the newer APIs, tho this is Andoidx and Google so who knows how they are composing the stable and alpha channel code.
For the Alpha here I was planning to use the TestNavHostController
that comes in the 2.3.0-alpha
; I've found it a lot better than mocking in a few projects. Tho, I did not end up using it, so, yer I think 2.2.1
should work.
2.2.1
it is then.
mvrx-navigation/build.gradle
Outdated
} | ||
|
||
// module specific dependencies | ||
dependencies { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am using your branch in a personal project of mine (that is the whole reason why I was pushing the refactors 😉).
@marukami I was trying to figure out why you made two separated segments of dependencies
into this build.gradle
.
Does not api
already suggests that a package is restricted to the module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some libraries already are saved at dependencies.gradle
:
dependencies {
api libraries.navigationFragmentKtx
api libraries.navigationUiKtx
api libraries.rxAndroid
debugApi libraries.fragment
debugApi libraries.fragmentKtx
implementation libraries.kotlin
implementation libraries.lifecycleCommon
implementation project(":mvrx")
implementation project(":testing")
debugImplementation libraries.fragmentTesting
testImplementation testLibraries.junit
testImplementation testLibraries.mockito
testImplementation testLibraries.navigationTesting
testImplementation testLibraries.roboeletric
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was trying to figure out why you made two separate segments of dependencies into this build.gradle.
We do not need dependencies.gradle
here as these libraries are not shared with any other module and having a separator like a 2nd dependencies seemed like a nice way to segment the core project dependencies from the module-specific dependencies.
Does not api already suggests that a package is restricted to the module?
That rule seems a bit oversimplified. It's an OK rule of thumb inside a project module as for a Library I'm not sure. Tho in a library I don't think it's a restricted module otherwise then we would API include most things.
The assumption is here is the same as with implementation
for Koltin STD and AppCompat. In that the consumer is assumed to already be including the navigation-component
modules otherwise they can't have a navigation graph to attach the ViewModel
.
Tho, I've not managed many libraries and I migth be missing something here.
mvrx/build.gradle
Outdated
|
||
api libraries.rxAndroid | ||
api libraries.rxJava | ||
api libraries.lifecycleCommonJava8 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
api libraries.lifecycleCommon
api libraries.rxAndroid
api libraries.rxJava
@@ -101,11 +101,13 @@ data class FragmentViewModelContext( | |||
/** | |||
* The fragment owner of the ViewModel. | |||
*/ | |||
val fragment: Fragment | |||
val fragment: Fragment, | |||
private val ownerProvider: ViewModelStoreOwner = fragment, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marukami name suggestion: storeOwner
@@ -16,7 +14,7 @@ private object UninitializedValue | |||
*/ | |||
@RestrictTo(RestrictTo.Scope.LIBRARY) | |||
@SuppressWarnings("Detekt.ClassNaming") | |||
class lifecycleAwareLazy<out T>(private val owner: LifecycleOwner, initializer: () -> T) : Lazy<T>, Serializable { | |||
class lifecycleAwareLazy<out T>(owner: LifecycleOwner, initializer: () -> T) : Lazy<T>, Serializable, DefaultLifecycleObserver { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marukami suggestion
class lifecycleAwareLazy<out F>(
owner: LifecycleOwner,
initializer: () -> F
) : Lazy<F>, Serializable, DefaultLifecycleObserver {
I don't know what is the correct Kotlin style according Google/JetBrains when there are tons of parameters and interfaces, but this is the way I cheat the linter and keep things readable (well, at least it does not complain 😉)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what is the correct Kotlin style according Google/JetBrains
There isn't one 😀 I find it a bit hard as the project style XML seems to be at odds with the detetkt rules and AS keeps differing from the projects actual rules.
I only removed the private scope access. I guess we can update the style to match things while we are here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know what is the correct Kotlin style according Google/JetBrains when there are tons of parameters and interfaces, but this is the way I cheat the linter and keep things readable (well, at least it does not complain 😉)
This project has code style checked into git, so you can set this up to be done automatically via code reformatting (ctrl+alt+L or command+option+L by default in Android Studio). The code style for this is kotlin -> wrapping and braces -> function declaration parameters -> chop down if long.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When I made this PR this was the project style. After #387 is merged I'm going to rebase and format to match the updated styles.
mvrx-navigation/build.gradle
Outdated
enabled = false | ||
} | ||
|
||
task coverage(type: JacocoReport, dependsOn: "testDebugUnitTest") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marukami absolute n00b Gradle question:
Since this task is also present at mvrx
, could it be moved to the root build.gradle
file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, the best way is to create a named task in buildSrc and then loop over subprojects and register the task to every module. The tricky thing here is that we have example modules mixed in. Given we only have a few modules a simple custom plugin would reduce the most code per module.
@marukami I don't know what are @elihart and @gpeal roadmap about replacing Rx by Kotlin coroutines). If your features will be merged after #347, build navigation module over coroutines branch could speed up integrating your features in the next release. |
@marukami my last pull request broke Travis CI environment just because my code was not following the correct style, just like yours 😄 Adding this to #!/usr/bin/env bash
./gradlew lintFix && ./gradlew test |
Righto. Are CI jobs only master, not PRs? OK then that's easy to fix |
02c586f
to
50ded18
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@marukami Thanks for all your work on this. Sorry it's taken us a while to get to, I'll try to spend some time on this soon
50ded18
to
96f783e
Compare
96f783e
to
d8141ff
Compare
d8141ff
to
4f36703
Compare
4f36703
to
aee0783
Compare
aee0783
to
08b7a44
Compare
@marukami I'd like to merge this before your other PR so you can include a sample. Without it, it won't be easy for people to figure out how to use it. However, I think you may have mis-targeted this PR. It is targeting master. Did you intend to target |
Ah, yes, I was working on a |
1ea1191
to
eb3d684
Compare
# Conflicts: # CHANGELOG.md # mvrx/src/main/kotlin/com/airbnb/mvrx/MvRxViewModelFactory.kt
* added navigationLifecycleAwareLazy as Navigation ViewModel need to wait for onStart to safely access the navController
eb3d684
to
42598c2
Compare
@gpeal I fix up my git for this 1.0 PR and push up #443 for the 2.0 release. |
Closed by #443 |
navGraphViewModel
for navigation graph view modelsnavigationLifecycleAwareLazy
a slightly forkedlifecycleAwareLazy
that subscribes the MvRx view when possible and if not defers the lazy until the fragment access the view modelMvRxNavDirections
a NavDirections that makes it a little easier to pass an argument Parcelable and set the navigation label if providedNOTES
onViewCreated
callback. During lifecycle flows like re-configuration theNavHostFragment
is not accessible until after the activity onCreate has finished.