Skip to content

Commit 75f0646

Browse files
Sam1301borisyankov
authored andcommitted
Add slide animation view.
1 parent b6c6261 commit 75f0646

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/common/SlideAnimationView.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* flow */
2+
import React, { Component } from 'react';
3+
import { Animated } from 'react-native';
4+
5+
export default class SlideAnimationView extends Component {
6+
state = {
7+
animationIndex: new Animated.Value(0),
8+
};
9+
10+
animate() {
11+
const { easing, duration } = this.props;
12+
this.state.animationIndex.setValue(0);
13+
Animated.timing(this.state.animationIndex, {
14+
toValue: 1,
15+
duration,
16+
easing,
17+
useNativeDriver: true,
18+
}).start();
19+
}
20+
21+
componentWillReceiveProps() {
22+
this.animate();
23+
}
24+
25+
render() {
26+
const { property, from, to, movement, style } = this.props;
27+
const animationValue = this.state.animationIndex.interpolate({
28+
inputRange: [0, 1],
29+
outputRange: movement === 'out' ? [from, to] : [to, from],
30+
});
31+
32+
const slideStyle = { transform: [{ [property]: animationValue }] };
33+
return (
34+
<Animated.View style={[style, slideStyle]}>
35+
{this.props.children}
36+
</Animated.View>
37+
);
38+
}
39+
}

src/common/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ export { default as UserStatusIndicator } from './UserStatusIndicator';
1919
export { default as ZulipButton } from './ZulipButton';
2020
export { default as ZulipStatusBar } from './ZulipStatusBar';
2121
export { default as ZulipSwitch } from './ZulipSwitch';
22+
export { default as SlideAnimationView } from './SlideAnimationView';

0 commit comments

Comments
 (0)