admin管理员组文章数量:1221823
I'm working on a multi-modal chat application where users send text requests, and the chatbot responds with text, images, and thumbnails. One of the requirements is to send context information about what is currently visible on the screen to the backend, including the bounds of visible elements.
Requirements for Bounds Calculation
The bounds should be in density-independent pixels (dp).
The coordinate system originates at the top-left corner of the chat window.
If an element is partially visible, its bounds should be clipped to only the visible portion.
The reported bounds should be an axis-aligned rectangle enclosing the visible part of the element.
Composable Hierarchy
ChatScreenComposable
├── UIFragmentsComposable
│ ├── RequestFragmentsComposable (User request)
│ ├── ResponseFragmentsComposable (Bot responses)
│ ├── ChildFragmentsComposable (Bot images, thumbnails, etc.)
- A root fragment represents a user request.
- A response fragment contains one or more bot responses (text). A root fragment can contain multiple responses.
- A child fragment contains response images, thumbnails, etc. A response fragment can contain multiple child(ren) fragments.
Current Approach (Using onGloballyPositioned)
Currently, I use Modifier.onGloballyPositioned
on:
- Request fragments
- Response fragments
- Child fragments (inside response fragments)
I store these bounds in a map and use them later when generating the JSON payload to send to the backend.
Problem
A reviewer pointed out that onGloballyPositioned
has previously caused lag in scrolling performance.
What I've Tried
onPlaced
: Considered, but it also has performance concerns.LazyListState
: It provides visibility info for root fragments but does not track nested fragments (child elements inside responses).onSizeChanged
: Tracks size efficiently but does not provide position.
Question
What are better-performing alternatives to track visible bounds of nested elements in Jetpack Compose, without using onGloballyPositioned
?
Any insights on efficient ways to track position and size while avoiding expensive recompositions would be appreciated.
本文标签:
版权声明:本文标题:Efficiently track bounds of fragments of composables on the screen in android without onGloballyPositioned - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1739352115a2159435.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论