Skip to content

Instantly share code, notes, and snippets.

@mczernek
Last active November 16, 2020 09:41
Show Gist options
  • Save mczernek/ba38fcf64a46a98cf567f6ff50bc2a34 to your computer and use it in GitHub Desktop.
Save mczernek/ba38fcf64a46a98cf567f6ff50bc2a34 to your computer and use it in GitHub Desktop.
const showVideoOverlay = useSharedValue(0 as number);
const [overlayVisible, setOverlayVisible] = useState(false as boolean);
const videoOverlayStyle = useAnimatedStyle(() => {
return {
opacity: showVideoOverlay.value,
};
});
const showVideo = () => {
trackCourseVideoOpened(result?.id);
setOverlayVisible(true);
showVideoOverlay.value = withTiming(1);
};
const hideOverlay = () => {
setOverlayVisible(false);
};
const hideVideo = () => {
trackCourseVideoClosed(result?.id);
showVideoOverlay.value = withTiming(0, undefined, () => {
runOnJS(hideOverlay);
});
};
return (
...
{result.courseVideo && overlayVisible && (
<Animated.View style={[styles.videoOverlay, videoOverlayStyle]}>
...
</Animated.View>
)}
...
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment