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

EditText/BAsicEditText scroll support broken #1575

Closed
sergeych opened this issue Dec 12, 2021 · 8 comments · Fixed by JetBrains/compose-multiplatform-core#384
Closed

EditText/BAsicEditText scroll support broken #1575

sergeych opened this issue Dec 12, 2021 · 8 comments · Fixed by JetBrains/compose-multiplatform-core#384
Assignees
Labels
desktop enhancement New feature or request p:high High priority scroll text

Comments

@sergeych
Copy link

Impossible to correcly connect vertical scrollbar to EditText or BasicEditText. If the scllbar is connected, then when caret goes below the visible part of the text it just disspears. It is expected that the text editor automatically scrolls as the caret moves.

If the line makred below as (1) is commented out, the eritor properly scrolls to make caret always visible, but the scrollbar is no more connected and does not function.

    var text by remember { mutableStateOf(TextFieldValue("some multiline text")) }
    val ss = rememberScrollState()

    Column(
        modifier = Modifier.fillMaxSize().background(Color.White)
    ) {
        Box(Modifier.weight(1f).padding(4.dp).fillMaxWidth()) {
            BasicTextField(
                text, { text = it },
                Modifier.fillMaxSize()
                    .verticalScroll(ss) // (1) with this like cursor goes off screen, with it no scrollbar is dsiplayed
                    .padding(0.dp)
                    .focusRequester(fr),
                textStyle = TextStyle(fontFamily = FontFamily.Monospace, fontSize = 1.em)
            )
            VerticalScrollbar(
                rememberScrollbarAdapter(ss), Modifier.align(Alignment.CenterEnd),
                style = defaultScrollbarStyle().copy(hoverDurationMillis = 700)
            )
        }
   }

project settings:

    kotlin("jvm") version "1.5.31"
    id("org.jetbrains.compose") version "1.0.0"
@akurasov akurasov self-assigned this Dec 13, 2021
@akurasov akurasov added desktop bug Something isn't working labels Dec 13, 2021
@akurasov akurasov added this to the 1.1 milestone Dec 13, 2021
@akurasov akurasov added the p:high High priority label Dec 13, 2021
@akurasov akurasov removed their assignment Feb 10, 2022
@akurasov akurasov removed this from the 1.1 milestone Feb 15, 2022
@NeroSong
Copy link

NeroSong commented Sep 5, 2022

meet it too.
after a TextField combined with VerticalScrollbar, it will lose auto-scroll when cursor move out of view.

@radicaled
Copy link

Does anyone have a workaround for this? I've hacked for a few hours but it seems like the only real solution is to modify the source code directly, which I'd like to avoid.

@sergeych
Copy link
Author

as of 1.2.2 it is still here. A year ago a critical bug has been reported. Looks like the platform is about to be abandoned. I suppose they have fired their Russian dev team just then and hardly could ever substitute it ;)

@radicaled did you find any idea how to fix it? I'm really disappointed as our plans were to use the platform, we switched to kotlin for a reason, and it seems to be dying and self-cancelling...

@sergeych
Copy link
Author

I've created test project to show it and probably create a workaround: https://github.com/sergeych/EditScrollBarBug

@radicaled
Copy link

@radicaled did you find any idea how to fix it?

Afraid not.

This issue + some others in the repository + discovering that Fleet not using Compose for Desktop has kind of shaken my confidence in using Compose Multiplatform as a solution for desktop applications, so I don't think I'll be expending much more effort in this direction.

@sergeych
Copy link
Author

sergeych commented Jan 23, 2023 via email

@m-sasha m-sasha self-assigned this Jan 23, 2023
@igordmn
Copy link
Collaborator

igordmn commented Jan 23, 2023

It is not correct to add verticalScroll to TextField, because TextField is already scrollable by itself. The correct way is impossible right now (at least with simple code).

We need to extend BasicTextField, adding ability to manipulate its internal scroll state. It will look something like this after we add that:

val ss = rememberScrollState()
BasicTextField(
    text, { text = it },
    scrollState = ss
)

VerticalScrollbar(
    rememberScrollbarAdapter(ss), Modifier.align(Alignment.CenterEnd),
    style = defaultScrollbarStyle().copy(hoverDurationMillis = 700)
)

It is a design flaw, not a bug. But nevertheless it isn't nice that Compose Multiplatform still does not have this ability.

@m-sasha
Copy link
Contributor

m-sasha commented Jan 26, 2023

The new (experimental) API can be used like this (once released):

Box(...){
    val scrollState = rememberTextFieldVerticalScrollState()

    BasicTextField(
       text = ...,
       onValueChange = ...,
       scrollState = scrollState
    )

    VerticalScrollbar(
        adapter = rememberScrollbarAdapter(scrollState),
        modifier = ...
    )
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop enhancement New feature or request p:high High priority scroll text
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants