Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@jokester
Last active May 27, 2018 07:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jokester/58cfb129b6b29ae2103aa30073585f65 to your computer and use it in GitHub Desktop.
Save jokester/58cfb129b6b29ae2103aa30073585f65 to your computer and use it in GitHub Desktop.
add RefreshControl to FlatList / SectionList in a simpler way
import * as React from 'react';
import { FlatList, FlatListProps, ScrollView, SectionList, SectionListProps } from 'react-native';
import { Debug } from "../../../util";
export function FlatListWithRefreshControl(props: FlatListProps<any>) {
const { refreshControl, renderScrollComponent: providedComponent, ...rest } = props;
Debug.assert(refreshControl && !providedComponent, 'only use this when you need to fix refreshControl');
const renderScrollComponent = (props: {}) => <ScrollView refreshControl={refreshControl} {...props} />;
return (
<FlatList
renderScrollComponent={renderScrollComponent}
{...rest}
/>
);
}
export function SectionListWithRefreshControl(props: SectionListProps<any>) {
const { refreshControl, renderScrollComponent: providedComponent, ...rest } = props;
Debug.assert(refreshControl && !providedComponent, 'only use this when you need to fix refreshControl');
const renderScrollComponent = (props: {}) => <ScrollView refreshControl={refreshControl} {...props} />;
return (
<SectionList
renderScrollComponent={renderScrollComponent}
{...props}
/>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment