-
Notifications
You must be signed in to change notification settings - Fork 237
Updated ListDetailPaneScaffold use to alpha11 #255
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8ec917d
Updated ListDetailPaneScaffold use to alpha11
IanGClifton cf7f8ab
Apply Spotless
IanGClifton b7e2748
Update compose/snippets/src/main/java/com/example/compose/snippets/ad…
IanGClifton 23282f0
Updated m3 adaptive to 1.0.0-alpha12
IanGClifton 922d6ed
Apply Spotless
IanGClifton File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
|
||
package com.example.compose.snippets.adaptivelayouts | ||
|
||
import android.os.Parcelable | ||
import androidx.activity.compose.BackHandler | ||
import androidx.compose.foundation.background | ||
import androidx.compose.foundation.clickable | ||
|
@@ -35,33 +36,25 @@ import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole | |
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.saveable.Saver | ||
import androidx.compose.runtime.saveable.rememberSaveable | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import kotlinx.parcelize.Parcelize | ||
|
||
@OptIn(ExperimentalMaterial3AdaptiveApi::class) | ||
@Composable | ||
fun SampleListDetailPaneScaffoldParts() { | ||
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02] | ||
val navigator = rememberListDetailPaneScaffoldNavigator<Nothing>() | ||
val navigator = rememberListDetailPaneScaffoldNavigator<MyItem>() | ||
|
||
BackHandler(navigator.canNavigateBack()) { | ||
navigator.navigateBack() | ||
} | ||
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02] | ||
|
||
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part01] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Farewell part01, you will be missed 👋 |
||
var selectedItem: MyItem? by rememberSaveable(stateSaver = MyItem.Saver) { | ||
mutableStateOf(null) | ||
} | ||
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part01] | ||
|
||
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part03] | ||
ListDetailPaneScaffold( | ||
directive = navigator.scaffoldDirective, | ||
|
@@ -78,13 +71,11 @@ fun SampleListDetailPaneScaffoldParts() { | |
directive = navigator.scaffoldDirective, | ||
value = navigator.scaffoldValue, | ||
listPane = { | ||
AnimatedPane(Modifier) { | ||
AnimatedPane { | ||
MyList( | ||
onItemClick = { id -> | ||
// Set current item | ||
selectedItem = id | ||
// Switch focus to detail pane | ||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) | ||
onItemClick = { item -> | ||
// Navigate to the detail pane with the passed item | ||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item) | ||
} | ||
) | ||
} | ||
|
@@ -104,9 +95,9 @@ fun SampleListDetailPaneScaffoldParts() { | |
{}, | ||
// [END_EXCLUDE] | ||
detailPane = { | ||
AnimatedPane(Modifier) { | ||
selectedItem?.let { item -> | ||
MyDetails(item) | ||
AnimatedPane { | ||
navigator.currentDestination?.content?.let { | ||
MyDetails(it) | ||
} | ||
} | ||
}, | ||
|
@@ -119,13 +110,7 @@ fun SampleListDetailPaneScaffoldParts() { | |
@Composable | ||
fun SampleListDetailPaneScaffoldFull() { | ||
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full] | ||
// Currently selected item | ||
var selectedItem: MyItem? by rememberSaveable(stateSaver = MyItem.Saver) { | ||
mutableStateOf(null) | ||
} | ||
|
||
// Create the ListDetailPaneScaffoldState | ||
val navigator = rememberListDetailPaneScaffoldNavigator<Nothing>() | ||
val navigator = rememberListDetailPaneScaffoldNavigator<MyItem>() | ||
|
||
BackHandler(navigator.canNavigateBack()) { | ||
navigator.navigateBack() | ||
|
@@ -135,22 +120,20 @@ fun SampleListDetailPaneScaffoldFull() { | |
directive = navigator.scaffoldDirective, | ||
value = navigator.scaffoldValue, | ||
listPane = { | ||
AnimatedPane(Modifier) { | ||
AnimatedPane { | ||
MyList( | ||
onItemClick = { id -> | ||
// Set current item | ||
selectedItem = id | ||
// Display the detail pane | ||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail) | ||
onItemClick = { item -> | ||
// Navigate to the detail pane with the passed item | ||
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item) | ||
}, | ||
) | ||
} | ||
}, | ||
detailPane = { | ||
AnimatedPane(Modifier) { | ||
AnimatedPane { | ||
// Show the detail pane content if selected item is available | ||
selectedItem?.let { item -> | ||
MyDetails(item) | ||
navigator.currentDestination?.content?.let { | ||
MyDetails(it) | ||
} | ||
} | ||
}, | ||
|
@@ -206,19 +189,11 @@ fun MyDetails(item: MyItem) { | |
} | ||
|
||
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_myitem] | ||
class MyItem(val id: Int) { | ||
companion object { | ||
val Saver: Saver<MyItem?, Int> = Saver( | ||
{ it?.id }, | ||
::MyItem, | ||
) | ||
} | ||
} | ||
@Parcelize | ||
class MyItem(val id: Int) : Parcelable | ||
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_myitem] | ||
|
||
val shortStrings = listOf( | ||
"Android", | ||
"Petit four", | ||
"Cupcake", | ||
"Donut", | ||
"Eclair", | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
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.
Will this correctly save
MyItem
in saved instance state? We aren't usingMyItem.Saver
anywhere now, which seems suspicious.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.
You're right, we aren't actually passing the saver into the rememberX so I guess it has to be a Parcelable class to be safely used here.