Migrate navigation graph xml to kotlin DSL #754
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change summary
Replaced res/xml/settings_nav.xml with
SettingsRoute
to simplify the process of navigation between fragments, as well as adding new fragments in the future, since there is no need to define an "action" between all adjacent destinations.see also: https://developer.android.com/guide/navigation/design/kotlin-dsl
According to the docs above, the route object should be serializable. While data class with only primitive members become serializable automatically,
ListFragment
could haveConfigDescriptor
andRawConfig
as params. To workaround this,RawConfig
was marked@Serializable
since it contains primitives only, andConfigDescriptor
was modified to store its rawRawConfig
value before parsing. Such thatSettingsRoute
could carry those params while being Serializable:Inside the fragment, there is a new
lazyRoute
function to obtain params in a more type-safe way:Navigation animation was also moved to a centralized position:
Things could be improved
uri
param inSettingsRoute.PinyinDict
got serialized and deserialized multiple times when handling IntentSettingsRoute.QuickPhraseEdit
, eg. make CustomQuickPhrase/BuiltinQuickPhrase SerializableApk size got a little bit larger¯\(ツ)/¯