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

Cursor position is displayed on the left edge when textAlign is set to center in BasicTextField #4611

Open
y-sugitani opened this issue Apr 13, 2024 · 1 comment
Assignees
Labels
bug Something isn't working text

Comments

@y-sugitani
Copy link

y-sugitani commented Apr 13, 2024

Describe the bug
When setting textAlign to TextAlign.Center in BasicTextField (and TextField) on iOS, the cursor position is displayed on the left edge when focused. On Android, it is displayed in the center as expected.

Affected platforms

  • iOS

Versions

  • Kotlin version: 1.9.23
  • Compose Multiplatform version: 1.6.2
  • OS version(s): iOS 17.4
  • Device: iPhone 15 Pro Simulator

To Reproduce

  1. Create a new Compose Multiplatform project
  2. Add the following code:
@Composable
@Preview
fun App() {
    var text by remember { mutableStateOf("") }

    MaterialTheme {
        BasicTextField(
            value = text,
            onValueChange = { text = it },
            modifier = Modifier
                .fillMaxWidth()
                .background(Color.LightGray)
                .padding(18.dp),
            maxLines = Int.MAX_VALUE,
            textStyle = TextStyle.Default.copy(
                textAlign = TextAlign.Center,
            ),
        )
    }
}
  1. Run the app on an iOS Simulator
  2. Tap the BasicTextField to focus it
  3. The cursor is displayed on the left edge

Expected behavior
Since textAlign in BasicTextField is set to TextAlign.Center, the cursor should be displayed in the center of the text field on iOS, just like on Android.

Screenshots

Android
https://github.com/JetBrains/compose-multiplatform/assets/32157797/a968c4a8-57a9-4962-8170-a5d4f115a6af

iOS
https://github.com/JetBrains/compose-multiplatform/assets/32157797/27ef6fd2-bb40-4714-99b9-3b6c510301d9

Additional context
The same behavior was observed when using TextField. Regardless of the textAlign value, the cursor is always displayed on the left edge on iOS.

A reproducible project is available at https://github.com/blackcat-carnival/compose-bugreport-202404-01

@y-sugitani y-sugitani added bug Something isn't working submitted labels Apr 13, 2024
@terrakok terrakok added text and removed submitted labels Apr 16, 2024
@terrakok
Copy link
Collaborator

I reproduced it on a JVM as well
CursorIssue-all.zip

@igordmn igordmn changed the title Cursor position is displayed on the left edge when textAlign is set to center in BasicTextField on iOS Cursor position is displayed on the left edge when textAlign is set to center in BasicTextField May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working text
Projects
None yet
Development

No branches or pull requests

3 participants