Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I disable the horizontal stretching/overscroll when using the `verticalScroll` modifier?

I want a scrollable view which I'm doing by using the verticalScroll modifier on a column.

Column(modifier = Modifier.verticalScroll(rememberScrollState())) { 
    // ... I could provide more detail about the contents here but I don't think it matters.
}

When I start scrolling vertically, the view will allow horizontal over scroll and stretch the view horizontally. This doesn't seem like desirable behavior to me.

Scrolling around in my view

Is there anyway to stop this behavior from happening?

like image 433
B Roy Dawson Avatar asked Oct 23 '25 08:10

B Roy Dawson


1 Answers

You can try disabling the overscroll via CompositionLocal directly scoping the Column

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun MyListWithoutOverScroll() {
    CompositionLocalProvider(
        LocalOverscrollConfiguration provides null
    ) {
        Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
            repeat(100) {
                Text("Hello World $it")
            }
        }
    }
}

or set it in Activity level

@Composable
fun MyList() {
    Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
        repeat(100) {
            Text("Hello World $it")
        }
    }
}


@OptIn(ExperimentalFoundationApi::class)
@AndroidEntryPoint
class MyActivity : ComponentActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        setContent {
            CompositionLocalProvider(
                LocalOverscrollConfiguration provides null
            ) {
                MyList()
            }
        }
    }
}

Without overscroll using CompositionLocalProvider setting it to null (not-stretching)

enter image description here

With overscroll (stretching)

enter image description here

like image 102
z.g.y Avatar answered Oct 25 '25 23:10

z.g.y



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!