Skip to content

Commit 0170070

Browse files
committed
Prop screenHeight added to handle react native issue facebook/react-native#7340
1 parent dd14f4a commit 0170070

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,17 @@ This component supports all the properties of the original react native modal co
112112
| animateOnMount | false | `bool` | Determine whether or not animate the modal if it's visible when it mounts. |
113113
| animationDuration | 300 | `number` | Duration of the animation. |
114114
| position | bottom | `string` | Position where the sliding animation of the modal should start. Accepted values: "top", "bottom", "left", "right". |
115-
| containerStyle | - | `object` | Container styles used for positioning the modal with flexbox (default: alignItems: 'center', flex: 1, justifyContent: 'center'). See the examples. |
115+
| containerStyle | - | `any` | Container styles used for positioning the modal with flexbox (default: alignItems: 'center', flex: 1, justifyContent: 'center'). See the examples. |
116116
| isNative | true | `bool` | Determine the usage of the react native modal component or a simple view wrapper instead. It can be set to false to overcome some react native modal limitations (for example to have more than one modal open at the same time). |
117117
| onAnimateClose | () => null | `func` | Callback executed after the modal is closed. |
118118
| onAnimateOpen | () => null | `func` | Callback executed after the modal is open. |
119-
| overlayStyle | - | `object` | Styles used to define the overlay backgroundColor (default: "#000") and opacity (default: 0.5). |
119+
| overlayStyle | - | `any` | Styles used to define the overlay backgroundColor (default: "#000") and opacity (default: 0.5). |
120+
| screenHeight | computed screen height | `number` | Allow the user to manually set the right screen height to adjust the keyboardSpacer due to an issue on iPad in react native https://github.com/facebook/react-native/issues/7340. |
120121
| shouldAnimateOnOverlayPress | true | `bool` | Determine whether or not animate the modal closing down when the overlay is pressed. |
121122
| shouldAnimateOnRequestClose | false | `bool` | Determine whether or not animate the modal closing down when the onRequestClose callback is executed. |
122123
| shouldCloseOnOverlayPress | true | `bool` | Determine whether or not allow the modal closing down if the overlay is pressed. |
123124
| showOverlay | true | `bool` | Determine whether or not showing the overlay. In combination with isNative={false} it is possible to interact with the background of the application when the modal is still open. |
124-
| style | - | `object` | Styles of the modal (default: backgroundColor: '#fff', justifyContent: 'center'). |
125+
| style | - | `any` | Styles of the modal (default: backgroundColor: '#fff', justifyContent: 'center'). |
125126

126127
Note: this component sets some properties of the underlying native modal component to allow sliding flexibility in each direction and the clickable overlay behavior, therefore we suggest not to change those. However, you can set to 0 the animationDuration prop to avoid the component sliding logic from top, bottom, left or right and therefore turning on the react native modal animationType prop, disabled by default. Here the list of the react native modal properties set by default:
127128

index.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,9 @@ export default class ModalWrapper extends Component {
144144
}
145145
return previous;
146146
}, {});
147-
const { children, containerStyle, isNative, overlayStyle, showOverlay, style,
147+
const { children, containerStyle, isNative, overlayStyle, showOverlay, screenHeight, style,
148148
...modalProps } = Object.keys(this.props).reduce((previous, current) => {
149+
// the reducer is used to get the correct set of ...modalProps
149150
if (!Modal.propTypes.hasOwnProperty(current) && current !== 'position') {
150151
previous[current] = this.props[current];
151152
}
@@ -161,7 +162,8 @@ export default class ModalWrapper extends Component {
161162
const modal = <Animated.View style={modalStyle} {...modalProps}>
162163
{children}
163164
</Animated.View>;
164-
const keyboardSpacer = Platform.OS === 'ios' ? <KeyboardSpacer /> : null;
165+
const computedScreenHeight = screenHeight ? screenHeight : Dimensions.get('window').height;
166+
const keyboardSpacer = Platform.OS === 'ios' ? <KeyboardSpacer screenHeight={computedScreenHeight} /> : null;
165167
const renderContainer = (hasKeyboardSpacer) => ( // eslint-disable-line no-extra-parens
166168
<View style={[styles.container, containerStyle]}>
167169
{showOverlay &&
@@ -193,6 +195,7 @@ ModalWrapper.propTypes = {
193195
onAnimateOpen: React.PropTypes.func,
194196
overlayStyle: React.PropTypes.any,
195197
position: React.PropTypes.oneOf(['top', 'bottom', 'left', 'right']),
198+
screenHeight: React.PropTypes.number,
196199
showOverlay: React.PropTypes.bool,
197200
shouldAnimateOnOverlayPress: React.PropTypes.bool,
198201
shouldAnimateOnRequestClose: React.PropTypes.bool,

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-modal-wrapper",
3-
"version": "2.0.1",
3+
"version": "2.1.0",
44
"description": "Wrapper component that extends the react native Modal component, adding overlay clickable behavior and allowing swipe in and out in all directions",
55
"main": "index.js",
66
"scripts": {
@@ -33,7 +33,7 @@
3333
"lint"
3434
],
3535
"dependencies": {
36-
"react-native-keyboard-spacer": "^0.3.0"
36+
"react-native-keyboard-spacer": "miguelsm/react-native-keyboard-spacer#screen-height-prop"
3737
},
3838
"devDependencies": {
3939
"babel-eslint": "7.1.1",

0 commit comments

Comments
 (0)