mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-08-11 12:30:18 +00:00
Merge pull request #18402 from timwangdev/patch-1
[react-native] Fix FlatList/SectionList renderItem method types
This commit is contained in:
Vendored
+31
-8
@@ -4,6 +4,7 @@
|
||||
// Fedor Nezhivoi <https://github.com/gyzerok>
|
||||
// HuHuanming <https://github.com/huhuanming>
|
||||
// Kyle Roach <https://github.com/iRoachie>
|
||||
// Tim Wang <https://github.com/timwangdev>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.3
|
||||
|
||||
@@ -3451,6 +3452,22 @@ export interface ViewabilityConfig {
|
||||
/**
|
||||
* @see https://facebook.github.io/react-native/docs/flatlist.html#props
|
||||
*/
|
||||
|
||||
interface ListRenderItemInfo<ItemT> {
|
||||
|
||||
item: ItemT
|
||||
|
||||
index: number
|
||||
|
||||
separators: {
|
||||
highlight: () => void,
|
||||
unhighlight: () => void,
|
||||
updateProps: (select: 'leading' | 'trailing', newProps: any) => void,
|
||||
},
|
||||
}
|
||||
|
||||
type ListRenderItem<ItemT> = (info: ListRenderItemInfo<ItemT>) => React.ReactElement<any> | null
|
||||
|
||||
export interface FlatListProperties<ItemT> extends ScrollViewProperties {
|
||||
|
||||
/**
|
||||
@@ -3585,7 +3602,7 @@ export interface FlatListProperties<ItemT> extends ScrollViewProperties {
|
||||
* ```
|
||||
* Provides additional metadata like `index` if you need it.
|
||||
*/
|
||||
renderItem: (info: ItemT) => React.ReactElement<any> | null
|
||||
renderItem: ListRenderItem<ItemT>
|
||||
|
||||
/**
|
||||
* See `ViewabilityHelper` for flow type and further documentation.
|
||||
@@ -3643,20 +3660,26 @@ export interface FlatListStatic<ItemT> extends React.ComponentClass<FlatListProp
|
||||
recordInteraction: () => void
|
||||
}
|
||||
|
||||
export interface SectionListData<ItemT> {
|
||||
/**
|
||||
* @see https://facebook.github.io/react-native/docs/sectionlist.html
|
||||
*/
|
||||
export interface SectionBase<ItemT> {
|
||||
|
||||
data: ItemT[]
|
||||
|
||||
key: string
|
||||
key?: string
|
||||
|
||||
renderItem?: (info: {item: ItemT, index: number}) => React.ReactElement<any> | null
|
||||
renderItem?: ListRenderItem<ItemT>
|
||||
|
||||
ItemSeparatorComponent?: React.ComponentClass<any> | null
|
||||
|
||||
keyExtractor?: (item: ItemT, index: number) => string
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://facebook.github.io/react-native/docs/sectionlist.html
|
||||
*/
|
||||
export interface SectionListData<ItemT> extends SectionBase<ItemT> {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
export interface SectionListProperties<ItemT> extends ScrollViewProperties {
|
||||
|
||||
/**
|
||||
@@ -3712,7 +3735,7 @@ export interface SectionListProperties<ItemT> extends ScrollViewProperties {
|
||||
/**
|
||||
* 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
|
||||
renderItem?: ListRenderItem<ItemT>
|
||||
|
||||
/**
|
||||
* Rendered at the top of each section. Sticky headers are not yet supported.
|
||||
|
||||
@@ -31,7 +31,9 @@ import {
|
||||
ViewStyle,
|
||||
ViewPagerAndroid,
|
||||
FlatList,
|
||||
FlatListProperties,
|
||||
SectionList,
|
||||
SectionListProperties,
|
||||
findNodeHandle,
|
||||
ScrollView,
|
||||
ScrollViewProps,
|
||||
@@ -205,29 +207,35 @@ InteractionManager.runAfterInteractions(() => {
|
||||
// ...
|
||||
}).then(() => 'done')
|
||||
|
||||
export class FlatListTest {
|
||||
export class FlatListTest extends React.Component<FlatListProperties<number>, {}> {
|
||||
render() {
|
||||
<FlatList
|
||||
data={[1, 2, 3, 4, 5]}
|
||||
renderItem={(itemInfo: number) => <View><Text>{itemInfo}</Text></View>}
|
||||
/>
|
||||
return (
|
||||
<FlatList
|
||||
data={[1, 2, 3, 4, 5]}
|
||||
renderItem={(info: { item: number }) => <View><Text>{info.item}</Text></View>}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export class SectionListTest {
|
||||
export class SectionListTest extends React.Component<SectionListProperties<string>, {}> {
|
||||
render() {
|
||||
var sections = [{
|
||||
key: 's1',
|
||||
data: ['A', 'B', 'C', 'D', 'E']
|
||||
title: 'Section 1',
|
||||
data: ['A', 'B', 'C', 'D', 'E'],
|
||||
}, {
|
||||
key: 's2',
|
||||
data: ['A2', 'B2', 'C2', 'D2', 'E2']
|
||||
title: 'Section 2',
|
||||
data: ['A2', 'B2', 'C2', 'D2', 'E2'],
|
||||
renderItem: (info: { item: string }) => <View><Text>{info.item}</Text></View>
|
||||
}];
|
||||
|
||||
<SectionList
|
||||
sections={sections}
|
||||
renderItem={(info: {item: string, index: number}) => <View><Text>{info.item}</Text></View>}
|
||||
/>
|
||||
return (
|
||||
<SectionList
|
||||
sections={sections}
|
||||
renderSectionHeader={({section}) => <View><Text>{section.title}</Text></View>}
|
||||
renderItem={(info: { item: string }) => <View><Text>{info.item}</Text></View>}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user