Skip to content

Commit

Permalink
Merge pull request #804 from AJIEKCX/child-panels-windowsizeclass-doc
Browse files Browse the repository at this point in the history
Add an example of using window size classes with ChildPanelsMode
  • Loading branch information
arkivanov authored Nov 8, 2024
2 parents 85bbf2f + f2fe2f3 commit 551b6bc
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions docs/extensions/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,37 @@ The default `HorizontalChildPanelsLayout` layout places child components (panels
- If the `mode` is `DUAL`, the Main panel is always displayed on the left side, and then the Details and the Extra panels are displayed in a stack on the right side (next to the Main panel).
- If the `mode` is `TRIPLE`, all panels are displayed horizontally side by side.

You can use window size classes from the `material3-window-size-class` package to determine which `ChildPanelsMode` should be used.

```kotlin title="WindowSizeClass example"
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass
import androidx.compose.material3.windowsizeclass.WindowWidthSizeClass.Companion.Expanded
import androidx.compose.material3.windowsizeclass.calculateWindowSizeClass
import com.arkivanov.decompose.router.panels.ChildPanelsMode
import com.arkivanov.decompose.router.panels.ChildPanelsMode.SINGLE
import com.arkivanov.decompose.router.panels.ChildPanelsMode.DUAL

@Composable
fun ChildPanelsModeChangedEffect(onModeChanged: (ChildPanelsMode) -> Unit) {
val windowSize = calculateWindowSizeClass()
val mode = if (windowSize.widthSizeClass < Expanded) SINGLE else DUAL

DisposableEffect(mode) {
onModeChanged(mode)
onDispose {}
}
}
```

```kotlin title="Basic example"
import androidx.compose.runtime.Composable
import com.arkivanov.decompose.extensions.compose.experimental.panels.ChildPanels
import com.arkivanov.decompose.router.panels.ChildPanelsMode

@Composable
fun PanelsContent(component: PanelsComponent) {
ChildPanelsModeChangedEffect(component::setMode)

ChildPanels(
panels = component.panels,
mainChild = { MainContent(it.instance) },
Expand Down Expand Up @@ -327,9 +352,12 @@ import com.arkivanov.decompose.extensions.compose.experimental.stack.animation.f
import com.arkivanov.decompose.extensions.compose.experimental.stack.animation.plus
import com.arkivanov.decompose.extensions.compose.experimental.stack.animation.scale
import com.arkivanov.decompose.extensions.compose.stack.animation.predictiveback.materialPredictiveBackAnimatable
import com.arkivanov.decompose.router.panels.ChildPanelsMode

@Composable
fun PanelsContent(component: PanelsComponent) {
ChildPanelsModeChangedEffect(component::setMode)

ChildPanels(
panels = component.panels,
mainChild = { MainContent(it.instance) },
Expand Down

0 comments on commit 551b6bc

Please sign in to comment.