From 23cd82bb15b5d7d193761e8e8a782a057e493216 Mon Sep 17 00:00:00 2001 From: JonatanSalas Date: Mon, 26 Oct 2020 20:33:32 -0300 Subject: [PATCH] fix: fix to get story preview item props via callback --- src/components/StoryPreview/index.tsx | 41 ++++++++++++++++----------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/components/StoryPreview/index.tsx b/src/components/StoryPreview/index.tsx index 3973dd8..7f7a56b 100644 --- a/src/components/StoryPreview/index.tsx +++ b/src/components/StoryPreview/index.tsx @@ -36,9 +36,12 @@ export type StoryPreviewProps = { */ style?: ViewStyle; /** - * Props for Story Preview Item component + * Get Props for Story Preview Item component based on Story and Index */ - StoryPreviewItemProps?: StoryPreviewItemProps; + getStoryPreviewItemProps?: ( + story: Story, + idx: number + ) => StoryPreviewItemProps | any; /** * Callback fired when drag to next item */ @@ -68,12 +71,12 @@ export type StoryPreviewProps = { export const StoryPreview: React.FC = ({ style, stories, - StoryPreviewItemProps, StoryDetailItemHeader, StoryDetailItemFooter, onStoryDetailItemNext, onStoryDetailBackPress, onStoryPreviewItemPress, + getStoryPreviewItemProps, }) => { const [isVisible, setIsVisible] = useState(false); const [index, setIndex] = useState(null); @@ -91,20 +94,25 @@ export const StoryPreview: React.FC = ({ showsHorizontalScrollIndicator={false} keyExtractor={(story) => `${story.id}`} contentContainerStyle={[styles.container, style]} - renderItem={({ item: story, index: idx }) => ( - { - setIsVisible(true); - setIndex(idx); + renderItem={({ item: story, index: idx }) => { + const StoryPreviewItemProps = + getStoryPreviewItemProps && getStoryPreviewItemProps(story, idx); - if (onStoryPreviewItemPress) { - onStoryPreviewItemPress(story, idx); - } - }} - /> - )} + return ( + { + setIsVisible(true); + setIndex(idx); + + if (onStoryPreviewItemPress) { + onStoryPreviewItemPress(story, idx); + } + }} + /> + ); + }} /> = ({ StoryPreview.displayName = 'StoryPreview'; StoryPreview.defaultProps = { + getStoryPreviewItemProps: () => {}, stories: [], };