Skip to content

Add slide animation view. #682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/common/SlideAnimationView.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/* flow */
import React, { Component } from 'react';
import { Animated } from 'react-native';

export default class SlideAnimationView extends Component {
state = {
animationIndex: new Animated.Value(0),
};

animate() {
const { easing, duration } = this.props;
this.state.animationIndex.setValue(0);
Animated.timing(this.state.animationIndex, {
toValue: 1,
duration,
easing,
useNativeDriver: true,
}).start();
}

componentWillReceiveProps() {
this.animate();
}

render() {
const { property, from, to, movement, style } = this.props;
const animationValue = this.state.animationIndex.interpolate({
inputRange: [0, 1],
outputRange: movement === 'out' ? [from, to] : [to, from],
});

const slideStyle = { transform: [{ [property]: animationValue }] };
return (
<Animated.View style={[style, slideStyle]}>
{this.props.children}
</Animated.View>
);
}
}
1 change: 1 addition & 0 deletions src/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export { default as UserStatusIndicator } from './UserStatusIndicator';
export { default as ZulipButton } from './ZulipButton';
export { default as ZulipStatusBar } from './ZulipStatusBar';
export { default as ZulipSwitch } from './ZulipSwitch';
export { default as SlideAnimationView } from './SlideAnimationView';