From 1543d9fe2eae9a1e038e7a17da6cbcf14e240747 Mon Sep 17 00:00:00 2001 From: Alberto Schiabel Date: Sun, 15 Apr 2018 13:30:10 +0200 Subject: [PATCH] Update index.js - removed useless function invokation - switched from old style propTypes declaration to the static version. This makes all the code related to the component reside inside its class declaration, thus enhancing encapsulation and readability --- index.js | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/index.js b/index.js index 3dedcc9..402f1de 100644 --- a/index.js +++ b/index.js @@ -10,6 +10,25 @@ import { } from "react-native"; export default class BouncingPreloader extends Component { + static propTypes = { + icons: PropTypes.array, + leftRotation: PropTypes.string, + rightRotation: PropTypes.string, + leftDistance: PropTypes.number, + rightDistance: PropTypes.number, + speed: PropTypes.number + }; + static defaultProps = { + icons: [ + "https://www.shareicon.net/data/256x256/2016/05/04/759946_bar_512x512.png", + "https://www.shareicon.net/data/256x256/2016/05/04/759908_food_512x512.png" + ], + leftRotation: "-680deg", + rightRotation: "360deg", + leftDistance: -180, + rightDistance: -250, + speed: 1200 + }; state = { spinValue: new Animated.Value(0), yValue: new Animated.Value(0), @@ -33,7 +52,7 @@ export default class BouncingPreloader extends Component { currentIndex: nextIndex >= icons.length / 2 ? 0 : nextIndex }, () => { - this.startAnimation(() => this.changeIndex()); + this.startAnimation(this.changeIndex); } ); } @@ -123,26 +142,6 @@ export default class BouncingPreloader extends Component { } } -BouncingPreloader.propTypes = { - icons: PropTypes.array, - leftRotation: PropTypes.string, - rightRotation: PropTypes.string, - leftDistance: PropTypes.number, - rightDistance: PropTypes.number, - speed: PropTypes.number -}; -BouncingPreloader.defaultProps = { - icons: [ - "https://www.shareicon.net/data/256x256/2016/05/04/759946_bar_512x512.png", - "https://www.shareicon.net/data/256x256/2016/05/04/759908_food_512x512.png" - ], - leftRotation: "-680deg", - rightRotation: "360deg", - leftDistance: -180, - rightDistance: -250, - speed: 1200 -}; - const styles = StyleSheet.create({ container: {}, image: {