How to use refreshControl on a ScrollView but prevent dragging direction?

Viewed 237

I have content that I want to "refresh" with a RefreshControl but I do not want the content to scroll upwards. I was originally under the impression that setting bounces=false and scrollEnabled=true would achieve this.

1 Answers

How about you set a key to the Component, then update it when you want to refresh it.

When a key changes, React see it as a new component. As a result, it will literally refresh the component.

export default () => {
  const [refreshKey, setRefreshKey] = React.useState('randomstring');

  // call me when refresh required
  const refresh = () => {
    setRefreshKey(refreshKey + 'randomstring');
  };

  return (
    <ScrollView key={refreshKey}>
      {/* Some Awesome Contents */}
    </ScrollView>
  );
};

Related