-
Notifications
You must be signed in to change notification settings - Fork 177
/
shine.js
59 lines (50 loc) · 1.2 KB
/
shine.js
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
import React from 'react';
import { Animated, View, StyleSheet } from 'react-native';
import PropTypes from 'prop-types';
const START_VALUE = 0;
const END_VALUE = 100;
const DURATION = 750;
const isInteraction = false;
const styles = StyleSheet.create({
shine: {
width: 30,
position: 'absolute',
height: '100%',
backgroundColor: '#ffffff',
opacity: 0.4,
},
});
/**
* Create a repetitive Shine animation
*/
const Shine = ({ children, ...props }) => {
const animation = new Animated.Value(0);
function start() {
animation.setValue(START_VALUE);
Animated.sequence([
Animated.timing(animation, {
toValue: END_VALUE,
duration: DURATION,
isInteraction,
}),
]).start(e => e.finished && start());
}
start();
const marginLeft = animation.interpolate({
inputRange: [START_VALUE, END_VALUE],
outputRange: ['0%', '100%'],
});
return (
<View {...props}>
{children}
<Animated.View style={[styles.shine, { marginLeft }]} />
</View>
);
};
Shine.propTypes = {
children: PropTypes.oneOfType([PropTypes.element, PropTypes.arrayOf(PropTypes.element)]),
};
Shine.defaultProps = {
children: null,
};
export default Shine;