Skip to content

Commit

Permalink
fix: fix to get story preview item props via callback
Browse files Browse the repository at this point in the history
  • Loading branch information
JonatanSalas committed Oct 26, 2020
1 parent 89a1016 commit 23cd82b
Showing 1 changed file with 25 additions and 16 deletions.
41 changes: 25 additions & 16 deletions src/components/StoryPreview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -68,12 +71,12 @@ export type StoryPreviewProps = {
export const StoryPreview: React.FC<StoryPreviewProps> = ({
style,
stories,
StoryPreviewItemProps,
StoryDetailItemHeader,
StoryDetailItemFooter,
onStoryDetailItemNext,
onStoryDetailBackPress,
onStoryPreviewItemPress,
getStoryPreviewItemProps,
}) => {
const [isVisible, setIsVisible] = useState<boolean>(false);
const [index, setIndex] = useState<any>(null);
Expand All @@ -91,20 +94,25 @@ export const StoryPreview: React.FC<StoryPreviewProps> = ({
showsHorizontalScrollIndicator={false}
keyExtractor={(story) => `${story.id}`}
contentContainerStyle={[styles.container, style]}
renderItem={({ item: story, index: idx }) => (
<StoryPreviewItem
{...StoryPreviewItemProps}
{...story}
onPress={() => {
setIsVisible(true);
setIndex(idx);
renderItem={({ item: story, index: idx }) => {
const StoryPreviewItemProps =
getStoryPreviewItemProps && getStoryPreviewItemProps(story, idx);

if (onStoryPreviewItemPress) {
onStoryPreviewItemPress(story, idx);
}
}}
/>
)}
return (
<StoryPreviewItem
{...StoryPreviewItemProps}
{...story}
onPress={() => {
setIsVisible(true);
setIndex(idx);

if (onStoryPreviewItemPress) {
onStoryPreviewItemPress(story, idx);
}
}}
/>
);
}}
/>
<StoryDetail
initial={index}
Expand Down Expand Up @@ -142,5 +150,6 @@ export const StoryPreview: React.FC<StoryPreviewProps> = ({

StoryPreview.displayName = 'StoryPreview';
StoryPreview.defaultProps = {
getStoryPreviewItemProps: () => {},
stories: [],
};

0 comments on commit 23cd82b

Please sign in to comment.