React native swipe navigation
Swipe to navigate
It's another react native navigation library -- still in beta version --
Snapchat demo
![](https://github.com/540/react-native-swipe-navigation/raw/HEAD/./giphy.gif)
Installation
yarn add react-native-swipe-navigation
or
npm install --save react-native-swipe-navigation
Usage
If we want to implement this navigation style
Check the Demo
![](https://github.com/540/react-native-swipe-navigation/raw/HEAD/./giphy3.gif)
So this library provides for us a clean and an easy way to do it
import SwipeNavigator from 'react-native-swipe-navigation';
const Navigator = SwipeNavigator({
Map: {
screen: Map,
left: 'Notifications',
right: 'Menu',
top: 'Search',
bottom: 'Messages',
},
Notifications: {
screen: Notifications,
type: 'push',
},
Menu: {
screen: Menu,
type: 'over',
},
Search: {
screen: Search,
type: 'place',
},
Messages: {
screen: Messages,
right: 'Chat',
},
Chat: {
screen: Chat,
type: 'over',
color: '#fbb464',
},
Profile: {
screen: Profile,
left: '@BACK',
type: 'over',
},
});
export default Navigator
Now the SwipeNavigator will pass a nav props to all screens for more control
class Map extends React.Component {
componentDidMount() {
const { nav } = this.props;
nav.onNavigateShouldAllow(() => {
return true;
});
nav.onNavigateLeftShouldAllow(() => {
return true;
});
nav.onNavigateRightShouldAllow(() => {
return true;
});
nav.onNavigateUpShouldAllow(() => {
return true;
});
nav.onNavigateDownShouldAllow(() => {
return true;
});
nav.onNavigateLeftStartedListener(({isBack, isMain}) => {
});
nav.onNavigateLeftCompletedListener(({completed, isBack}) => {
});
nav.onNavigateRightStartedListener(({isBack, isMain}) => {
});
nav.onNavigateRightCompletedListener(({completed, isBack}) => {
});
nav.onNavigateDownStartedListener(({isBack, isMain}) => {
});
nav.onNavigateDownCompletedListener(({completed, isBack}) => {
});
nav.onNavigateUpStartedListener(({isBack, isMain}) => {
});
nav.onNavigateUpCompletedListener(({completed, isBack}) => {
});
}
componentWillUnmount() {
this.props.nav.cleanUp()
}
render() {
return (
<View style={{flex: 1, backgroundColor: 'blue'}}>
<TouchableOpacity onPress={() => this.props.nav.navigate('Profile')}>
<Text>GO TO PROFILE</Text>
</TouchableOpacity>
</View>
);
}
}