Search code examples
androidandroid-jetpack-compose

AnchoredDraggable Overscroll Effect


I recently migrated from Swipeable to AnchoredDraggable successfuly, following the official migration guide: https://developer.android.com/develop/ui/compose/touch-input/pointer-input/migrate-swipeable

I am using AnchoredDraggableState to drag between 2 states (Expanded and Collapsed). Everything works fine except overscroll effect, when I drag an item in opposite direction. With Swipeable implementation, overscroll effect was present.

How can I achieve overscroll effect using AnchoredDraggableState and anchoredDraggable modifier?


Solution

  • Compose 1.7.0 added an overscrollEffect parameter to the anchoredDraggable modifier which allows you to provide an OverscrollEffect object.

    Unfortunately, this version is, as of the time of writing, only available as a release candidate (1.7.0-rc01). If you do not want to wait for a stable version you need to update your compose dependencies to this pre-release version. If you use the Compose BOM in your gradle setup you need to either switch to a third-party BOM (because there is no offical BOM for pre-release versions) or revert back to explicitly specifying the appropriate version number for each compose dependency separately.