Type definition for SectionList

This commit is contained in:
Andrew Goodale
2017-04-20 09:58:42 -04:00
parent 6c68ba6447
commit ca056c85c5
2 changed files with 100 additions and 0 deletions
+82
View File
@@ -3615,6 +3615,85 @@ export interface FlatListStatic<ItemT> extends React.ComponentClass<FlatListProp
recordInteraction: () => void
}
export interface SectionListData<ItemT> {
data: ItemT[]
key: string
renderItem?: (info: {item: ItemT, index: number}) => React.ReactElement<any> | null
keyExtractor?: (item: ItemT, index: number) => string
}
/**
* @see https://facebook.github.io/react-native/docs/sectionlist.html
*/
export interface SectionListProperties<ItemT> extends ScrollViewProperties {
/**
* An array of objects with data for each section.
*/
sections: SectionListData<ItemT>[]
/**
* Used to extract a unique key for a given item at the specified index. Key is used for caching
* and as the react key to track item re-ordering. The default extractor checks `item.key`, then
* falls back to using the index, like React does.
*/
keyExtractor?: (item: ItemT, index: number) => string
/**
* Default renderer for every item in every section. Can be over-ridden on a per-section basis.
*/
renderItem?: (info: {item: ItemT, index: number}) => React.ReactElement<any> | null
/**
* Rendered at the top of each section. Sticky headers are not yet supported.
*/
renderSectionHeader?: (info: {section: SectionListData<ItemT>}) => React.ReactElement<any> | null
/**
* Rendered in between each item, but not at the top or bottom
*/
ItemSeparatorComponent?: React.ComponentClass<any> | null
/**
* Rendered at the bottom of all the items.
*/
ListFooterComponent?: React.ComponentClass<any> | null
/**
* Rendered at the top of all the items.
*/
ListHeaderComponent?: React.ComponentClass<any> | null
/**
* Rendered in between each section.
*/
SectionSeparatorComponent?: React.ComponentClass<any> | null
/**
* If provided, a standard RefreshControl will be added for "Pull to Refresh" functionality.
* Make sure to also set the refreshing prop correctly.
*/
onRefresh?: (() => void) | null
/**
* Set this true while waiting for new data from a refresh.
*/
refreshing?: boolean | null
/**
* Render a custom scroll component, e.g. with a differently styled `RefreshControl`.
*/
renderScrollComponent?: (props: ScrollViewProperties) => React.ReactElement<ScrollViewProperties>
}
export interface SectionListStatic<SectionT> extends React.ComponentClass<SectionListProperties<SectionT>> {
}
/**
* @see https://facebook.github.io/react-native/docs/listview.html#props
*/
@@ -8467,6 +8546,9 @@ export type StatusBar = StatusBarStatic
export var ScrollView: ScrollViewStatic
export type ScrollView = ScrollViewStatic
export var SectionList: SectionListStatic<any>
export type SectionList<ItemT> = SectionListStatic<ItemT>
export var SnapshotViewIOS: SnapshotViewIOSStatic
export type SnapshotViewIOS = SnapshotViewIOSStatic
+18
View File
@@ -26,6 +26,7 @@ import {
ViewStyle,
ViewPagerAndroid,
FlatList,
SectionList,
findNodeHandle
} from 'react-native';
@@ -201,3 +202,20 @@ export class FlatListTest {
/>
}
}
export class SectionListTest {
render() {
var sections = [{
key: 's1',
data: ['A', 'B', 'C', 'D', 'E']
},{
key: 's2',
data: ['A2', 'B2', 'C2', 'D2', 'E2']
}];
<SectionList
sections={sections}
renderItem={(info: {item: string, index: number}) => <View><Text>{info.item}</Text></View>}
/>
}
}