Skip to content

Instantly share code, notes, and snippets.

@rt2zz
Created November 27, 2015 23:23
Show Gist options
  • Save rt2zz/21d06a70167a6c976f9f to your computer and use it in GitHub Desktop.
Save rt2zz/21d06a70167a6c976f9f to your computer and use it in GitHub Desktop.
competing drawers
/**
* Sample React Native App
* https://github.com/facebook/react-native
*/
'use strict';
var React = require('react-native');
var {
AppRegistry,
StyleSheet,
Text,
View,
} = React;
var Drawer = require('react-native-drawer')
var dtest = React.createClass({
getInitialState () {
return {
leftDrawerOpen: false,
rightDrawerOpen: false
}
},
toggleLeftDrawer () {
this.state.leftDrawerOpen ? this.refs.leftDrawer.close() : this.refs.leftDrawer.open();
},
toggleRightDrawer () {
this.state.rightDrawerOpen ? this.refs.rightDrawer.close() : this.refs.rightDrawer.open();
},
openRightDrawer () {
this.setState({
rightDrawerOpen: true
})
console.log('OPEN RIGHT')
},
openLeftDrawer () {
this.setState({
leftDrawerOpen: true
})
console.log('OPEN LEFT')
},
closeLeftDrawer () {
this.setState({
leftDrawerOpen: false
})
console.log('CLOSE LEFT')
},
closeRightDrawer () {
this.setState({
rightDrawerOpen: false
})
console.log('CLOSE RIGHT')
},
render () {
// return <View style={{width: 500, height: 500, backgroundColor: 'red'}}><Text>hi</Text></View>
return (
<Drawer
ref='leftDrawer'
type='static'
side='left'
content={<View style={{padding: 20, flex: 1, backgroundColor: 'rgba(150,20,20,.5)'}}><Text>Left Panel</Text></View>}
openDrawerOffset={100}
onOpen={this.openLeftDrawer}
onClose={this.closeLeftDrawer}
styles={{main: {shadowColor: '#000000', shadowOpacity: 0.4, shadowRadius: 3}}}
tweenHandler={Drawer.tweenPresets.parallax}
captureGestures={this.state.leftDrawerOpen ? true : false}
>
<Drawer
ref='rightDrawer'
type='static'
side='right'
content={<View style={{padding: 20, flex: 1, backgroundColor: 'rgba(100,100,20,.5)'}}><Text>Right Panel</Text></View>}
openDrawerOffset={100}
onOpen={this.openRightDrawer}
onClose={this.closeRightDrawer}
styles={{main: {shadowColor: '#000000', shadowOpacity: 0.4, shadowRadius: 3}}}
tweenHandler={Drawer.tweenPresets.parallax}
captureGestures={this.state.rightDrawerOpen ? true : false}
>
<View style={{flex: 1, backgroundColor: 'rgba(100,50,90,.5)'}}>
<Text>Hi Main</Text>
</View>
</Drawer>
</Drawer>
)
}
});
var styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});
AppRegistry.registerComponent('dtest', () => dtest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment