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

CompositionLocals given in application scope are not take into account in window scope (such as LocalLayoutDirection) #3571

Closed
mahozad opened this issue Aug 26, 2023 · 4 comments
Assignees
Labels
bug Something isn't working desktop

Comments

@mahozad
Copy link
Contributor

mahozad commented Aug 26, 2023

Describe the bug
All Arrangement.Absolute.spacedBy() overloads refer to Arrangement.spacedBy() in their documentation for the direction-aware alternative.

But the Arrangement.spacedBy() does not honor RTL layout direction.

Affected platforms

  • Desktop
  • and probably others

Versions

  • Kotlin version*: 1.9.0
  • Compose Multiplatform version*: 1.5.0-rc01
  • OS version(s)*: Windows 10, Windows 11
  • OS architecture (x86 or arm64): x64
  • JDK (for desktop issues): Oracle JDK 17.0.7

To Reproduce

// ...
import androidx.compose.foundation.layout.Arrangement.spacedBy

fun main() {
    application {
        CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
            Window(onCloseRequest = ::exitApplication) {
                Row(horizontalArrangement = spacedBy(24.dp)) {
                    Box(modifier = Modifier.size(64.dp).background(Color.Red))
                    Box(modifier = Modifier.size(64.dp).background(Color.Green))
                }
            }
        }
    }
}

Expected behavior
When layout direction is RTL, the components should be placed in reverse order (green box should be on the left).

Untitled

@mahozad mahozad added bug Something isn't working submitted labels Aug 26, 2023
@mahozad mahozad changed the title Bug with layout direction when using HorizontalArrangement.spacedBy in a Row Bug with layout direction when using Arrangement.spacedBy in a Row Aug 26, 2023
@mahozad
Copy link
Contributor Author

mahozad commented Aug 26, 2023

When I moved CompositionLocalProvider into Window content, it works correctly:

fun main() {
    application {
        Window(onCloseRequest = ::exitApplication) {
            CompositionLocalProvider(LocalLayoutDirection provides LayoutDirection.Rtl) {
                Row(horizontalArrangement = spacedBy(24.dp)) {
                    Box(modifier = Modifier.size(64.dp).background(Color.Red))
                    Box(modifier = Modifier.size(64.dp).background(Color.Green))
                }
            }
        }
    }
}

So, it should be the same problem as this:

@Walingar
Copy link
Collaborator

Hello @mahozad, thank you for submitting the issue.
This is related to this issue: #3289. See the comment

For now we provide CompositionLocals in Window scope and given LayoutDirection is overriden by default values

@Walingar Walingar changed the title Bug with layout direction when using Arrangement.spacedBy in a Row CompositionLocals given in application scope are not takein into account in window scope (such as LocalLayoutDirection) Aug 28, 2023
@Walingar Walingar changed the title CompositionLocals given in application scope are not takein into account in window scope (such as LocalLayoutDirection) CompositionLocals given in application scope are not take into account in window scope (such as LocalLayoutDirection) Aug 28, 2023
@Walingar Walingar added the discussion Need further discussion to understand if it actually needed label Aug 28, 2023
@mahozad
Copy link
Contributor Author

mahozad commented Aug 28, 2023

Thanks for the relevant information.

@m-sasha m-sasha self-assigned this Aug 29, 2023
@m-sasha m-sasha removed the discussion Need further discussion to understand if it actually needed label Aug 29, 2023
@m-sasha
Copy link
Contributor

m-sasha commented Aug 31, 2023

Fixed by JetBrains/compose-multiplatform-core#777

@m-sasha m-sasha closed this as completed Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working desktop
Projects
None yet
Development

No branches or pull requests

3 participants