Whenever I click to edit the BasicFieldText, the p...
# compose-desktop
n
Whenever I click to edit the BasicFieldText, the parent view (the 2D canvas that holds items) is calling the
scrollable
events. The parent scrolling events stop when I manually scroll the wheel when inside the element. After investigation I understood that this is because the child item has
Modifier.verticalScroll(rememberScrollState)
but I don't really want for that to pass the events to the parent. Can someone point out how to disable parent scrolling when child scroll is working? Thanks!
a
Can you post a short reproducer?
n
Will do tomorrow!
Here is the gist: https://gist.github.com/NuruNabiyev/8e1f94433a86533362e0e0b32496ec13 Add it in your main application and you will be able to see - also added comments/logs. Thanks for your time!
a
Try remembering the ScrollableState
n
Tried it, doesn't help - canvas scroll events still trigger when I scroll in child
a
Just to clarify what you're after. You want scrolling inside the textfield not to cause scrolling of its parent when it reaches 0 or max?
n
Yes
a
You can put another verticalScroll above it and always consume all the delta.
n
Above what?
a
Between the textfield and your grid widget
n
Still unclear. Can you indicate which line in the gist? And by "another verticalScroll" you mean additional
Copy code
.verticalScroll(rememberScrollState(0))
?
a
Copy code
.scrollable(
    orientation = Orientation.Vertical,
    state = remember { ScrollableState { it } }
)                   .verticalScroll(stateVertical)
on the Column holding the text field.
n
Thus works, thanks! Now there is another problem where when clicking on text (to make it editable) the scroll is again executed. Apparently because of the if else statement where if editable then I'll show basic edit text instead of of plain text.../
Nah, even when I remove if statement and have only "BasicTextField" then it still scrolls when I click on text
Yes, apparently when starting a cursor in basic text field - a scroll event is happening even in parent
I digged into library - it is due to focus. Apparently on focus the scroll function is called from CoreTextField.kt and TextFieldScroll.kt libs
a
It looks like it tries to bring the cursor into view, although it's already in view. It's possibly a bug, but also you're using scroll on textfield incorrectly. (Basic)TextField is already scrollable by itself; you should not add
verticalScroll
to it. The right way to do it is:
Copy code
val scrollState = rememberTextFieldScrollState(orientation = Orientation.Vertical)
BasicTextField(
    value = content.value,
    onValueChange = { content.value = it },
    scrollState = scrollState
)
VerticalScrollbar(
    rememberScrollbarAdapter(scrollState)
)