Was just pleasantly surprised to see that `Modifie...
# compose-desktop
a
Was just pleasantly surprised to see that
Modifier.scroll
seems to automatically keep the focused element in view. Very nice.
😮 2
z
Sometimes 😜 we're still working on some ā€œedgeā€ cases
šŸ™‚ 1
šŸ‘šŸ» 1
a
Is there a way to ask for it to scroll a bit more than the necessary minimum such that element is not only visible, but slightly more ā€œinsideā€ the scrollable container? I could give it extra padding, but that would affect the layout, which I don’t want.
z
You could use your own
BringIntoViewRequester
and make the request on focus with a larger rect than the size of the field. I haven’t tried that but i think it should work
a
Is
BringIntoViewResponder
not in compose-desktop yet? It seems like the better way to go is to implement
BringIntoViewResponder.calculateRectForParent
to return a slightly larger rect.
Hmm, I see
BringIntoViewResponder
but not
Modifier.bringIntoViewResponder
Also, my own
BringIntoViewRequester
doesn’t work, because the ā€œbuilt-inā€ mechanism calls
scrollableState.animateScrollBy
immediately after my
BringIntoViewRequester
does so, which overrides my scroll request.
It does work if I put
delay(1)
before calling
bringIntoViewRequester.bringIntoView
z
Does your requested rectangle include the whole field? Overlapping concurrent requests should be merged
a
It does:
Copy code
.onGloballyPositioned {
    layoutCoords = it
 }
.bringIntoViewRequester(bringIntoViewRequester)
.onFocusChanged {
    if (it.isFocused) {
        layoutCoords?.size?.let { size ->
            coroutineScope.launch {
                delay(1)
                val rect = size.toSize().toRect()
                val targetRect = rect.copy(top = <http://rect.top|rect.top> - 20, bottom = rect.bottom + 20)
                bringIntoViewRequester.bringIntoView(targetRect)
            }
        }
    }
}
I don’t see them being merged. I just put a breakpoint in
BringIntoViewResponder.performBringIntoView
and it’s called twice - once from my call (with the correct rect) and once from somewhere else (with the default rect).
and since all it does is call
Copy code
scrollableState.animateScrollBy(offset.reverseIfNeeded())
it’s not surprising that the 2nd call ā€œcancelsā€ the first call.
z
No, the merging happens somewhere else. What version of compose is this?
a
Copy code
id("org.jetbrains.compose") version "1.1.1"
z
Oh yea, all of these fixes are only in 1.2