25

I am using version 1.1.0-alpha05 of Jetpack Compose and I wanted to know if there is a way to turn off the scrolling effect for LazyColumn like xml (android:overScrollMode="never")?

enter image description here

Jonik
  • 80,077
  • 70
  • 264
  • 372
Ghasem
  • 467
  • 5
  • 8

2 Answers2

46

You can disable it by providing LocalOverscrollConfiguration:

CompositionLocalProvider(
    LocalOverscrollConfiguration provides null
) {
    LazyColumn(Modifier.fillMaxWidth()) {
        items(1000) {
            Text(it.toString())
        }
    }
}

You can also build it into your theme so that it applies to the entire application:

@Composable
fun AppTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    content: @Composable () -> Unit
) {
    val colors = if (darkTheme) {
        DarkThemeColors
    } else {
        LightThemeColors
    }
    MaterialTheme(
        colors = colors,
        typography = typography,
        shapes = shapes,
    ) {
        CompositionLocalProvider(
            LocalOverscrollConfiguration provides null,
            content = content
        )
    }
}

p.s. in 1.2.0-rc01 LocalOverScrollConfiguration has being renamed to LocalOverscrollConfiguration

Phil Dukhov
  • 67,741
  • 15
  • 184
  • 220
  • Is there a way, to create custom overscroll animation something like https://stackoverflow.com/questions/40758635/ios-like-over-scroll-effect-on-android ? – slaviboy Mar 14 '22 at 13:35
  • @slaviboy https://stackoverflow.com/a/70632616/3585796 – Phil Dukhov Mar 15 '22 at 04:37
  • @slaviboy Here is the compose way of customising overscrolleffect. https://developer.android.com/reference/kotlin/androidx/compose/foundation/OverscrollEffect – Zakir Sheikh Dec 12 '22 at 05:55
  • is there any way to add that scroll animation if we have minimum content in the screen because the lazy column won't animate if we have minimum data on the screen @PhilDukhov – Tippu Fisal Sheriff Jun 21 '23 at 06:01
0

For people who have nested LazyColumns:

To remove the unsightly overscroll effect that appears around the nested content, don't forget to set userScrollEnabled = false on it.

Tom
  • 6,946
  • 2
  • 47
  • 63
  • Is there any way to add that scroll animation if we have minimum content on the screen the lazy column won't animate if we have minimum data on the screen – Tippu Fisal Sheriff Jun 21 '23 at 06:02
  • That's probably its own question - try making a new SO question and filling out with all the details you can muster – Tom Jun 22 '23 at 20:24