@@ -32,7 +32,6 @@ import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneSca
3232import androidx.compose.material3.adaptive.navigation.rememberSupportingPaneScaffoldNavigator
3333import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
3434import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
35- import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
3635import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
3736import androidx.compose.runtime.Composable
3837import androidx.compose.runtime.LaunchedEffect
@@ -116,35 +115,21 @@ fun MainScreen(
116115
117116 val listDetailNavigator = rememberSupportingPaneScaffoldNavigator<ThreePaneScaffoldRole >()
118117
119- windowSizeClass?.let { wsc ->
120- LaunchedEffect (
121- isDetailFlowActive,
122- listDetailNavigator.currentDestination,
123- wsc.widthSizeClass
124- ) {
125- val currentPaneRole = listDetailNavigator.currentDestination?.pane
118+ LaunchedEffect (
119+ isDetailFlowActive,
120+ listDetailNavigator.currentDestination
121+ ) {
122+ val currentPaneRole = listDetailNavigator.currentDestination?.pane
126123
127- if (wsc.widthSizeClass == WindowWidthSizeClass .Compact ) {
128- if (isDetailFlowActive) {
129- if (currentPaneRole != ThreePaneScaffoldRole .Primary ) {
130- listDetailNavigator.navigateTo(ThreePaneScaffoldRole .Primary )
131- }
132- } else {
133- if (currentPaneRole != ThreePaneScaffoldRole .Secondary ) {
134- listDetailNavigator.navigateTo(ThreePaneScaffoldRole .Secondary )
135- }
136- }
137- } else { // Medium or Expanded
138- if (isDetailFlowActive) {
139- if (currentPaneRole != ThreePaneScaffoldRole .Primary ) {
140- listDetailNavigator.navigateTo(ThreePaneScaffoldRole .Primary )
141- }
142- } else {
143- if (currentPaneRole != ThreePaneScaffoldRole .Secondary ) {
144- listDetailNavigator.navigateTo(ThreePaneScaffoldRole .Secondary )
145- }
146- }
147- }
124+ // Common logic for determining target pane based on isDetailFlowActive
125+ val targetPaneRole = if (isDetailFlowActive) {
126+ ThreePaneScaffoldRole .Primary // Show detail
127+ } else {
128+ ThreePaneScaffoldRole .Secondary // Show list
129+ }
130+
131+ if (currentPaneRole != targetPaneRole) {
132+ listDetailNavigator.navigateTo(targetPaneRole)
148133 }
149134 }
150135
0 commit comments