-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add simple animations * feat: create option list wrapper * feat: update snapshot * fix: apply requested changes, rename isAnimated prop to animated * fix: change ReactElement type for ReactNode * fix: change default animations prop in types * feat: add animated example * feat: add animation example with different animation durations Co-authored-by: Agata Kosior <agata.kosior@tunego.com>
- Loading branch information
Showing
8 changed files
with
211 additions
and
81 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
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,21 @@ | ||
import React from 'react'; | ||
import { SafeAreaView, Text } from 'react-native'; | ||
import { Select } from '@mobile-reality/react-native-select-pro'; | ||
|
||
import { DATA } from '../App'; | ||
|
||
export const Animated = () => { | ||
return ( | ||
<SafeAreaView> | ||
<Text style={{ marginBottom: 10 }}>With default animation duration (200 ms)</Text> | ||
<Select animated options={DATA} selectControlStyle={{ width: 280, marginBottom: 20 }} /> | ||
<Text style={{ marginBottom: 10 }}>With custom animation duration (500 ms)</Text> | ||
<Select | ||
animated | ||
animationDuration={500} | ||
options={DATA} | ||
selectControlStyle={{ width: 280 }} | ||
/> | ||
</SafeAreaView> | ||
); | ||
}; |
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,48 @@ | ||
import React, { ComponentProps, ReactNode, useEffect, useRef } from 'react'; | ||
import { Animated, StyleProp, View, ViewStyle } from 'react-native'; | ||
|
||
import type { OptionalToRequired } from '../../helpers'; | ||
import type { OptionsList } from '../options-list'; | ||
|
||
type FromOptionListProps = Pick< | ||
ComponentProps<typeof OptionsList>, | ||
'animated' | 'animationDuration' | 'isOpened' | ||
>; | ||
|
||
type WrapperStyles = { | ||
wrapperStyles: StyleProp<ViewStyle>; | ||
}; | ||
|
||
type OptionsListWrapperProps = OptionalToRequired<FromOptionListProps> & { | ||
children: ReactNode; | ||
} & WrapperStyles; | ||
|
||
export const OptionsListWrapper = ({ | ||
children, | ||
animated, | ||
animationDuration, | ||
isOpened, | ||
wrapperStyles, | ||
}: OptionsListWrapperProps) => { | ||
const fadeAnimation = useRef(new Animated.Value(0)).current; | ||
|
||
useEffect(() => { | ||
if (animated) { | ||
Animated.timing(fadeAnimation, { | ||
toValue: isOpened ? 1 : 0, | ||
duration: animationDuration, | ||
useNativeDriver: true, | ||
}).start(); | ||
} | ||
}, [fadeAnimation, isOpened]); | ||
|
||
return animated ? ( | ||
<Animated.View | ||
pointerEvents={isOpened ? 'auto' : 'none'} | ||
style={[wrapperStyles, { opacity: fadeAnimation }]}> | ||
{children} | ||
</Animated.View> | ||
) : isOpened ? ( | ||
<View style={wrapperStyles}>{children}</View> | ||
) : null; | ||
}; |
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.