Skip to content

Revert "update adaptive layouts samples to navigable scaffolds" #450

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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
import androidx.compose.foundation.layout.Column
Expand All @@ -32,31 +33,30 @@ import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
import androidx.compose.material3.adaptive.layout.AnimatedPane
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
import androidx.compose.material3.adaptive.navigation.BackNavigationBehavior
import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneScaffold
import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldPredictiveBackHandler
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
import androidx.compose.runtime.Composable
import androidx.compose.runtime.rememberCoroutineScope
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.coroutines.launch
import kotlinx.parcelize.Parcelize

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun SampleNavigableListDetailPaneScaffoldParts() {
fun SampleListDetailPaneScaffoldParts() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02]
val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem>()
val scope = rememberCoroutineScope()
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_part03]
NavigableListDetailPaneScaffold(
navigator = scaffoldNavigator,
ListDetailPaneScaffold(
directive = navigator.scaffoldDirective,
value = navigator.scaffoldValue,
// [START_EXCLUDE]
listPane = {},
detailPane = {},
Expand All @@ -65,21 +65,16 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part03]

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part04]
NavigableListDetailPaneScaffold(
navigator = scaffoldNavigator,
ListDetailPaneScaffold(
directive = navigator.scaffoldDirective,
value = navigator.scaffoldValue,
listPane = {
AnimatedPane {
MyList(
onItemClick = { item ->
// Navigate to the detail pane with the passed item
scope.launch {
scaffoldNavigator
.navigateTo(
ListDetailPaneScaffoldRole.Detail,
item
)
}
},
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item)
}
)
}
},
Expand All @@ -90,14 +85,16 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part04]

// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part05]
NavigableListDetailPaneScaffold(
navigator = scaffoldNavigator,
ListDetailPaneScaffold(
directive = navigator.scaffoldDirective,
value = navigator.scaffoldValue,
listPane =
// [START_EXCLUDE]
listPane = {},
{},
// [END_EXCLUDE]
detailPane = {
AnimatedPane {
scaffoldNavigator.currentDestination?.contentKey?.let {
navigator.currentDestination?.content?.let {
MyDetails(it)
}
}
Expand All @@ -109,80 +106,37 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Preview
@Composable
fun SampleNavigableListDetailPaneScaffoldFull() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem>()
val scope = rememberCoroutineScope()
fun SampleListDetailPaneScaffoldFull() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
val navigator = rememberListDetailPaneScaffoldNavigator<MyItem>()

NavigableListDetailPaneScaffold(
navigator = scaffoldNavigator,
listPane = {
AnimatedPane {
MyList(
onItemClick = { item ->
// Navigate to the detail pane with the passed item
scope.launch {
scaffoldNavigator.navigateTo(
ListDetailPaneScaffoldRole.Detail,
item
)
}
},
)
}
},
detailPane = {
AnimatedPane {
// Show the detail pane content if selected item is available
scaffoldNavigator.currentDestination?.contentKey?.let {
MyDetails(it)
}
}
},
)
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
}

@OptIn(ExperimentalMaterial3AdaptiveApi::class)
@Composable
fun SampleListDetailPaneScaffoldWithPredictiveBackFull() {
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_with_pb_full]
val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem>()
val scope = rememberCoroutineScope()

ThreePaneScaffoldPredictiveBackHandler(
navigator = scaffoldNavigator,
backBehavior = BackNavigationBehavior.PopUntilContentChange
)
BackHandler(navigator.canNavigateBack()) {
navigator.navigateBack()
}

ListDetailPaneScaffold(
directive = scaffoldNavigator.scaffoldDirective,
scaffoldState = scaffoldNavigator.scaffoldState,
directive = navigator.scaffoldDirective,
value = navigator.scaffoldValue,
listPane = {
AnimatedPane {
MyList(
onItemClick = { item ->
// Navigate to the detail pane with the passed item
scope.launch {
scaffoldNavigator.navigateTo(
ListDetailPaneScaffoldRole.Detail,
item
)
}
navigator.navigateTo(ListDetailPaneScaffoldRole.Detail, item)
},
)
}
},
detailPane = {
AnimatedPane {
// Show the detail pane content if selected item is available
scaffoldNavigator.currentDestination?.contentKey?.let {
navigator.currentDestination?.content?.let {
MyDetails(it)
}
}
},
)
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_with_pb_full]
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
}

@Composable
Expand Down
Loading