Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import React, {Component} from 'react'
- import { View,
- Dimensions,
- StyleSheet, Animated} from 'react-native'
- let {width:W,height:H} = Dimensions.get("window");
- export default class test0123 extends React.Component{
- constructor(props){
- super(props);
- this.state={
- pos:new Animated.ValueXY
- }
- }
- _loopAnimation(){
- let des = {x:W*Math.random(), y:Math.random()*H};
- Animated.timing(this.state.pos, {
- toValue:des,
- duration:3000
- }).start(()=>{
- this._loopAnimation();
- });
- }
- componentDidMount(){
- this._loopAnimation();
- }
- render(){
- return <Animated.View style={{
- width:50,height:50,
- borderRadius:25,
- backgroundColor:"red",
- position:"absolute",
- left:this.state.pos.x,
- top:this.state.pos.y
- }}/>
- }
- }
Add Comment
Please, Sign In to add comment