-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* refactor(MovieCalendarProvider): give more control towards calendar context dates * feat: add disabled dates UI * refactor: separate useGetVenuesByDay in several hooks
- Loading branch information
1 parent
f5ecf6e
commit c0d7c70
Showing
24 changed files
with
770 additions
and
523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/features/offer/components/ExpandingFlatlist/ExpandingFlatList.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import { ComponentMeta } from '@storybook/react' | ||
import React from 'react' | ||
import styled from 'styled-components/native' | ||
|
||
import { VariantsTemplate, type Variants, type VariantsStory } from 'ui/storybook/VariantsTemplate' | ||
|
||
import { ExpandingFlatList } from './ExpandingFlatList' | ||
|
||
const meta: ComponentMeta<typeof ExpandingFlatList> = { | ||
title: 'features/offer/ExpandingFlatList', | ||
component: ExpandingFlatList, | ||
argTypes: { | ||
isLoading: { | ||
control: 'boolean', | ||
defaultValue: false, | ||
}, | ||
skeletonListLength: { | ||
control: 'number', | ||
defaultValue: 3, | ||
}, | ||
}, | ||
} | ||
export default meta | ||
|
||
type Item = { | ||
id: number | ||
title: string | ||
} | ||
|
||
const mockData: Item[] = [ | ||
{ id: 1, title: 'Item 1' }, | ||
{ id: 2, title: 'Item 2' }, | ||
{ id: 3, title: 'Item 3' }, | ||
] | ||
|
||
const variantConfig: Variants<typeof ExpandingFlatList<Item>> = [ | ||
{ | ||
label: 'Default state', | ||
props: { | ||
data: mockData, | ||
renderItem: () => <StyledItem />, | ||
renderSkeleton: () => <StyledItem />, | ||
}, | ||
}, | ||
] | ||
|
||
export const Template: VariantsStory<typeof ExpandingFlatList> = (args) => ( | ||
<VariantsTemplate | ||
variants={variantConfig.map((variant) => ({ | ||
...variant, | ||
props: { | ||
...variant.props, | ||
...args, | ||
}, | ||
}))} | ||
Component={ExpandingFlatList} | ||
/> | ||
) | ||
|
||
const StyledItem = styled.View({ | ||
borderColor: 'black', | ||
backgroundColor: 'lightgrey', | ||
borderWidth: 1, | ||
height: 50, | ||
width: 200, | ||
}) | ||
|
||
Template.storyName = 'ExpandingFlatList' | ||
Template.args = { | ||
isLoading: false, | ||
skeletonListLength: 3, | ||
} |
57 changes: 57 additions & 0 deletions
57
src/features/offer/components/ExpandingFlatlist/ExpandingFlatList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import React, { useCallback, useRef, useState } from 'react' | ||
import { View } from 'react-native' | ||
import Animated, { Easing, useAnimatedStyle, withTiming } from 'react-native-reanimated' | ||
|
||
export const ExpandingFlatList = <T,>({ | ||
isLoading, | ||
renderSkeleton, | ||
data, | ||
renderItem, | ||
skeletonListLength = 3, | ||
animationDuration = 300, | ||
...props | ||
}: Animated.FlatListPropsWithLayout<T> & { | ||
animationDuration?: number | ||
isLoading?: boolean | ||
skeletonListLength?: number | ||
renderSkeleton: Animated.FlatListPropsWithLayout<T>['renderItem'] | ||
}) => { | ||
const { animatedStyle, onContentSizeChange } = useAnimatedHeight(animationDuration) | ||
|
||
return ( | ||
<View> | ||
<Animated.FlatList | ||
{...props} | ||
data={isLoading ? Array(skeletonListLength).fill(undefined) : data} | ||
renderItem={isLoading ? renderSkeleton : renderItem} | ||
style={animatedStyle} | ||
onContentSizeChange={onContentSizeChange} | ||
/> | ||
</View> | ||
) | ||
} | ||
|
||
const useAnimatedHeight = (duration: number) => { | ||
const [contentHeight, setContentHeight] = useState(0) | ||
const isFirstRender = useRef(true) | ||
|
||
const animatedStyle = useAnimatedStyle(() => { | ||
if (isFirstRender.current) { | ||
isFirstRender.current = false | ||
return { height: contentHeight } | ||
} | ||
|
||
return { | ||
height: withTiming(contentHeight, { | ||
duration, | ||
easing: Easing.bezier(0.25, 0.1, 0.25, 1), | ||
}), | ||
} | ||
}, [contentHeight]) | ||
|
||
const onContentSizeChange = useCallback((_width: number, height: number) => { | ||
setContentHeight(height) | ||
}, []) | ||
|
||
return { animatedStyle, onContentSizeChange } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.