How do you disable inertia scrolling using React Native ScrollView, so that whatever force you apply, it will be next element that the list is going to be scrolled to (and snapped to)? I have reviewed the list of props and any of them does directly what I would like to achieve.
Now, whenever we want to scroll to a specific location we can use scrollTo which is a property of ScrollView. In this, we have to pass the X and Y location to scroll and animated (True/False).
Hence, to make a scrollable list of data, you also need to put the View component inside the ScrollView component. Note: ScrollView must have a parent with a defined height. The ScrollView is a generic React Native scrolling container that allows both vertical and horizontal direction scrolling.
In the ScrollView, we can scroll the components in both direction vertically and horizontally. By default, the ScrollView container scrolls its components and views in vertical. To scroll its components in horizontal, it uses the props horizontal: true (default, horizontal: false).
Use disableIntervalMomentum={ true }
in your ScrollView
. This will only allow the user to scroll one page at a time horizontally.
https://reactnative.dev/docs/scrollview#disableintervalmomentum
<ScrollView
horizontal
disableIntervalMomentum={ true }
snapToInterval={ width }
>
<Child 1 />
<Child 2 />
</ScrollView>
Assuming that you want to snap
to an item horizontally or vertically, its position needs to be fixed relative to the screen (where it should snap)
Since the props are available for IOS only therefore
You can use
decelerationRate
- Set the de accelaration rate to 0
, once the user lifts the fingersnapToAlignment
- Set the alignmnet to a particular element to centersnapToInterval
- Set the interval to snap to based on your contentInset
props.
<ScrollView
horizontal
decelerationRate={0}
snapToInterval={width - (YOUR_INSET_LEFT + YOUR_INSET_RIGHT)}
snapToAlignment={"center"}
contentInset={{top: 0, left: YOUR_INSET_LEFT, bottom: 0, right: YOUR_INSET_RIGHT,
}}>
<Comp/>
<Comp/>
<Comp/>
<Comp/>
</ScrollView>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With