Skip to content
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

[Toolbar] Added show and hide animations #80

Merged
merged 18 commits into from
Jan 28, 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
1 change: 1 addition & 0 deletions docs/BottomNavigation.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# [BottomNavigation](https://material.google.com/components/bottom-navigation.html)

<img src="https://raw.githubusercontent.com/xotahal/react-native-material-ui-demo-app/master/resources/bottom-navigation-1.gif" width="285">
<img src="https://raw.githubusercontent.com/xotahal/react-native-material-ui-demo-app/master/resources/bottom-navigation-anim.gif" width="285">

Expand Down
Empty file modified src/BottomNavigation/BottomNavigationAction.react.js
100755 → 100644
Empty file.
45 changes: 42 additions & 3 deletions src/Toolbar/Toolbar.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
TextInput,
TouchableWithoutFeedback,
View,
Platform,
Easing,
} from 'react-native';
/* eslint-enable import/no-unresolved, import/extensions */
import IconToggle from '../IconToggle';
Expand Down Expand Up @@ -84,6 +86,10 @@ const propTypes = {
*/
translucent: PropTypes.bool,
/**
* Wether or not the Toolbar should show
*/
hidden: PropTypes.bool,
/**
* Called when centerElement was pressed.
* TODO: better to rename to onCenterElementPress
*/
Expand Down Expand Up @@ -146,6 +152,7 @@ const propTypes = {
const defaultProps = {
elevation: 4, // TODO: probably useless, elevation is defined in getTheme function
style: {},
hidden: false,
};
const contextTypes = {
uiTheme: PropTypes.object.isRequired,
Expand Down Expand Up @@ -219,6 +226,7 @@ class Toolbar extends PureComponent {
this.state = {
isSearchActive: props.isSearchActive,
searchValue: '',
moveAnimated: new Animated.Value(0),
};
}
componentWillReceiveProps(nextProps) {
Expand All @@ -230,6 +238,14 @@ class Toolbar extends PureComponent {
if (nextProps.searchable && this.state.isSearchActive) {
this.backButtonListener = addBackButtonListener(this.onSearchCloseRequested);
}
// if hidden prop is changed we animate show or hide
if (nextProps.hidden !== this.props.hidden) {
if (nextProps.hidden === true) {
this.hide();
} else {
this.show();
}
}
}
onMenuPressed = (labels) => {
const { onRightElementPress } = this.props;
Expand Down Expand Up @@ -268,7 +284,6 @@ class Toolbar extends PureComponent {
searchable.onSearchPressed();
}


this.setState({
isSearchActive: true,
searchValue: '',
Expand All @@ -283,7 +298,6 @@ class Toolbar extends PureComponent {
searchable.onSearchClosed();
}


this.setState({
isSearchActive: false,
searchValue: '',
Expand All @@ -292,6 +306,25 @@ class Toolbar extends PureComponent {
focusSearchField() {
this.searchFieldRef.focus();
}
show = () => {
const { moveAnimated } = this.state;
Animated.timing(moveAnimated, {
toValue: 0,
duration: 225,
easing: Easing.bezier(0.0, 0.0, 0.2, 1),
useNativeDriver: Platform.OS === 'android',
}).start();
}
hide = () => {
const { moveAnimated } = this.state;
const styles = getStyles(this.props, this.context, this.state);
Animated.timing(moveAnimated, {
toValue: (-1 * StyleSheet.flatten(styles.container).height),
duration: 195,
easing: Easing.bezier(0.4, 0.0, 0.6, 1),
useNativeDriver: Platform.OS === 'android',
}).start();
}
renderLeftElement = (style) => {
const { searchable, leftElement, onLeftElementPress, size } = this.props;

Expand Down Expand Up @@ -496,7 +529,13 @@ class Toolbar extends PureComponent {
const styles = getStyles(this.props, this.context, this.state);

return (
<Animated.View style={styles.container}>
<Animated.View
style={[styles.container, {
transform: [{
translateY: this.state.moveAnimated,
}],
}]}
>
{this.renderLeftElement(styles)}
{this.renderCenterElement(styles)}
{this.renderRightElement(styles)}
Expand Down