From 1c5ba514f840cbca7f1749d4b7a756f3998656ee Mon Sep 17 00:00:00 2001 From: leeight Date: Tue, 4 Oct 2016 22:28:42 +0800 Subject: [PATCH 1/2] Add viewConfig to RCTSlider Component --- Examples/UIExplorer/js/RTLExample.js | 4 +--- Libraries/Animated/src/AnimatedImplementation.js | 8 +++++--- Libraries/Components/Slider/Slider.js | 9 +++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/Examples/UIExplorer/js/RTLExample.js b/Examples/UIExplorer/js/RTLExample.js index 5298dc5f6a99..74f31b0ea214 100644 --- a/Examples/UIExplorer/js/RTLExample.js +++ b/Examples/UIExplorer/js/RTLExample.js @@ -47,8 +47,6 @@ const { const UIExplorerPage = require('./UIExplorerPage'); const UIExplorerBlock = require('./UIExplorerBlock'); -const AnimatedImage = Animated.createAnimatedComponent(Image); - type State = { toggleStatus: any, pan: Object, @@ -116,7 +114,7 @@ function AnimationBlock(props) { return ( - diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 4182a8aac375..1779b916c436 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -1715,9 +1715,11 @@ function createAnimatedComponent(Component: any): any { var callback = () => { if (this._component.setNativeProps) { if (!this._propsAnimated.__isNative) { - this._component.setNativeProps( - this._propsAnimated.__getAnimatedValue() - ); + if (this._component.viewConfig != null) { + this._component.setNativeProps( + this._propsAnimated.__getAnimatedValue() + ); + } } else { throw new Error('Attempting to run JS driven animation on animated ' + 'node that has been moved to "native" earlier by starting an ' diff --git a/Libraries/Components/Slider/Slider.js b/Libraries/Components/Slider/Slider.js index 032d374ba581..2db7392b805e 100644 --- a/Libraries/Components/Slider/Slider.js +++ b/Libraries/Components/Slider/Slider.js @@ -13,6 +13,7 @@ var Image = require('Image'); var NativeMethodsMixin = require('react/lib/NativeMethodsMixin'); +var ReactNativeViewAttributes = require('ReactNativeViewAttributes'); var Platform = require('Platform'); var PropTypes = require('react/lib/ReactPropTypes'); var React = require('React'); @@ -139,6 +140,14 @@ var Slider = React.createClass({ }; }, + viewConfig: { + uiViewClassName: 'RCTSlider', + validAttributes: { + ...ReactNativeViewAttributes.RCTView, + value: true + } + }, + render: function() { const {style, onValueChange, onSlidingComplete, ...props} = this.props; props.style = [styles.slider, style]; From a33047096809021d940405e91a97b5a2c45a44db Mon Sep 17 00:00:00 2001 From: leeight Date: Wed, 12 Oct 2016 22:22:32 +0800 Subject: [PATCH 2/2] Throw error if viewConfig is undefined --- Libraries/Animated/src/AnimatedImplementation.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/Libraries/Animated/src/AnimatedImplementation.js b/Libraries/Animated/src/AnimatedImplementation.js index 1779b916c436..7fb99069c559 100644 --- a/Libraries/Animated/src/AnimatedImplementation.js +++ b/Libraries/Animated/src/AnimatedImplementation.js @@ -1715,11 +1715,15 @@ function createAnimatedComponent(Component: any): any { var callback = () => { if (this._component.setNativeProps) { if (!this._propsAnimated.__isNative) { - if (this._component.viewConfig != null) { - this._component.setNativeProps( - this._propsAnimated.__getAnimatedValue() - ); + if (this._component.viewConfig == null) { + var ctor = this._component.constructor; + var componentName = ctor.displayName || ctor.name || ''; + throw new Error(componentName + ' "viewConfig" is not defined.'); } + + this._component.setNativeProps( + this._propsAnimated.__getAnimatedValue() + ); } else { throw new Error('Attempting to run JS driven animation on animated ' + 'node that has been moved to "native" earlier by starting an '