Skip to content

Commit ec192c4

Browse files
authored
Merge pull request #435 from akitikkx/fix/simplify-mainscreen-pane-logic
Refactor: Simplify pane navigation logic in MainScreen
2 parents 30adfab + 574d992 commit ec192c4

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

app/src/main/java/com/theupnextapp/ui/main/MainScreen.kt

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import androidx.compose.material3.adaptive.navigation.NavigableListDetailPaneSca
3232
import androidx.compose.material3.adaptive.navigation.rememberSupportingPaneScaffoldNavigator
3333
import androidx.compose.material3.adaptive.navigationsuite.NavigationSuiteScaffold
3434
import androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi
35-
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
3635
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
3736
import androidx.compose.runtime.Composable
3837
import 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

Comments
 (0)