'React native - disable scrolling in 1 direction
Is there a way to disable one ScrollView in react native (iOS)?
I mean i need only to pull down to refresh but, I can also pull up. I want to disable the pull up.
<ScrollView
refreshControl={
<RefreshControl
refreshing={this.state.isRefreshing}
onRefresh={this._onRefresh}></RefreshControl>}
style={styles.container} contentContainerStyle={{flex: 1}}>
Solution 1:[1]
I am not aware of any prop in scrollview that would do just that.
One way to do it I can think of is to create a state that keeps track of if you are scrolling up or not. And then calculate which way you are scrolling by doing something like this:
const [scrollDisabled, setScrollDisabled] = useState(false);
let viewPosition = 0;
const disableDownwardScroll = event => {
const currentPosition = event.nativeEvent.contentOffset.y;
const isScrollingDown =
currentPosition > 0 &&
currentPosition > viewPosition
? true
: false;
setScrollDisabled(isScrollingDown);
}
return(
<ScrollView
onScroll={disableDownwardScroll}
disableScrollViewPanResponder={scrollDisabled}>
<Content />
</ScrollView>
);
I have myself never used the prop "disableScrollViewPanResponder" before, but I think it's something along the lines of this is what you need.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Jonathan Manner |