Skip to content

Instantly share code, notes, and snippets.

@DimitryDushkin
Last active January 8, 2024 10:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DimitryDushkin/2a5db8d854288af224b9190be4a9452e to your computer and use it in GitHub Desktop.
Save DimitryDushkin/2a5db8d854288af224b9190be4a9452e to your computer and use it in GitHub Desktop.
React Native animated fade-in and fade-out
import React from 'react';
import {StyleProp, ViewStyle} from 'react-native';
import * as Animatable from 'react-native-animatable';
type Props = {
isVisible: boolean,
children: React.ReactNode,
style?: StyleProp<ViewStyle>,
};
export default function AnimatableFade({isVisible, children, style}: Props) {
return (
<Animatable.View
transition={['opacity']}
style={[
{opacity: isVisible ? 1 : 0},
style,
]}
useNativeDriver
>
{children}
</Animatable.View>
);
}
// How to use
function App() {
const [isVisible, setVisibility] = useState(false);
return (
<>
<Button onPress={() => setVisibility(!isVisible)}>Toggle</Button>
<AnimatedFade isVisible={isVisible}><Text>HEY LOOK!</Text></AnimatedFade>
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment