Composables and modifiers
rememberFoldState, rememberHinge, rememberFoldStateFlow, rememberPostureTransition, ProvideFoldState, FoldAwareTwoPane, TabletopLayout and Modifier.avoidFold.
rememberFoldState
@Composable
public fun rememberFoldState(): FoldState
The current FoldState, updated as the device folds and unfolds. It returns the state of the nearest ProvideFoldState when there is one, otherwise the state the platform reports. JVM and wasm report FoldState.None.
rememberHinge
@Composable
public fun rememberHinge(): Hinge?
The current Hinge, or null. Shorthand for rememberFoldState().hinge.
rememberFoldStateFlow
@Composable
public fun rememberFoldStateFlow(): StateFlow<FoldState>
The current FoldState as a StateFlow, for a view-model or other code outside composition. It follows rememberFoldState() and has the current state from the first read. It updates only while the call is in the composition, then keeps its last value. See observing the fold.
postures
public fun StateFlow<FoldState>.postures(): Flow<Posture>
The Posture of each state: the current one first, then only when it changes. A change of hinge angle within a posture emits nothing.
rememberPostureTransition
@Composable
public fun rememberPostureTransition(): PostureTransition
| Property | Description |
|---|---|
previous |
The posture before the latest change. Equal to current until the posture first changes. |
current |
The current posture. |
changed |
Whether the posture has changed since the composition began. |
Recomposes when the posture changes, not when only the hinge angle does.
ProvideFoldState
@Composable
public fun ProvideFoldState(state: FoldState, content: @Composable () -> Unit)
| Parameter | Description |
|---|---|
state |
The state rememberFoldState() returns inside content. |
content |
The content that reads it. |
For previews, tests and simulators.
FoldAwareTwoPane
@Composable
public fun FoldAwareTwoPane(
first: @Composable () -> Unit,
second: @Composable () -> Unit,
modifier: Modifier = Modifier,
fallback: TwoPaneFallback = TwoPaneFallback.FirstOnly,
)
| Parameter | Description |
|---|---|
first |
The left pane across a vertical fold, the top pane across a horizontal one. |
second |
The right or bottom pane. |
modifier |
Applied to the layout. |
fallback |
What to show when no separating fold crosses the layout. |
With a separating fold the panes split exactly at the fold, and skip its bounds when isOccluding. See two-pane layouts.
TabletopLayout
@Composable
public fun TabletopLayout(
top: @Composable () -> Unit,
bottom: @Composable () -> Unit,
modifier: Modifier = Modifier,
flat: @Composable () -> Unit = top,
)
| Parameter | Description |
|---|---|
top |
Shown above the fold in Posture.Tabletop. |
bottom |
Shown below the fold in Posture.Tabletop. |
modifier |
Applied to the layout. |
flat |
Shown in every other posture. Defaults to top. |
See tabletop mode.
Modifier.avoidFold
public fun Modifier.avoidFold(): Modifier
When a separating fold crosses the element, the element keeps its place in the layout and draws its content on the larger side of the fold. Otherwise nothing changes. See avoiding the fold.