Guest User

Untitled

a guest
Jan 22nd, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. import React, {Component} from 'react'
  2. import { View,
  3. Dimensions,
  4. StyleSheet, Animated} from 'react-native'
  5.  
  6. let {width:W,height:H} = Dimensions.get("window");
  7.  
  8. export default class test0123 extends React.Component{
  9.  
  10. constructor(props){
  11. super(props);
  12. this.state={
  13. pos:new Animated.ValueXY
  14. }
  15. }
  16.  
  17. _loopAnimation(){
  18. let des = {x:W*Math.random(), y:Math.random()*H};
  19. Animated.timing(this.state.pos, {
  20. toValue:des,
  21. duration:3000
  22. }).start(()=>{
  23. this._loopAnimation();
  24. });
  25. }
  26.  
  27. componentDidMount(){
  28. this._loopAnimation();
  29. }
  30.  
  31. render(){
  32. return <Animated.View style={{
  33. width:50,height:50,
  34. borderRadius:25,
  35. backgroundColor:"red",
  36. position:"absolute",
  37. left:this.state.pos.x,
  38. top:this.state.pos.y
  39. }}/>
  40. }
  41. }
Add Comment
Please, Sign In to add comment