Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | 1x 1x 1x 1x 1x 1x 1x 41x 1x 1x | import Svg, { Rect } from 'react-native-svg';
import { Animated, StyleSheet } from 'react-native';
import React, { FC, useEffect, useRef } from 'react';
interface StripedOverlayProps {
width: number;
height: number;
stripeWidth?: number;
color?: string;
opacity?: number;
animated: boolean;
direction: 'horizontal' | 'vertical';
}
const StripedOverlay: FC<StripedOverlayProps> = ({
width,
height,
stripeWidth = 8,
color = 'rgba(255,255,255,1)',
opacity = 0.8,
animated,
direction
}) => {
const translateAnim = useRef(new Animated.Value(0)).current;
useEffect(() => {
Eif (animated) {
Animated.loop(
Animated.timing(translateAnim, {
toValue: stripeWidth * 5,
duration: 1000,
useNativeDriver: true,
})
).start();
}
}, [animated]);
const stripes = [];
for (let i = -Math.max(width, height); i < Math.max(width, height) * 2; i += stripeWidth * 2.75) {
stripes.push(
<Rect
key={i}
x={i}
y={0}
width={stripeWidth}
height={Math.max(width, height) * 2}
transform={`rotate(-45 ${i} 0)`}
fill={color}
opacity={opacity}
/>
);
}
const animatedStyle = {
transform: [
direction === 'horizontal' ? { translateX: translateAnim } : { translateY: translateAnim },
],
};
return (
<Animated.View pointerEvents="none" style={[StyleSheet.absoluteFill, animatedStyle]}>
<Svg
style={{ transform: [{ translateX: -50 }, { translateY: -50 }] }}
width={width + 1000}
height={height + 1000}
>
{stripes}
</Svg>
</Animated.View>
);
};
export default StripedOverlay;
|