17
17
package com.example.compose.snippets.adaptivelayouts
18
18
19
19
import android.os.Parcelable
20
+ import androidx.activity.compose.BackHandler
20
21
import androidx.compose.foundation.background
21
22
import androidx.compose.foundation.clickable
22
23
import androidx.compose.foundation.layout.Column
@@ -32,31 +33,30 @@ import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
32
33
import androidx.compose.material3.adaptive.layout.AnimatedPane
33
34
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold
34
35
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
35
- import androidx.compose.material3.adaptive.navigation.BackNavigationBehavior
36
- import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneScaffold
37
- import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldPredictiveBackHandler
38
36
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
39
37
import androidx.compose.runtime.Composable
40
- import androidx.compose.runtime.rememberCoroutineScope
41
38
import androidx.compose.ui.Modifier
42
39
import androidx.compose.ui.graphics.Color
43
40
import androidx.compose.ui.tooling.preview.Preview
44
41
import androidx.compose.ui.unit.dp
45
42
import androidx.compose.ui.unit.sp
46
- import kotlinx.coroutines.launch
47
43
import kotlinx.parcelize.Parcelize
48
44
49
45
@OptIn(ExperimentalMaterial3AdaptiveApi ::class )
50
46
@Composable
51
- fun SampleNavigableListDetailPaneScaffoldParts () {
47
+ fun SampleListDetailPaneScaffoldParts () {
52
48
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02]
53
- val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem >()
54
- val scope = rememberCoroutineScope()
49
+ val navigator = rememberListDetailPaneScaffoldNavigator<MyItem >()
50
+
51
+ BackHandler (navigator.canNavigateBack()) {
52
+ navigator.navigateBack()
53
+ }
55
54
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part02]
56
55
57
56
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part03]
58
- NavigableListDetailPaneScaffold (
59
- navigator = scaffoldNavigator,
57
+ ListDetailPaneScaffold (
58
+ directive = navigator.scaffoldDirective,
59
+ value = navigator.scaffoldValue,
60
60
// [START_EXCLUDE]
61
61
listPane = {},
62
62
detailPane = {},
@@ -65,21 +65,16 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
65
65
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part03]
66
66
67
67
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part04]
68
- NavigableListDetailPaneScaffold (
69
- navigator = scaffoldNavigator,
68
+ ListDetailPaneScaffold (
69
+ directive = navigator.scaffoldDirective,
70
+ value = navigator.scaffoldValue,
70
71
listPane = {
71
72
AnimatedPane {
72
73
MyList (
73
74
onItemClick = { item ->
74
75
// Navigate to the detail pane with the passed item
75
- scope.launch {
76
- scaffoldNavigator
77
- .navigateTo(
78
- ListDetailPaneScaffoldRole .Detail ,
79
- item
80
- )
81
- }
82
- },
76
+ navigator.navigateTo(ListDetailPaneScaffoldRole .Detail , item)
77
+ }
83
78
)
84
79
}
85
80
},
@@ -90,14 +85,16 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
90
85
// [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part04]
91
86
92
87
// [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_part05]
93
- NavigableListDetailPaneScaffold (
94
- navigator = scaffoldNavigator,
88
+ ListDetailPaneScaffold (
89
+ directive = navigator.scaffoldDirective,
90
+ value = navigator.scaffoldValue,
91
+ listPane =
95
92
// [START_EXCLUDE]
96
- listPane = {},
93
+ {},
97
94
// [END_EXCLUDE]
98
95
detailPane = {
99
96
AnimatedPane {
100
- scaffoldNavigator .currentDestination?.contentKey ?.let {
97
+ navigator .currentDestination?.content ?.let {
101
98
MyDetails (it)
102
99
}
103
100
}
@@ -109,80 +106,37 @@ fun SampleNavigableListDetailPaneScaffoldParts() {
109
106
@OptIn(ExperimentalMaterial3AdaptiveApi ::class )
110
107
@Preview
111
108
@Composable
112
- fun SampleNavigableListDetailPaneScaffoldFull () {
113
- // [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
114
- val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem >()
115
- val scope = rememberCoroutineScope()
109
+ fun SampleListDetailPaneScaffoldFull () {
110
+ // [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
111
+ val navigator = rememberListDetailPaneScaffoldNavigator<MyItem >()
116
112
117
- NavigableListDetailPaneScaffold (
118
- navigator = scaffoldNavigator,
119
- listPane = {
120
- AnimatedPane {
121
- MyList (
122
- onItemClick = { item ->
123
- // Navigate to the detail pane with the passed item
124
- scope.launch {
125
- scaffoldNavigator.navigateTo(
126
- ListDetailPaneScaffoldRole .Detail ,
127
- item
128
- )
129
- }
130
- },
131
- )
132
- }
133
- },
134
- detailPane = {
135
- AnimatedPane {
136
- // Show the detail pane content if selected item is available
137
- scaffoldNavigator.currentDestination?.contentKey?.let {
138
- MyDetails (it)
139
- }
140
- }
141
- },
142
- )
143
- // [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full]
144
- }
145
-
146
- @OptIn(ExperimentalMaterial3AdaptiveApi ::class )
147
- @Composable
148
- fun SampleListDetailPaneScaffoldWithPredictiveBackFull () {
149
- // [START android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_with_pb_full]
150
- val scaffoldNavigator = rememberListDetailPaneScaffoldNavigator<MyItem >()
151
- val scope = rememberCoroutineScope()
152
-
153
- ThreePaneScaffoldPredictiveBackHandler (
154
- navigator = scaffoldNavigator,
155
- backBehavior = BackNavigationBehavior .PopUntilContentChange
156
- )
113
+ BackHandler (navigator.canNavigateBack()) {
114
+ navigator.navigateBack()
115
+ }
157
116
158
117
ListDetailPaneScaffold (
159
- directive = scaffoldNavigator .scaffoldDirective,
160
- scaffoldState = scaffoldNavigator.scaffoldState ,
118
+ directive = navigator .scaffoldDirective,
119
+ value = navigator.scaffoldValue ,
161
120
listPane = {
162
121
AnimatedPane {
163
122
MyList (
164
123
onItemClick = { item ->
165
124
// Navigate to the detail pane with the passed item
166
- scope.launch {
167
- scaffoldNavigator.navigateTo(
168
- ListDetailPaneScaffoldRole .Detail ,
169
- item
170
- )
171
- }
125
+ navigator.navigateTo(ListDetailPaneScaffoldRole .Detail , item)
172
126
},
173
127
)
174
128
}
175
129
},
176
130
detailPane = {
177
131
AnimatedPane {
178
132
// Show the detail pane content if selected item is available
179
- scaffoldNavigator .currentDestination?.contentKey ?.let {
133
+ navigator .currentDestination?.content ?.let {
180
134
MyDetails (it)
181
135
}
182
136
}
183
137
},
184
138
)
185
- // [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_with_pb_full ]
139
+ // [END android_compose_adaptivelayouts_sample_list_detail_pane_scaffold_full ]
186
140
}
187
141
188
142
@Composable
0 commit comments