Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Rtl in SplitPane #4265

Merged
merged 4 commits into from
Feb 8, 2024

Conversation

ahmedhosnypro
Copy link
Contributor

This is related to issue: #4258

changes

  • DesktopSplitPane.kt: placable.place() -> placable.placeRelative

  • SplitePaneDSL.kt: change the delta direction to follow the layout direction

 @Composable
    override fun Modifier.markAsHandle(): Modifier = this.run {
        val layoutDirection = LocalLayoutDirection.current
        pointerInput(containerScope.splitPaneState) {
            detectDragGestures { change, _ ->
                change.consume()
                containerScope.splitPaneState.dispatchRawMovement(
                    if (containerScope.isHorizontal)
                        if (layoutDirection == LayoutDirection.Ltr) change.position.x else -change.position.x
                    else change.position.y
                )
            }
        }

the problem with .onPointerEvent() Modifier, or onDrag also, is
whenever the layout direction is Ltr or Rtl:
moving to right always produce positive change, [expected negative if dir =Rtl]
moving to left always produce negative change, [expected positive if dir =Rtl]

the calculation of postion will fail if layoutDir is Rtl, because positionPercentage will be out of range

fun dispatchRawMovement(delta: Float) {
        val movableArea = maxPosition - minPosition
        if (movableArea > 0) {
            positionPercentage =
                ((movableArea * positionPercentage) + delta).coerceIn(0f, movableArea) / movableArea
        }
    }

Copy link
Collaborator

@igordmn igordmn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

ahmedhosnypro and others added 3 commits February 8, 2024 15:16
…ns/compose/splitpane/SplitPaneDSL.kt

Co-authored-by: Igor Demin <[email protected]>
…ns/compose/splitpane/SplitPaneDSL.kt

Co-authored-by: Igor Demin <[email protected]>
@igordmn igordmn merged commit a8e9486 into JetBrains:master Feb 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants