diff --git a/README.md b/README.md index 015dac6..31bbbaf 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,30 @@ Shadowlist doesn't support state updates or dynamic prop calculations inside the ```js import {Shadowlist} from 'shadowlist'; +const stringify = (str: string) => `{{${str}}}`; + +type ElementProps = { + data: Array; +}; + +const Element = (props: ElementProps) => { + const handlePress = (event: GestureResponderEvent) => { + const elementDataIndex = __NATIVE_getRegistryElementMapping( + event.nativeEvent.target + ); + props.data[elementDataIndex]; + }; + + return ( + + + {stringify('id')} + {stringify('text')} + index: {stringify('position')} + + ); +}; + item.id} onVisibleChange={onVisibleChange} onStartReached={onStartReached} diff --git a/src/SLContainer.tsx b/src/SLContainer.tsx index fd66a4e..5965b00 100644 --- a/src/SLContainer.tsx +++ b/src/SLContainer.tsx @@ -11,8 +11,13 @@ import SLContainerNativeComponent, { // @ts-ignore // import ReactNativeInterface from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface'; +export type ItemProp = { + id: string; + [key: string]: any; +}; + export type SLContainerWrapperProps = { - data: Array; + data: Array; }; export type SLContainerInstance = InstanceType< diff --git a/src/Shadowlist.tsx b/src/Shadowlist.tsx index 8353621..fc78e0d 100644 --- a/src/Shadowlist.tsx +++ b/src/Shadowlist.tsx @@ -2,6 +2,7 @@ import React, { type Ref } from 'react'; import { type ViewStyle } from 'react-native'; import { SLContainer } from './SLContainer'; import { SLElement } from './SLElement'; +import type { ItemProp } from './SLContainer'; import type { SLContainerNativeCommands, SLContainerNativeProps, @@ -19,9 +20,9 @@ const invoker = (Component: Component) => { }; export type ShadowlistProps = { - data: Array; + data: Array; renderItem: () => React.ReactElement; - keyExtractor: (item: any, index: number) => string; + keyExtractor: (item: ItemProp, index: number) => string; contentContainerStyle?: ViewStyle; ListHeaderComponent?: Component; ListHeaderComponentStyle?: ViewStyle;