You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4cc61bc
Browse filesBrowse the repository at this point in the historyBrowse files
[GH] Add fromSavedState handle method to generated nav args
## Proposed Changes
- Generate a `fromSavedState` method for all nav args classes, similar to the `fromBundle` one.
## Testing
Test: Adapted existing tests to also include the new method
## Issues Fixed
Fixes: 136967621
This is an imported pull request from #122.
Resolves#122
Github-Pr-Head-Sha: d235f9a
GitOrigin-RevId: aa9caad
Change-Id: I74ef156e29b8955ef2422f59c8cc69c86424a43d
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/java/JavaNavWriter.kt
+59-27Lines changed: 59 additions & 27 deletions
Original file line number
Diff line number
Diff line change
@@ -198,8 +198,7 @@ class JavaNavWriter(private val useAndroidX: Boolean = true) : NavWriter<JavaCod
198
198
?:throwIllegalStateException("Destination with arguments must have name")
199
199
val className =ClassName.get(destName.packageName(), "${destName.simpleName()}Args")
200
200
val args = destination.args
201
-
val specs =
202
-
ClassWithArgsSpecs(args, annotations)
201
+
val specs =ClassWithArgsSpecs(args, annotations)
203
202
204
203
val fromBundleMethod =MethodSpec.methodBuilder("fromBundle").apply {
205
204
addAnnotation(annotations.NONNULL_CLASSNAME)
@@ -216,34 +215,30 @@ class JavaNavWriter(private val useAndroidX: Boolean = true) : NavWriter<JavaCod
216
215
addStatement("$T$N = new $T()", className, result, className)
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/java/JavaTypes.kt
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -56,6 +56,8 @@ internal val ACTION_ONLY_NAV_DIRECTION_CLASSNAME: ClassName =
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/kotlin/KotlinNavWriter.kt
+47Lines changed: 47 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -267,6 +267,52 @@ class KotlinNavWriter(private val useAndroidX: Boolean = true) : NavWriter<Kotli
267
267
addStatement("return·%T(${tempVariables.joinToString(", ") { it }})", className)
268
268
}.build()
269
269
270
+
val fromSavedStateHandleFunSpec =FunSpec.builder("fromSavedStateHandle").apply {
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/main/kotlin/androidx/navigation/safe/args/generator/kotlin/KotlinTypes.kt
+2Lines changed: 2 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -62,6 +62,8 @@ internal val ACTION_ONLY_NAV_DIRECTION_CLASSNAME: ClassName =
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/test/test-data/expected/java_nav_writer_test/MainFragment$InnerFragmentArgs.java
+19Lines changed: 19 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@
18
18
19
19
importandroid.os.Bundle;
20
20
importandroidx.annotation.NonNull;
21
+
importandroidx.lifecycle.SavedStateHandle;
21
22
importandroidx.navigation.NavArgs;
22
23
importjava.lang.IllegalArgumentException;
23
24
importjava.lang.Object;
@@ -54,6 +55,24 @@ public class MainFragment$InnerFragmentArgs implements NavArgs {
Copy file name to clipboardExpand all lines: navigation/navigation-safe-args-generator/src/test/test-data/expected/java_nav_writer_test/MainFragmentArgs.java
0 commit comments