Skip to content

Commit

Permalink
Changed docs about ChildPanels
Browse files Browse the repository at this point in the history
  • Loading branch information
AJIEKCX authored Nov 8, 2024
1 parent 0c31dc6 commit f2fe2f3
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions docs/extensions/compose.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,34 +298,32 @@ You can use window size classes from the `material3-window-size-class` package t

```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 calculatePanelsMode(): ChildPanelsMode {
fun ChildPanelsModeChangedEffect(onModeChanged: (ChildPanelsMode) -> Unit) {
val windowSize = calculateWindowSizeClass()
return if (windowSize.widthSizeClass < WindowWidthSizeClass.Expanded) {
ChildPanelsMode.SINGLE
} else {
ChildPanelsMode.DUAL
val mode = if (windowSize.widthSizeClass < Expanded) SINGLE else DUAL

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

!!!warning
Function calculateWindowSizeClass will cause recomposition on every window size change. Try to reduce the recomposition scope.

```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) {
val mode = calculatePanelsMode()
DisposableEffect(mode) {
component.setMode(mode)
onDispose { }
}
ChildPanelsModeChangedEffect(component::setMode)

ChildPanels(
panels = component.panels,
Expand Down Expand Up @@ -358,11 +356,7 @@ import com.arkivanov.decompose.router.panels.ChildPanelsMode

@Composable
fun PanelsContent(component: PanelsComponent) {
val mode = calculatePanelsMode()
DisposableEffect(mode) {
component.setMode(mode)
onDispose { }
}
ChildPanelsModeChangedEffect(component::setMode)

ChildPanels(
panels = component.panels,
Expand Down

0 comments on commit f2fe2f3

Please sign in to comment.