New Compose Multiplatform components arrived on Composables UICheck it out →

Modifier in Compose Foundation

bringIntoViewResponder

Common

A parent that can respond to [BringIntoViewRequester] requests from its children, and scroll so that the item is visible on screen. See [BringIntoViewResponder] for more details about how this mechanism works.

Last updated:

Installation

dependencies {
   implementation("androidx.compose.foundation:foundation:1.7.0-beta04")
}

Overloads

@ExperimentalFoundationApi
@Suppress("ModifierInspectorInfo"
fun Modifier.bringIntoViewResponder(
    responder: BringIntoViewResponder
)

Code Example

BringIntoViewSample

@Composable
@Sampled
@OptIn(ExperimentalFoundationApi::class
fun BringIntoViewSample() {
    Row(Modifier.horizontalScroll(rememberScrollState())) {
        repeat(100) {
            val bringIntoViewRequester = remember { BringIntoViewRequester() }
            val coroutineScope = rememberCoroutineScope()
            Box(
                Modifier
                    // This associates the RelocationRequester with a Composable that wants to be
                    // brought into view.
                    .bringIntoViewRequester(bringIntoViewRequester)
                    .onFocusChanged {
                        if (it.isFocused) {
                            coroutineScope.launch {
                                // This sends a request to all parents that asks them to scroll so
                                // that this item is brought into view.
                                bringIntoViewRequester.bringIntoView()
                            }
                        }
                    }
                    .focusTarget()
            )
        }
    }
}