Skip to content

Fix Navigation 3 scene metadata key checks#927

Open
nero002 wants to merge 1 commit into
android:mainfrom
nero002:dheeraj/fix-navigation3-scene-metadata-keys
Open

Fix Navigation 3 scene metadata key checks#927
nero002 wants to merge 1 commit into
android:mainfrom
nero002:dheeraj/fix-navigation3-scene-metadata-keys

Conversation

@nero002
Copy link
Copy Markdown
Contributor

@nero002 nero002 commented May 20, 2026

This makes the list-detail scene snippet explicit about looking up entries in NavEntry metadata by String key.

Test: ANDROID_HOME=/Users/Dheeraj/Library/Android/sdk ./gradlew :compose:snippets:compileDebugKotlin

@nero002 nero002 requested a review from a team as a code owner May 20, 2026 10:55
@nero002 nero002 requested a review from AjeshRPai May 20, 2026 10:55
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies ScenesSnippets.kt by replacing the idiomatic use of the contains extension function with explicit containsKey(Key.toString()) calls for metadata lookups and removing the associated import. The reviewer recommends reverting these changes to use the more idiomatic in operator, which improves readability and maintains consistency with other snippets in the repository. Specific code suggestions were provided to restore the idiomatic syntax for both DetailKey and ListKey checks.

import androidx.navigation3.runtime.NavEntry
import androidx.navigation3.runtime.NavKey
import androidx.navigation3.runtime.NavMetadataKey
import androidx.navigation3.runtime.contains
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This import should be retained if you use the idiomatic in operator or contains extension for metadata key checks, as suggested in the comments below.

entries.lastOrNull()?.takeIf { it.metadata.contains(DetailKey) } ?: return null
val listEntry = entries.findLast { it.metadata.contains(ListKey) } ?: return null
entries.lastOrNull()?.takeIf {
it.metadata.containsKey(DetailKey.toString())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using containsKey(DetailKey.toString()) is less idiomatic than using the contains extension function (or the in operator) provided by the Navigation 3 runtime. This change also introduces an inconsistency with other snippets in the repository, such as MetadataSnippets.kt, which demonstrate the use of the extension. If the extension is functional, it is preferred for better readability and type safety.

Suggested change
it.metadata.containsKey(DetailKey.toString())
DetailKey in it.metadata

it.metadata.containsKey(DetailKey.toString())
} ?: return null
val listEntry =
entries.findLast { it.metadata.containsKey(ListKey.toString()) } ?: return null
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Consistent with the check for DetailKey, consider using the idiomatic in operator here as well.

Suggested change
entries.findLast { it.metadata.containsKey(ListKey.toString()) } ?: return null
entries.findLast { ListKey in it.metadata } ?: return null

@nero002 nero002 force-pushed the dheeraj/fix-navigation3-scene-metadata-keys branch from fe9c912 to 23d8289 Compare May 20, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Wrong example: Basic list-detail layout (custom Scene and strategy)

1 participant