Skip to content

Commit d66de28

Browse files
Merge pull request #21 from AlexGustafsson/coherent-animation
Made animations coherent as per iOS spec.
2 parents 5661e79 + 829c05d commit d66de28

File tree

3 files changed

+20
-24
lines changed

3 files changed

+20
-24
lines changed

components/NavBarContent.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
'use strict';
22

33
var React = require('react-native');
4-
var tweenState = require('react-tween-state'); // Animate header
4+
var Animated = require('Animated');
5+
var Easing = require('Easing');
56

67
var NavButton = require('./NavButton');
78

@@ -14,26 +15,26 @@ var {
1415

1516
var NavBarContent = React.createClass({
1617

17-
mixins: [tweenState.Mixin],
18-
1918
getInitialState: function() {
2019
return {
21-
opacity: this.props.willDisappear ? 1 : 0
20+
opacity: this.props.willDisappear ? new Animated.Value(1) : new Animated.Value(0)
2221
};
2322
},
2423

2524
componentWillReceiveProps: function(newProps) {
2625
if (newProps.route !== this.props.route) {
27-
this.setState({
28-
opacity: this.props.willDisappear ? 1 : 0
29-
});
26+
this.state.opacity.setValue(this.props.willDisappear ? 1 : 0);
3027

3128
setTimeout(() => {
32-
this.tweenState('opacity', {
33-
easing: tweenState.easingTypes.easeInOutQuad,
34-
duration: 200,
35-
endValue: 1
36-
});
29+
Animated.timing(
30+
this.state.opacity,
31+
{
32+
fromValue: this.props.willDisappear ? 1 : 0,
33+
toValue: this.props.willDisappear ? 0 : 1,
34+
duration: 300,
35+
easing: Easing.easeOutQuad
36+
}
37+
).start();
3738
}, 0);
3839
}
3940
},
@@ -54,7 +55,7 @@ var NavBarContent = React.createClass({
5455

5556
render() {
5657
var transitionStyle = {
57-
opacity: this.getTweeningValue('opacity'),
58+
opacity: this.state.opacity,
5859
};
5960

6061
var leftCorner;
@@ -128,11 +129,11 @@ var NavBarContent = React.createClass({
128129
var color = this.props.borderColor ? this.props.borderColor : null;
129130

130131
return (
131-
<View style={[styles.navbar, transitionStyle, this.props.route.headerStyle,{borderBottomWidth: width, borderColor: color}, trans]}>
132+
<Animated.View style={[styles.navbar, transitionStyle, this.props.route.headerStyle,{borderBottomWidth: width, borderColor: color}, trans]}>
132133
{leftCorner}
133134
{titleComponent}
134135
{rightCorner}
135-
</View>
136+
</Animated.View>
136137
);
137138
}
138139
});

index.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ var Router = React.createClass({
2626
}
2727
},
2828

29-
/*
30-
* This changes the title in the navigation bar
31-
* It should preferrably be called for "onWillFocus" instad >
32-
* > but a recent update to React Native seems to break the animation
33-
*/
34-
onDidFocus: function(route) {
29+
onWillFocus: function(route) {
3530
this.setState({ route: route });
3631
},
3732

@@ -45,7 +40,7 @@ var Router = React.createClass({
4540
route.index = this.state.route.index + 1 || 1;
4641
navigator.push(route);
4742
},
48-
43+
4944
replaceRoute: function(route) {
5045
route.index = this.state.route.index + 0 || 0;
5146
this.refs.navigator.replace(route);
@@ -209,7 +204,7 @@ var Router = React.createClass({
209204
initialRoute={this.props.firstRoute}
210205
navigationBar={navigationBar}
211206
renderScene={this.renderScene}
212-
onDidFocus={this.onDidFocus}
207+
onWillFocus={this.onWillFocus}
213208
/>
214209
)
215210
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
},
2828
"homepage": "https://github.com/MikaelCarpenter/gb-native-router",
2929
"dependencies": {
30-
"react-tween-state": "^0.1.x"
30+
3131
},
3232
"peerDependencies": {
3333
"react-native": "^0.12.0"

0 commit comments

Comments
 (0)