Skip to content
Open
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: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var {

var Button = require('./button.js');
var Overlay = require('./overlay.js');
var ModalActionSheet = require('./modal.js');
var Sheet = require('./sheet.js');

module.exports = React.createClass({
Expand Down Expand Up @@ -46,6 +47,7 @@ module.exports = React.createClass({
},
});
module.exports.Button = Button;
module.exports.ModalActionSheet = ModalActionSheet;

var styles = StyleSheet.create({
actionSheetContainer: {
Expand Down
56 changes: 56 additions & 0 deletions modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React, {Modal} from 'react-native';

import ActionSheet from '@remobile/react-native-action-sheet';

//The idea behind this thin wrapper is that it allows you to put action sheet's anywhere in your component tree,
//not just in a component that consumes the entire screen.

export default class ModalActionSheet extends React.Component {
constructor(props, context) {
super(props, context);
this.state = {
modalVisible: this.props.visible || false,
sheetVisible: false,
}
}

componentWillReceiveProps(nextProps) {
if(nextProps.visible && !this.props.visible) this.show();
else if(!nextProps.visible && this.props.visible) this.hide();
}

show() {
console.log('SHOW')
this.setState({modalVisible: true});
}
hide() {
this.setState({sheetVisible: false});
//allow ActionSheet to slide down animation to be seen before hiding modal

setTimeout(() => {
this.setState({modalVisible: false});
}, 300);
}

render() {
return (
<Modal
animated={false}
transparent={true}
visible={this.state.modalVisible}
onShow={() => this.setState({sheetVisible: true})}
//onDismiss={this.onDismiss} //not working in RN 22, so timers used instead; ideally onDismiss and onCancel are used in combination similar to onShow/show; perhaps in RN 23+ when onRequestClose works
>
<ActionSheet
visible={this.state.sheetVisible}
onCancel={this.props.onCancel}
cancelText={this.props.cancelText}
>
{this.props.children}
</ActionSheet>
</Modal>
);
}
}

ModalActionSheet.Button = ActionSheet.Button;