Skip to content

Commit

Permalink
fix: Fix horizontal RTL alignment of vertical arrangement (#23)
Browse files Browse the repository at this point in the history
* chore: Change order of function parameters

* fix: Fix horizontal RTL alignment of vertical arrangement
  • Loading branch information
svenjacobs authored Jan 4, 2023
1 parent 2c5ea80 commit 5872d3b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.layout
import androidx.compose.ui.unit.IntRect
import androidx.compose.ui.unit.IntSize
import androidx.compose.ui.unit.LayoutDirection

/**
* Scope for overlay content which provides Modifiers to align an element relative to the
Expand Down Expand Up @@ -86,7 +85,7 @@ internal class RevealOverlayScopeInstance(
constraints.copy(maxWidth = layoutSize.width),
)

layout(layoutSize.width, layoutSize.height) {
layout(constraints.maxWidth, constraints.maxHeight) {
placeable.placeRelative(
x = horizontalArrangement.align(
size = placeable.width,
Expand Down Expand Up @@ -121,12 +120,14 @@ internal class RevealOverlayScopeInstance(
constraints.copy(maxHeight = layoutSize.height),
)

layout(layoutSize.width, layoutSize.height) {
placeable.placeRelative(
layout(constraints.maxWidth, constraints.maxHeight) {
// Using place() instead of placeRelative() because layoutSize and the value
// returned by horizontalAlignment.align() are RTL-aware
placeable.place(
x = layoutSize.left + horizontalAlignment.align(
size = placeable.width,
space = layoutSize.width,
layoutDirection = LayoutDirection.Ltr, // Ltr because we use placeRelative()
layoutDirection = layoutDirection,
),
y = verticalArrangement.align(
size = placeable.height,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,25 +25,25 @@ public interface RevealScope {
* effect is shown for the element, the effect is finished.
*
* @param key Unique key to identify the revealable content. Also see documentation of [Key].
* @param padding Additional padding around the reveal area. Positive values increase area while
* negative values decrease it. Defaults to 8 dp on all sides.
* @param shape Shape of the reveal effect around the element. Defaults to a rounded rect
* with a corner size of 4 dp.
* @param padding Additional padding around the reveal area. Positive values increase area while
* negative values decrease it. Defaults to 8 dp on all sides.
*
* @see Key
*/
public fun Modifier.revealable(
key: Key,
padding: PaddingValues = PaddingValues(8.dp),
shape: RevealShape = RevealShape.RoundRect(4.dp),
padding: PaddingValues = PaddingValues(8.dp),
): Modifier
}

internal class RevealScopeInstance(
private val revealState: RevealState,
) : RevealScope {

override fun Modifier.revealable(key: Key, padding: PaddingValues, shape: RevealShape): Modifier =
override fun Modifier.revealable(key: Key, shape: RevealShape, padding: PaddingValues): Modifier =
this.then(
Modifier
.onGloballyPositioned { layoutCoordinates ->
Expand Down

0 comments on commit 5872d3b

Please sign in to comment.