From d69406b4b1ad0dfbb7b9edabb99b8b15c5efc4e7 Mon Sep 17 00:00:00 2001 From: Cesar Andreu Date: Sun, 3 Jul 2016 11:00:50 -0700 Subject: [PATCH] Add an API to wrap and initialize animated (#159) --- src/apis/Animated/index.js | 14 ++++++++++++++ src/components/Touchable/TouchableBounce.js | 2 +- src/components/Touchable/TouchableOpacity.js | 2 +- src/index.js | 11 ++--------- 4 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 src/apis/Animated/index.js diff --git a/src/apis/Animated/index.js b/src/apis/Animated/index.js new file mode 100644 index 00000000..21f80b94 --- /dev/null +++ b/src/apis/Animated/index.js @@ -0,0 +1,14 @@ +import Animated from 'animated' +import StyleSheet from '../StyleSheet' +import Image from '../../components/Image' +import Text from '../../components/Text' +import View from '../../components/View' + +Animated.inject.FlattenStyle(StyleSheet.flatten) + +module.exports = { + ...Animated, + Image: Animated.createAnimatedComponent(Image), + Text: Animated.createAnimatedComponent(Text), + View: Animated.createAnimatedComponent(View) +} diff --git a/src/components/Touchable/TouchableBounce.js b/src/components/Touchable/TouchableBounce.js index 1c39ae99..7aec0b39 100644 --- a/src/components/Touchable/TouchableBounce.js +++ b/src/components/Touchable/TouchableBounce.js @@ -12,7 +12,7 @@ */ 'use strict'; -var Animated = require('animated'); +var Animated = require('../../apis/Animated'); var EdgeInsetsPropType = require('../../apis/StyleSheet/EdgeInsetsPropType'); var NativeMethodsMixin = require('../../modules/NativeMethodsMixin'); var React = require('react'); diff --git a/src/components/Touchable/TouchableOpacity.js b/src/components/Touchable/TouchableOpacity.js index e33af48a..2f6c6d91 100644 --- a/src/components/Touchable/TouchableOpacity.js +++ b/src/components/Touchable/TouchableOpacity.js @@ -14,7 +14,7 @@ // Note (avik): add @flow when Flow supports spread properties in propTypes -var Animated = require('animated'); +var Animated = require('../../apis/Animated'); var NativeMethodsMixin = require('../../modules/NativeMethodsMixin'); var React = require('react'); var StyleSheet = require('../../apis/StyleSheet'); diff --git a/src/index.js b/src/index.js index 65712f58..d2daef2b 100644 --- a/src/index.js +++ b/src/index.js @@ -5,7 +5,7 @@ import ReactDOM from 'react-dom' import ReactDOMServer from 'react-dom/server' // apis -import Animated from 'animated' +import Animated from './apis/Animated' import AppRegistry from './apis/AppRegistry' import AppState from './apis/AppState' import AsyncStorage from './apis/AsyncStorage' @@ -43,8 +43,6 @@ import ColorPropType from './apis/StyleSheet/ColorPropType' import EdgeInsetsPropType from './apis/StyleSheet/EdgeInsetsPropType' import PointPropType from './apis/StyleSheet/PointPropType' -Animated.inject.FlattenStyle(StyleSheet.flatten) - const ReactNative = { // top-level API findNodeHandle, @@ -55,12 +53,7 @@ const ReactNative = { renderToString: ReactDOMServer.renderToString, // apis - Animated: { - ...Animated, - Image: Animated.createAnimatedComponent(Image), - Text: Animated.createAnimatedComponent(Text), - View: Animated.createAnimatedComponent(View) - }, + Animated, AppRegistry, AppState, AsyncStorage,