Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save patissier-boulanger/301ed3c68e6c571b612fa0e37ebe3fb4 to your computer and use it in GitHub Desktop.
Save patissier-boulanger/301ed3c68e6c571b612fa0e37ebe3fb4 to your computer and use it in GitHub Desktop.
React-Native-modal-dimmed-Area
import React, {useEffect} from 'react';
import Animated, {
Easing,
useAnimatedStyle,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
type ModalPropType = {
showModal: boolean;
};
export function Modal({showModal}: ModalPropType) {
const backgroundColor = useSharedValue(0);
const backdropAnimatedStyle = useAnimatedStyle(() => {
return {
position: 'absolute',
top: 0,
right: 0,
bottom: 0,
left: 0,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#00000099',
opacity: backgroundColor.value,
zIndex: 1,
};
});
useEffect(() => {
if (showModal) {
backgroundColor.value = withTiming(1, {
duration: 250,
easing: Easing.linear,
});
return;
}
}, [showModal, backgroundColor]);
return (
<>
{showModal ? (
<>
<Animated.View style={backdropAnimatedStyle} />
</>
) : (
<></>
)}
</>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment