Skip to content

Commit 5f59d51

Browse files
authored
Merge pull request #91 from animatedjs/transformStyleFix
Fix transform styles on initial mount.
2 parents b553f0f + 2ba4362 commit 5f59d51

File tree

7 files changed

+2620
-24
lines changed

7 files changed

+2620
-24
lines changed

examples/interactive-docs/example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
global.React = require('react');
33
global.ReactDOM = require('react-dom');
44
global.Animated = require('../../lib/targets/react-dom');
5+
global.createClass = require("create-react-class");

examples/interactive-docs/index.html

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@
185185
var previousScript = document.getElementsByClassName('Example' + EXAMPLE_COUNT)[0].innerText;
186186
} else {
187187
var previousScript = `
188-
examplify(React.createClass({
188+
examplify(createClass({
189189
getInitialState: function() {
190190
return {
191191
anim: new Animated.Value(0), // ignore
@@ -210,7 +210,7 @@
210210
var code = document.createElement('div');
211211
script.parentNode.insertBefore(code, script);
212212

213-
var Example = React.createClass({
213+
var Example = createClass({
214214
render() {
215215
return (
216216
<div className="code">
@@ -223,7 +223,7 @@
223223
<Component key={Math.random()} />
224224
</div>
225225
<hr />
226-
<pre>{'React.createClass({'}</pre>
226+
<pre>{'createClass({'}</pre>
227227
{script.innerText
228228
.trim()
229229
.split(/\n/g)
@@ -257,7 +257,7 @@ <h2>Animated.Value</h2>
257257
<p>The basic building block of this library is <code>Animated.Value</code>. This is a variable that's going to drive the animation. You use it like a normal value in <code>style</code> attribute. Only animated components such as <code>Animated.div</code> will understand it.</p>
258258

259259
<script type="text/babel">
260-
examplify(React.createClass({
260+
examplify(createClass({
261261
getInitialState: function() {
262262
return {
263263
anim: new Animated.Value(100),
@@ -281,7 +281,7 @@ <h2>setValue</h2>
281281
<p>The <code>Animated.div</code> component when rendered tracks which animated values it received. This way, whenever that value changes, we don't need to re-render the entire component, we can directly update the specific style attribute that changed.</p>
282282

283283
<script type="text/babel">
284-
examplify(React.createClass({
284+
examplify(createClass({
285285
getInitialState: function() {
286286
return {
287287
anim: new Animated.Value(0),
@@ -310,7 +310,7 @@ <h2>Animated.timing</h2>
310310
<p>On every frame (via <code>requestAnimationFrame</code>), the <code>timing</code> animation is going to figure out the new value based on the current time, update the animated value which in turn is going to update the corresponding DOM node.</p>
311311

312312
<script type="text/babel">
313-
examplify(React.createClass({
313+
examplify(createClass({
314314
getInitialState: function() {
315315
return {
316316
anim: new Animated.Value(0),
@@ -339,7 +339,7 @@ <h2>Interrupt Animations</h2>
339339
<p>There are multiple challenges to implement this correctly. You need to stop the current animation, grab the current value and restart an animation from there. As this is pretty tedious to do manually, <code>Animated</code> will do that automatically for you.</p>
340340

341341
<script type="text/babel">
342-
examplify(React.createClass({
342+
examplify(createClass({
343343
getInitialState: function() {
344344
return {
345345
anim: new Animated.Value(1),
@@ -374,7 +374,7 @@ <h2>Animated.spring</h2>
374374
<p>It turns out that this model is useful in a very wide range of animations. I highly recommend you to always start with a <code>spring</code> animation instead of a <code>timing</code> animation. It will make your interface feels much better.</p>
375375

376376
<script type="text/babel">
377-
examplify(React.createClass({
377+
examplify(createClass({
378378
getInitialState: function() {
379379
return {
380380
anim: new Animated.Value(1),
@@ -409,7 +409,7 @@ <h2>interpolate</h2>
409409
<p>In the following example, we're going to model the animation with a variable where 1 means fully visible and 0 means fully hidden. We can pass it directly to the scale attribute as the ranges match. But for the rotation, we need to convert [0 ; 1] range to [260deg ; 0deg]. This is where <code>interpolate()</code> comes handy.</p>
410410

411411
<script type="text/babel">
412-
examplify(React.createClass({
412+
examplify(createClass({
413413
getInitialState: function() {
414414
return {
415415
anim: new Animated.Value(1),
@@ -453,7 +453,7 @@ <h2>stopAnimation</h2>
453453
<p>There's however one exception: when you want to stop the current animation. You need to know where it stopped in order to continue from there. We cannot know the value synchronously so we give it via a callback in <code>stopAnimation</code>. It will not suffer from beign out of sync since the animation is no longer running.</p>
454454

455455
<script type="text/babel">
456-
examplify(React.createClass({
456+
examplify(createClass({
457457
getInitialState: function() {
458458
return {
459459
anim: new Animated.Value(0)
@@ -503,7 +503,7 @@ <h2>HorizontalPan</h2>
503503
<p>We introduce a little helper called <code>HorizontalPan</code> which handles all this annoying code for us. It takes an <code>Animated.Value</code> as first argument and returns the event handlers required for it to work. We just have to bind this value to the <code>left</code> attribute and we're good to go.</p>
504504

505505
<script type="text/babel">
506-
examplify(React.createClass({
506+
examplify(createClass({
507507
getInitialState: function() {
508508
return {
509509
anim: new Animated.Value(0),
@@ -529,7 +529,7 @@ <h2>Animated.decay</h2>
529529
<p>In order to implement this effect, we are using a second real-world simulation: an object moving on an icy surface. All it needs is two values: the current velocity and a deceleration coefficient. It is implemented by <code>Animated.decay</code>.</p>
530530

531531
<script type="text/babel">
532-
examplify(React.createClass({
532+
examplify(createClass({
533533
getInitialState: function() {
534534
return {
535535
anim: new Animated.Value(0),
@@ -558,7 +558,7 @@ <h2>Animation Chaining</h2>
558558
<p>The target for an animation is usually a number but sometimes it is convenient to use another value as a target. This way, the first value will track the second. Using a spring animation, we can get a nice trailing effect.</p>
559559

560560
<script type="text/babel">
561-
examplify(React.createClass({
561+
examplify(createClass({
562562
getInitialState: function() {
563563
var anims = [0, 1, 2, 3, 4].map((_, i) => new Animated.Value(0));
564564
Animated.spring(anims[0], {toValue: anims[1]}).start();
@@ -596,7 +596,7 @@ <h2>addListener</h2>
596596
<p>As I said earlier, if you track a spring</p>
597597

598598
<script type="text/babel">
599-
examplify(React.createClass({
599+
examplify(createClass({
600600
getInitialState: function() {
601601
var anims = [0, 1, 2, 3, 4].map((_, i) => new Animated.Value(i * 100));
602602
anims[0].addListener(this.handleChange);
@@ -659,7 +659,7 @@ <h2>Animated.sequence</h2>
659659
<p>It is very common to animate </p>
660660

661661
<script type="text/babel">
662-
examplify(React.createClass({
662+
examplify(createClass({
663663
getInitialState: function() {
664664
return {
665665
anims: [0, 1, 2, 3, 4].map((_, i) => new Animated.Value(0.2)),
@@ -690,7 +690,7 @@ <h2>Animated.sequence</h2>
690690

691691

692692
<script type="text/babel">
693-
examplify(React.createClass({
693+
examplify(createClass({
694694
getInitialState: function() {
695695
return {
696696
anims: [0, 1, 2, 3, 4].map((_, i) => new Animated.Value(0.2)),
@@ -721,7 +721,7 @@ <h2>Animated.sequence</h2>
721721
</script><script>example();</script>
722722

723723
<script type="text/babel">
724-
examplify(React.createClass({
724+
examplify(createClass({
725725
getInitialState: function() {
726726
return {
727727
anims: [0, 1, 2, 3, 4].map((_, i) => new Animated.Value(0.2)),
@@ -757,7 +757,7 @@ <h2>Animated.sequence</h2>
757757
</script><script>example();</script>
758758

759759
<script type="text/babel">
760-
examplify(React.createClass({
760+
examplify(createClass({
761761
getInitialState: function() {
762762
return {
763763
anim: new Animated.Value(0),
@@ -797,7 +797,7 @@ <h2>Animated.sequence</h2>
797797
</script><script>example();</script>
798798

799799
<script type="text/babel">
800-
examplify(React.createClass({
800+
examplify(createClass({
801801
getInitialState: function() {
802802
return {
803803
anim: new Animated.Value(0)

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"babel-preset-react": "^6.5.0",
4646
"babel-preset-react-native": "^1.4.0",
4747
"browserify": "^13.0.0",
48-
"react": "^15.4.0",
49-
"react-dom": "^15.4.0"
48+
"create-react-class": "^15.6.3",
49+
"react": "^16.2.0",
50+
"react-dom": "^16.2.0"
5051
}
5152
}

src/createAnimatedComponent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,12 @@ function createAnimatedComponent(Component: any): any {
7272
}
7373

7474
render() {
75+
const { style, ...other} = this._propsAnimated.__getValue();
76+
7577
return (
7678
<Component
77-
{...this._propsAnimated.__getValue()}
79+
{...other}
80+
style={ApplyAnimatedValues.transformStyles(style)}
7881
ref={refName}
7982
/>
8083
);

src/injectable/ApplyAnimatedValues.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ var ApplyAnimatedValues = {
1818
return false;
1919
}
2020
},
21-
inject(apply) {
21+
transformStyles: function transformStyles(style) {
22+
return style;
23+
},
24+
inject(apply, transform) {
2225
ApplyAnimatedValues.current = apply;
26+
ApplyAnimatedValues.transformStyles = transform;
2327
},
2428
};
2529

src/targets/react-dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function ApplyAnimatedValues(instance, props) {
174174

175175
Animated
176176
.inject
177-
.ApplyAnimatedValues(ApplyAnimatedValues);
177+
.ApplyAnimatedValues(ApplyAnimatedValues, mapStyle);
178178

179179
module.exports = {
180180
...Animated,

0 commit comments

Comments
 (0)