17
17
package com.google.samples.apps.nowinandroid.ui.interests2pane
18
18
19
19
import androidx.activity.compose.BackHandler
20
- import androidx.annotation.Keep
21
20
import androidx.compose.animation.AnimatedContent
22
21
import androidx.compose.foundation.interaction.MutableInteractionSource
23
22
import androidx.compose.foundation.layout.Box
@@ -27,55 +26,44 @@ import androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi
27
26
import androidx.compose.material3.adaptive.WindowAdaptiveInfo
28
27
import androidx.compose.material3.adaptive.currentWindowAdaptiveInfo
29
28
import androidx.compose.material3.adaptive.layout.AnimatedPane
30
- import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffold
31
29
import androidx.compose.material3.adaptive.layout.ListDetailPaneScaffoldRole
32
30
import androidx.compose.material3.adaptive.layout.PaneAdaptedValue
33
31
import androidx.compose.material3.adaptive.layout.PaneExpansionAnchor
34
32
import androidx.compose.material3.adaptive.layout.ThreePaneScaffoldDestinationItem
35
33
import androidx.compose.material3.adaptive.layout.calculatePaneScaffoldDirective
34
+ import androidx.compose.material3.adaptive.layout.defaultDragHandleSemantics
36
35
import androidx.compose.material3.adaptive.layout.rememberPaneExpansionState
36
+ import androidx.compose.material3.adaptive.navigation.BackNavigationBehavior
37
+ import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneScaffold
37
38
import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldNavigator
39
+ import androidx.compose.material3.adaptive.navigation.ThreePaneScaffoldPredictiveBackHandler
38
40
import androidx.compose.material3.adaptive.navigation.rememberListDetailPaneScaffoldNavigator
39
41
import androidx.compose.runtime.Composable
40
42
import androidx.compose.runtime.getValue
41
- import androidx.compose.runtime.key
42
43
import androidx.compose.runtime.mutableStateOf
43
44
import androidx.compose.runtime.remember
44
45
import androidx.compose.runtime.rememberCoroutineScope
45
- import androidx.compose.runtime.saveable.Saver
46
- import androidx.compose.runtime.saveable.rememberSaveable
47
46
import androidx.compose.runtime.setValue
48
47
import androidx.compose.ui.Modifier
49
48
import androidx.compose.ui.draw.clipToBounds
50
49
import androidx.compose.ui.layout.layout
51
50
import androidx.compose.ui.unit.dp
52
51
import androidx.hilt.navigation.compose.hiltViewModel
53
52
import androidx.lifecycle.compose.collectAsStateWithLifecycle
54
- import androidx.lifecycle.viewmodel.viewModelFactory
55
53
import androidx.navigation.NavGraphBuilder
56
- import androidx.navigation.compose.NavHost
57
54
import androidx.navigation.compose.composable
58
- import androidx.navigation.compose.rememberNavController
59
55
import com.google.samples.apps.nowinandroid.feature.interests.InterestsRoute
60
56
import com.google.samples.apps.nowinandroid.feature.interests.navigation.InterestsRoute
61
57
import com.google.samples.apps.nowinandroid.feature.topic.TopicDetailPlaceholder
62
58
import com.google.samples.apps.nowinandroid.feature.topic.TopicScreen
63
59
import com.google.samples.apps.nowinandroid.feature.topic.TopicViewModel
64
- import com.google.samples.apps.nowinandroid.feature.topic.TopicViewModel_Factory
65
60
import com.google.samples.apps.nowinandroid.feature.topic.navigation.TopicRoute
66
- import com.google.samples.apps.nowinandroid.feature.topic.navigation.navigateToTopic
67
- import com.google.samples.apps.nowinandroid.feature.topic.navigation.topicScreen
68
61
import kotlinx.coroutines.launch
69
62
import kotlinx.serialization.Serializable
70
- import java.util.UUID
71
63
import kotlin.math.max
72
64
73
65
@Serializable internal object TopicPlaceholderRoute
74
66
75
- // TODO: Remove @Keep when https://issuetracker.google.com/353898971 is fixed
76
- @Keep
77
- @Serializable internal object DetailPaneNavHostRoute
78
-
79
67
fun NavGraphBuilder.interestsListDetailScreen () {
80
68
composable<InterestsRoute > {
81
69
InterestsListDetailScreen ()
@@ -121,9 +109,17 @@ internal fun InterestsListDetailScreen(
121
109
),
122
110
)
123
111
124
- BackHandler (listDetailNavigator.canNavigateBack()) {
112
+ ThreePaneScaffoldPredictiveBackHandler (
113
+ listDetailNavigator,
114
+ BackNavigationBehavior .PopUntilScaffoldValueChange ,
115
+ )
116
+ BackHandler (
117
+ paneExpansionState.currentAnchor == PaneExpansionAnchor .Proportion (0f ) &&
118
+ listDetailNavigator.isListPaneVisible() &&
119
+ listDetailNavigator.isDetailPaneVisible(),
120
+ ) {
125
121
coroutineScope.launch {
126
- listDetailNavigator.navigateBack( )
122
+ paneExpansionState.animateTo( PaneExpansionAnchor . Proportion ( 1f ) )
127
123
}
128
124
}
129
125
@@ -138,14 +134,18 @@ internal fun InterestsListDetailScreen(
138
134
coroutineScope.launch {
139
135
listDetailNavigator.navigateTo(ListDetailPaneScaffoldRole .Detail )
140
136
}
137
+ if (paneExpansionState.currentAnchor == PaneExpansionAnchor .Proportion (1f )) {
138
+ coroutineScope.launch {
139
+ paneExpansionState.animateTo(PaneExpansionAnchor .Proportion (0f ))
140
+ }
141
+ }
141
142
}
142
143
143
144
val mutableInteractionSource = remember { MutableInteractionSource () }
144
145
val minPaneWidth = 300 .dp
145
146
146
- ListDetailPaneScaffold (
147
- value = listDetailNavigator.scaffoldValue,
148
- directive = listDetailNavigator.scaffoldDirective,
147
+ NavigableListDetailPaneScaffold (
148
+ navigator = listDetailNavigator,
149
149
listPane = {
150
150
AnimatedPane {
151
151
Box (
@@ -209,7 +209,7 @@ internal fun InterestsListDetailScreen(
209
209
key = route.id,
210
210
) { factory ->
211
211
factory.create(route.id)
212
- }
212
+ },
213
213
)
214
214
}
215
215
is TopicPlaceholderRoute -> {
@@ -227,6 +227,7 @@ internal fun InterestsListDetailScreen(
227
227
state = paneExpansionState,
228
228
minTouchTargetSize = LocalMinimumInteractiveComponentSize .current,
229
229
interactionSource = mutableInteractionSource,
230
+ semanticsProperties = paneExpansionState.defaultDragHandleSemantics(),
230
231
),
231
232
interactionSource = mutableInteractionSource,
232
233
)
0 commit comments