-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoopAnimation.js
More file actions
116 lines (101 loc) · 3.23 KB
/
LoopAnimation.js
File metadata and controls
116 lines (101 loc) · 3.23 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import React, { Component, PropTypes } from 'react';
import {
StyleSheet,
View,
Text,
Image,
Dimensions,//get size of the device
Animated,
Easing
} from 'react-native';
import InViewPort from 'react-native-inviewport';
const Window = Dimensions.get('window');
const styles = StyleSheet.create({
main:{
flex: 1,
flexDirection: 'row',
position: 'absolute'
}
});
class LoopAnimation extends Component{
static propTypes={
};
static defaultProps={
source: {uri:'https://i.kinja-img.com/gawker-media/image/upload/s--ZI7xve4h--/c_scale,fl_progressive,q_80,w_800/ceukprxttxixxluji8tj.jpg',width: 600,height: 400},
duration: 10000,
style:{height: Window.height}
};
constructor(props){
super(props);
this.state={
move_1: new Animated.Value(0),
move_2: new Animated.Value(0),
width: 0,
};
}
firstAnimation(){
Animated.sequence([
Animated.timing(this.state.move_2,{
toValue: 0,
duration: 0,
}),
Animated.parallel([
Animated.timing(this.state.move_1,{
//toValue: -450,
toValue: -this.state.width,
duration: this.props.duration,
easing: Easing.linear,
}),
Animated.timing(this.state.move_2,{
//toValue: -450,
toValue: -this.state.width,
duration: this.props.duration,
easing: Easing.linear,
}),
])
]).start(() => {
this.secondAnimation();
});
}
secondAnimation(){
Animated.sequence([
Animated.timing(this.state.move_1,{
//toValue:450,
toValue: this.state.width,
duration:0,
}),
Animated.parallel([
Animated.timing(this.state.move_2,{
//toValue:-900,
toValue: -2*this.state.width,
duration: this.props.duration,
easing: Easing.linear,
}),
Animated.timing(this.state.move_1,{
toValue:0,
duration: this.props.duration,
easing: Easing.linear,
})
])
]).start(() => {
this.firstAnimation();
});
}
getWidth(e){
var ImageWidth = e.nativeEvent.layout.width;
this.setState({width: ImageWidth});
}
checkVisibility(){
}
render(){
const slidingAnimation_1 = this.state.move_1;
const slidingAnimation_2 = this.state.move_2;
return(
<View style={styles.main}>
<Animated.Image onLayout={this.getWidth.bind(this)} onLoadEnd={()=>{this.firstAnimation()}} source={this.props.source} style={[this.props.style, {transform: [{translateX: slidingAnimation_1}]} ]}/>
<Animated.Image source={this.props.source} style={[this.props.style, {transform: [{translateX: slidingAnimation_2},{scaleX:-1}]}]}/>
</View>
);
};
};
module.exports = LoopAnimation;