Skip to content

Commit 29959ae

Browse files
authored
Merge pull request #206 from gvlekke/master
a lot of prs merged
2 parents 05ec84a + e9f12f3 commit 29959ae

File tree

2 files changed

+92
-63
lines changed

2 files changed

+92
-63
lines changed

Example/index.ios.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Example extends React.Component {
3232
}
3333

3434
onOpen() {
35-
console.log('Modal just openned');
35+
console.log('Modal just opened');
3636
}
3737

3838
onClosingState(state) {

index.js

+91-62
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ var ModalBox = createReactClass({
6565
easing: PropTypes.func,
6666
coverScreen: PropTypes.bool,
6767
keyboardTopOffset: PropTypes.number,
68-
6968
onClosed: PropTypes.func,
7069
onOpened: PropTypes.func,
7170
onClosingState: PropTypes.func,
@@ -149,7 +148,7 @@ var ModalBox = createReactClass({
149148
* The keyboard is hidden (IOS only)
150149
*/
151150
onKeyboardHide: function(evt) {
152-
this.state.keyboardOffset = 0;
151+
this.setState({ keyboardOffset: 0 });
153152
},
154153

155154
/*
@@ -161,8 +160,9 @@ var ModalBox = createReactClass({
161160
var keyboardFrame = evt.endCoordinates;
162161
var keyboardHeight = this.state.containerHeight - keyboardFrame.screenY;
163162

164-
this.state.keyboardOffset = keyboardHeight;
165-
this.animateOpen();
163+
this.setState({ keyboardOffset: keyboardHeight }, () => {
164+
this.animateOpen();
165+
});
166166
},
167167

168168
/*
@@ -171,19 +171,21 @@ var ModalBox = createReactClass({
171171
animateBackdropOpen: function() {
172172
if (this.state.isAnimateBackdrop) {
173173
this.state.animBackdrop.stop();
174-
this.state.isAnimateBackdrop = false;
175174
}
176175

177-
this.state.isAnimateBackdrop = true;
178-
this.state.animBackdrop = Animated.timing(
176+
let animBackdrop = Animated.timing(
179177
this.state.backdropOpacity,
180178
{
181179
toValue: 1,
182180
duration: this.props.animationDuration
183181
}
184182
);
185-
this.state.animBackdrop.start(() => {
186-
this.state.isAnimateBackdrop = false;
183+
184+
this.setState({
185+
isAnimateBackdrop: true,
186+
animBackdrop
187+
}, () => {
188+
this.state.animBackdrop.start();
187189
});
188190
},
189191

@@ -193,19 +195,21 @@ var ModalBox = createReactClass({
193195
animateBackdropClose: function() {
194196
if (this.state.isAnimateBackdrop) {
195197
this.state.animBackdrop.stop();
196-
this.state.isAnimateBackdrop = false;
197198
}
198199

199-
this.state.isAnimateBackdrop = true;
200-
this.state.animBackdrop = Animated.timing(
200+
let animBackdrop = Animated.timing(
201201
this.state.backdropOpacity,
202202
{
203203
toValue: 0,
204204
duration: this.props.animationDuration
205205
}
206206
);
207-
this.state.animBackdrop.start(() => {
208-
this.state.isAnimateBackdrop = false;
207+
208+
this.setState({
209+
isAnimateBackdrop: false,
210+
animBackdrop
211+
}, () => {
212+
this.state.animBackdrop.start();
209213
});
210214
},
211215

@@ -215,7 +219,7 @@ var ModalBox = createReactClass({
215219
stopAnimateOpen: function() {
216220
if (this.state.isAnimateOpen) {
217221
if (this.state.animOpen) this.state.animOpen.stop();
218-
this.state.isAnimateOpen = false;
222+
this.setState({ isAnimateOpen: false });
219223
}
220224
},
221225

@@ -229,29 +233,36 @@ var ModalBox = createReactClass({
229233
if (this.props.backdrop)
230234
this.animateBackdropOpen();
231235

232-
this.state.isAnimateOpen = true;
233-
234-
requestAnimationFrame(() => {
235-
// Detecting modal position
236-
this.state.positionDest = this.calculateModalPosition(this.state.containerHeight - this.state.keyboardOffset, this.state.containerWidth);
237-
if (this.state.keyboardOffset && (this.state.positionDest < this.props.keyboardTopOffset)) {
238-
this.state.positionDest = this.props.keyboardTopOffset;
239-
}
240-
this.state.animOpen = Animated.timing(
241-
this.state.position,
242-
{
243-
toValue: this.state.positionDest,
244-
duration: this.props.animationDuration,
245-
easing: this.props.easing,
236+
this.setState({
237+
isAnimateOpen: true,
238+
isOpen: true,
239+
}, () => {
240+
requestAnimationFrame(() => {
241+
// Detecting modal position
242+
let positionDest = this.calculateModalPosition(this.state.containerHeight - this.state.keyboardOffset, this.state.containerWidth);
243+
if (this.state.keyboardOffset && (positionDest < this.props.keyboardTopOffset)) {
244+
positionDest = this.props.keyboardTopOffset;
246245
}
247-
);
248-
this.state.animOpen.start(() => {
249-
if (!this.state.isOpen && this.props.onOpened) this.props.onOpened();
250-
this.state.isAnimateOpen = false;
251-
this.state.isOpen = true;
252-
});
253-
})
254-
246+
let animOpen = Animated.timing(
247+
this.state.position,
248+
{
249+
toValue: positionDest,
250+
duration: this.props.animationDuration,
251+
easing: this.props.easing,
252+
}
253+
);
254+
255+
this.setState({
256+
isAnimateOpen: false,
257+
animOpen,
258+
positionDest
259+
}, () => {
260+
animOpen.start(() => {
261+
if (!this.state.isOpen && this.props.onOpened) this.props.onOpened();
262+
});
263+
});
264+
})
265+
});
255266
},
256267

257268
/*
@@ -260,7 +271,7 @@ var ModalBox = createReactClass({
260271
stopAnimateClose: function() {
261272
if (this.state.isAnimateClose) {
262273
if (this.state.animClose) this.state.animClose.stop();
263-
this.state.isAnimateClose = false;
274+
this.setState({ isAnimateClose: false });
264275
}
265276
},
266277

@@ -274,20 +285,26 @@ var ModalBox = createReactClass({
274285
if (this.props.backdrop)
275286
this.animateBackdropClose();
276287

277-
this.state.isAnimateClose = true;
278-
this.state.animClose = Animated.timing(
279-
this.state.position,
280-
{
281-
toValue: this.props.entry === 'top' ? -this.state.containerHeight : this.state.containerHeight,
282-
duration: this.props.animationDuration
283-
}
284-
);
285-
this.state.animClose.start(() => {
286-
Keyboard.dismiss();
287-
this.state.isAnimateClose = false;
288-
this.state.isOpen = false;
289-
this.setState({});
290-
if (this.props.onClosed) this.props.onClosed();
288+
this.setState({
289+
isAnimateClose: true,
290+
isOpen: false,
291+
}, () => {
292+
let animClose = Animated.timing(
293+
this.state.position,
294+
{
295+
toValue: this.props.entry === 'top' ? -this.state.containerHeight : this.state.containerHeight,
296+
duration: this.props.animationDuration
297+
}
298+
);
299+
300+
this.setState({
301+
isAnimateClose: false,
302+
animClose
303+
}, () => {
304+
animClose.start(() => {
305+
if (this.props.onClosed) this.props.onClosed();
306+
});
307+
});
291308
});
292309
},
293310

@@ -321,8 +338,9 @@ var ModalBox = createReactClass({
321338
inSwipeArea = false;
322339
if (this.props.entry === 'top' ? -state.dy > this.props.swipeThreshold : state.dy > this.props.swipeThreshold)
323340
this.animateClose();
324-
else
341+
else if (!this.state.isOpen) {
325342
this.animateOpen();
343+
}
326344
};
327345

328346
var animEvt = Animated.event([null, {customY: this.state.position}]);
@@ -347,11 +365,13 @@ var ModalBox = createReactClass({
347365
return true;
348366
};
349367

350-
this.state.pan = PanResponder.create({
351-
onStartShouldSetPanResponder: onPanStart,
352-
onPanResponderMove: onPanMove,
353-
onPanResponderRelease: onPanRelease,
354-
onPanResponderTerminate: onPanRelease,
368+
this.setState({
369+
pan: PanResponder.create({
370+
onStartShouldSetPanResponder: onPanStart,
371+
onPanResponderMove: onPanMove,
372+
onPanResponderRelease: onPanRelease,
373+
onPanResponderTerminate: onPanRelease,
374+
}),
355375
});
356376
},
357377

@@ -405,7 +425,7 @@ var ModalBox = createReactClass({
405425
if (this.props.backdrop) {
406426
backdrop = (
407427
<TouchableWithoutFeedback onPress={this.props.backdropPressToClose ? this.close : null}>
408-
<Animated.View style={[styles.absolute, {opacity: this.state.backdropOpacity}]}>
428+
<Animated.View importantForAccessibility="no" style={[styles.absolute, {opacity: this.state.backdropOpacity}]}>
409429
<View style={[styles.absolute, {backgroundColor:this.props.backdropColor, opacity: this.props.backdropOpacity}]}/>
410430
{this.props.backdropContent || []}
411431
</Animated.View>
@@ -425,6 +445,7 @@ var ModalBox = createReactClass({
425445
onLayout={this.onViewLayout}
426446
style={[styles.wrapper, size, this.props.style, {transform: [{translateY: this.state.position}, {translateX: offsetX}]} ]}
427447
{...this.state.pan.panHandlers}>
448+
{this.props.backdropPressToClose && <TouchableWithoutFeedback onPress={this.close}><View style={[styles.absolute]} /></TouchableWithoutFeedback>}
428449
{this.props.children}
429450
</Animated.View>
430451
)
@@ -434,23 +455,31 @@ var ModalBox = createReactClass({
434455
* Render the component
435456
*/
436457
render: function() {
458+
437459
var visible = this.state.isOpen || this.state.isAnimateOpen || this.state.isAnimateClose;
438460

439461
if (!visible) return <View/>
440462

441463
var content = (
442-
<View style={[styles.transparent, styles.absolute]} pointerEvents={'box-none'}>
464+
<View importantForAccessibility="yes" accessibilityViewIsModal={true} style={[styles.transparent, styles.absolute]} pointerEvents={'box-none'}>
443465
<View style={{ flex: 1 }} pointerEvents={'box-none'} onLayout={this.onContainerLayout}>
444466
{visible && this.renderBackdrop()}
445467
{visible && this.renderContent()}
446468
</View>
447469
</View>
448470
)
449471

450-
if (!this.props.coverScreen) return content;
472+
if (!this.props.coverScreen) return content;
451473

452474
return (
453-
<Modal onRequestClose={() => this.close()} supportedOrientations={['landscape', 'portrait']} transparent visible={visible}>
475+
<Modal
476+
onRequestClose={() => {
477+
if (this.props.backButtonClose) {
478+
this.close()
479+
}
480+
}}
481+
supportedOrientations={['landscape', 'portrait', 'portrait-upside-down']} transparent visible={visible}
482+
>
454483
{content}
455484
</Modal>
456485
);

0 commit comments

Comments
 (0)