Skip to content

Commit 3b69b71

Browse files
authored
Merge pull request #144 from prtkkmrsngh/master
Add coverScreen prop to fit parent components
2 parents 32b0e9d + 15488d4 commit 3b69b71

1 file changed

Lines changed: 26 additions & 5 deletions

File tree

index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var {
1212
BackAndroid,
1313
BackHandler,
1414
Platform,
15+
Modal
1516
} = require('react-native');
1617

1718
var BackButton = BackHandler || BackAndroid;
@@ -58,6 +59,7 @@ var ModalBox = React.createClass({
5859
animationDuration: React.PropTypes.number,
5960
backButtonClose: React.PropTypes.bool,
6061
easing: React.PropTypes.func,
62+
coverScreen: React.PropTypes.bool,
6163

6264
onClosed: React.PropTypes.func,
6365
onOpened: React.PropTypes.func,
@@ -78,6 +80,7 @@ var ModalBox = React.createClass({
7880
animationDuration: 400,
7981
backButtonClose: false,
8082
easing: Easing.elastic(0.8),
83+
coverScreen: false,
8184
};
8285
},
8386

@@ -396,11 +399,11 @@ var ModalBox = React.createClass({
396399
var size = {height: this.state.containerHeight, width: this.state.containerWidth};
397400
var offsetX = (this.state.containerWidth - this.state.width) / 2;
398401
var backdrop = this.renderBackdrop(size);
399-
400-
if (!visible) return <View/>
401-
402-
return (
403-
<View style={[styles.transparent, styles.absolute]} pointerEvents={'box-none'} onLayout={this.onContainerLayout}>
402+
var coverScreen = this.props.coverScreen;
403+
var modalContainer = [];
404+
405+
modalContainer = (
406+
<View style={{ flex: 1 }} pointerEvents={'box-none'} onLayout={this.onContainerLayout}>
404407
{backdrop}
405408
<Animated.View
406409
onLayout={this.onViewLayout}
@@ -410,6 +413,24 @@ var ModalBox = React.createClass({
410413
</Animated.View>
411414
</View>
412415
);
416+
417+
if (!visible) return <View/>
418+
419+
if (coverScreen) {
420+
return (
421+
<Modal onRequestClose={() => this.close()} supportedOrientations={['landscape', 'portrait']} transparent visible={visible}>
422+
<View style={[styles.transparent, styles.absolute]}>
423+
{modalContainer}
424+
</View>
425+
</Modal>
426+
);
427+
}
428+
429+
return (
430+
<View style={[styles.transparent, styles.absolute]}>
431+
{modalContainer}
432+
</View>
433+
);
413434
},
414435

415436
/****************** PUBLIC METHODS **********************/

0 commit comments

Comments
 (0)