-
Notifications
You must be signed in to change notification settings - Fork 56
[WIP] Three Panes (List-List-Detail) Strategy #52
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
base: main
Are you sure you want to change the base?
Conversation
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.
Summary of Changes
Hello @tiwiz, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request lays the groundwork for implementing a flexible and adaptive three-pane (List-List-Detail) UI pattern within the application. It introduces core components and strategies that allow the user interface to intelligently adjust its layout based on the available screen real estate, providing an optimized experience across various device form factors.
Highlights
- Adaptive Layout Implementation: New
DualPaneScene
andThreePaneScene
components, along with their respectiveSceneStrategy
implementations, are added to manage multi-pane layouts based onWindowSizeClass
. These strategies dynamically determine how many panes to display (one, two, or three) based on the available screen width. - New Three-Pane Activity Example: A
ThreePanesActivity
is introduced as a practical example of how to integrate the new adaptive navigation strategies. This activity demonstrates a List-List-Detail flow, where the UI adapts from a single pane to a dual-pane or three-pane layout as the window size increases. - Dependency Updates and Additions: The project's
build.gradle.kts
file has been updated to includeandroidx.window
andandroidx.window.core
dependencies, which are crucial for adaptive layouts. Additionally, several existing dependencies, including Kotlin, Compose BOM, and Navigation3, have been updated to their latest versions.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces a new three-pane layout strategy, which is a great addition for adaptive UIs. The implementation is a good starting point. My review includes a critical fix for a UI bug in the list display, along with several suggestions to improve code clarity, maintainability, and documentation accuracy. These include correcting KDocs, removing redundant dependencies and code, and adopting more idiomatic Kotlin constructs.
@@ -71,6 +71,8 @@ dependencies { | |||
implementation(libs.androidx.material3.windowsizeclass) | |||
implementation(libs.androidx.adaptive.layout) | |||
implementation(libs.androidx.material3.navigation3) | |||
implementation(libs.androidx.window) | |||
implementation(libs.androidx.window.core) |
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.
* A [SceneStrategy] that always creates a 1-entry [Scene] simply displaying the last entry in the | ||
* list. | ||
*/ |
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.
The KDoc for DualPaneSceneStrategy
is inaccurate. It states that it always creates a "1-entry [Scene]", but it actually creates a DualPaneScene
which contains two entries when screen width and back stack depth conditions are met. Please update the documentation to reflect the actual behavior.
* A [SceneStrategy] that always creates a 1-entry [Scene] simply displaying the last entry in the | |
* list. | |
*/ | |
* A [SceneStrategy] that creates a [DualPaneScene] when the window width is medium or larger | |
* and there are at least two entries in the back stack. | |
*/ |
* Basic example with two screens that uses the entryProvider DSL and has a persistent back stack. | ||
*/ |
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.
The KDoc for ThreePanesActivity
appears to be copied from another example. It mentions "two screens", but this activity demonstrates a three-pane layout. Please update the documentation to be accurate.
* Basic example with two screens that uses the entryProvider DSL and has a persistent back stack. | |
*/ | |
* Basic example that demonstrates a three-pane layout strategy. | |
*/ |
import androidx.navigation3.ui.SceneStrategy | ||
import androidx.window.core.layout.WindowSizeClass | ||
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_LARGE_LOWER_BOUND | ||
import androidx.window.core.layout.WindowSizeClass.Companion.WIDTH_DP_MEDIUM_LOWER_BOUND |
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.
private fun computeEntriesAndEmptyState() : Triple<NavEntry<T>, NavEntry<T>?, NavEntry<T>?> { | ||
if(entries.size >= 3) { | ||
return Triple(entries[entries.lastIndex - 2], entries[entries.lastIndex - 1], entries.last()) | ||
} else if(entries.size == 2) { | ||
return Triple(entries[entries.lastIndex - 1], entries.last(), null) | ||
} else { | ||
return Triple(entries.last(), null, null) | ||
} | ||
} |
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.
This if-else if-else
chain can be replaced with a when
expression, which is more idiomatic and generally more readable in Kotlin.
private fun computeEntriesAndEmptyState() : Triple<NavEntry<T>, NavEntry<T>?, NavEntry<T>?> {
return when {
entries.size >= 3 -> Triple(entries[entries.lastIndex - 2], entries[entries.lastIndex - 1], entries.last())
entries.size == 2 -> Triple(entries.first(), entries.last(), null)
else -> Triple(entries.first(), null, null)
}
}
* A [SceneStrategy] that always creates a 1-entry [Scene] simply displaying the last entry in the | ||
* list. | ||
*/ |
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.
The KDoc for ThreePaneSceneStrategy
is inaccurate and seems to be copied from another class. It should describe that this strategy creates a ThreePaneScene
for large-width windows.
* A [SceneStrategy] that creates a [ThreePaneScene] when the window width is large. The
* [ThreePaneScene] can display one, two, or three panes depending on the back stack depth.
*/
/* | ||
@Composable | ||
internal fun <T : Any> SceneStrategy<T>.calculateSceneWithSinglePaneFallback( | ||
entries: List<NavEntry<T>>, | ||
onBack: (count: Int) -> Unit, | ||
): Scene<T> = | ||
calculateScene(entries, onBack) ?: ThreePaneSceneStrategy<T>().calculateScene(entries, onBack) | ||
*/ |
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.
@@ -59,6 +60,8 @@ kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serializa | |||
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationCore" } | |||
androidx-material-icons-extended = { group = "androidx.compose.material", name = "material-icons-extended" } | |||
androidx-material3-navigation3 = { group = "androidx.compose.material3.adaptive", name = "adaptive-navigation3", version.ref = "nav3Material" } | |||
androidx-window = { group = "androidx.window", name = "window", version.ref = "window" } | |||
androidx-window-core = { group = "androidx.window", name = "window-core", version.ref = "window" } |
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.
The androidx-window-core
library is a transitive dependency of androidx-window
. It's good practice to only declare direct dependencies in your Gradle files. Since androidx.window.core
is not needed directly, you can remove this line. Remember to also remove the corresponding implementation from app/build.gradle.kts
.
No description provided.