Advertisement
Guest User

Untitled

a guest
Feb 8th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. 'use strict';
  2.  
  3. import React, {
  4. Component,
  5. Animated,
  6. Easing,
  7. Dimensions,
  8. StyleSheet
  9. } from 'react-native';
  10.  
  11. import Art, {
  12. Surface,
  13. Shape,
  14. Path,
  15. } from 'ReactNativeART';
  16.  
  17. import AnimatedCircle from './AnimatedCircle.js';
  18.  
  19. const {
  20. width: deviceWidth,
  21. height: deviceHeight
  22. } = Dimensions.get('window');
  23.  
  24. const AnimatedShape = Animated.createAnimatedComponent(Shape);
  25.  
  26. const AnimatedCircle = React.createClass({displayName: "Circle",
  27. render() {
  28. let radius = this.props.radius;
  29. let path = Path().moveTo(0, -radius)
  30. .arc(0, radius * 2, radius)
  31. .arc(0, radius * -2, radius)
  32. .close();
  33. return React.createElement(AnimatedShape, React.__spread({}, this.props, {d: path}));
  34. }
  35. });
  36.  
  37. const NUM_CIRCLES = 100;
  38.  
  39. const getRandomInt = (min, max) => Math.floor(Math.random() * (max - min)) + min;
  40.  
  41. class PerfTest extends Component {
  42. translateCircle(y, x, translate) {
  43. const move = () => {
  44. const newY = getRandomInt(y-50, y+50);
  45. const newX = getRandomInt(x-50, x+50);
  46.  
  47. Animated.timing(translate, {
  48. toValue: {
  49. x: getRandomInt(x, newX),
  50. y: getRandomInt(y, newY)
  51. },
  52. duration: 8000,
  53. easing: Easing.elastic(1),
  54. }).start();
  55.  
  56. setTimeout(move, 8000);
  57. }
  58.  
  59. return move();
  60. }
  61.  
  62. renderCircle() {
  63. return [...Array(NUM_CIRCLES).keys()].map(() => {
  64. const size = getRandomInt(0, 10);
  65. const y = getRandomInt(0, deviceHeight);
  66. const x = parseInt(getRandomInt(0, deviceWidth));
  67. const translate = new Animated.ValueXY({x: x, y: y});
  68.  
  69. this.translateCircle(y, x, translate);
  70.  
  71. return (
  72. <AnimatedCircle
  73. key={ i }
  74. x={ translate.x }
  75. y={ translate.y }
  76. radius={ size }
  77. scale={ 0.3 }
  78. fill={ 'rgba(0,0,0,0.1)' }
  79. opacity={ 1 }
  80. />
  81. );
  82. })
  83. }
  84.  
  85. render() {
  86. return (
  87. <Surface style={ styles.surface } width={ deviceWidth } height={ deviceHeight }>
  88. { this.renderCircles() }
  89. </Surface>
  90. );
  91. }
  92. }
  93.  
  94. const styles= StyleSheet.create({
  95. surface: {
  96. position: 'absolute',
  97. top: 0,
  98. left: 0,
  99. },
  100. });
  101.  
  102. AppRegistry.registerComponent('PerfTest', () => PerfTest);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement