Skip to content

Add hamburger animation #211

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 4 commits into from
Aug 17, 2020
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
2 changes: 1 addition & 1 deletion src/page/HomePage/HeaderView.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class HeaderView extends React.Component {
</TouchableOpacity>
)}
{this.state && this.state.reportName && (
<Text style={[styles.navText]}>
<Text numberOfLines={2} style={[styles.navText]}>
{this.state.reportName}
</Text>
)}
Expand Down
39 changes: 33 additions & 6 deletions src/page/HomePage/HomePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
StatusBar,
View,
Dimensions,
Animated,
Easing
} from 'react-native';
import {SafeAreaInsetsContext, SafeAreaProvider} from 'react-native-safe-area-context';
import {Route} from '../../lib/Router';
Expand All @@ -26,7 +28,8 @@ export default class App extends React.Component {
// TODO: Set back to windowSize.width > widthBreakPoint once
// https://github.com/AndrewGable/ReactNativeChat/pull/132 is merged
hamburgerShown: true,
isHamburgerEnabled: windowSize.width <= widthBreakPoint
isHamburgerEnabled: windowSize.width <= widthBreakPoint,
animationTranslateX: new Animated.Value(0),
};

this.toggleHamburger = this.toggleHamburger.bind(this);
Expand Down Expand Up @@ -74,8 +77,26 @@ export default class App extends React.Component {
return;
}

const currentValue = this.state.hamburgerShown;
this.setState({hamburgerShown: !currentValue});
const hamburgerIsShown = this.state.hamburgerShown;
const animationFinalValue = hamburgerIsShown ? -300 : 0;

// If the hamburger currently is not shown, we want to immediately make it visible for the animation
if (!hamburgerIsShown) {
this.setState({hamburgerShown: !hamburgerIsShown});
}

Animated.timing(this.state.animationTranslateX, {
toValue: animationFinalValue,
duration: 200,
easing: Easing.ease,
useNativeDriver: false
}).start(({finished}) => {
// If the hamburger is currently shown, we want to hide it only after the animation is complete
// Otherwise, we can't see the animation
if (finished && hamburgerIsShown) {
this.setState({hamburgerShown: false});
}
});
}

render() {
Expand All @@ -98,12 +119,18 @@ export default class App extends React.Component {
]}
>
<Route path="/:reportID?">
<View style={[hamburgerStyle, visibility]}>
<Animated.View style={[
hamburgerStyle,
visibility,
{
transform: [{translateX: this.state.animationTranslateX}]
}]}
>
<Sidebar insets={insets} onLinkClick={this.toggleHamburger} />
</View>
</Animated.View>
<View style={[styles.appContent, appContentStyle, styles.flex1, styles.flexColumn]}>
<Header
shouldShowHamburgerButton={!this.state.hamburgerShown}
shouldShowHamburgerButton={this.state.isHamburgerEnabled}
onHamburgerButtonClicked={this.toggleHamburger}
/>
<Main />
Expand Down
11 changes: 9 additions & 2 deletions src/style/StyleSheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,18 @@ const styles = {
top: 0,
bottom: 0,
zIndex: 2,
width: 300
width: 300,
shadowColor: '#000000',
shadowOffset: {
width: 0,
height: 0,
},
shadowOpacity: 0.3,
shadowRadius: 20
},

hamburgerOpen: {
width: 300
width: 300,
}

};
Expand Down