Last active
May 27, 2018 07:33
-
-
Save jokester/58cfb129b6b29ae2103aa30073585f65 to your computer and use it in GitHub Desktop.
add RefreshControl to FlatList / SectionList in a simpler way
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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