Skip to content

Commit d54050c

Browse files
ethansharM-i-k-e-l
andauthored
Fix/dialog on dismiss (#755)
* Revert change that caused onDismiss issue in DateTimePicker component * in Dialog add parity for Android with iOS Modal onDismiss * expose onDialogDismissed prop for both iOS and Android * add deprecation warning * Add check for prop existence Co-authored-by: Miki Leib <michaelle@wix.com>
1 parent f00b01c commit d54050c

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/components/dialog/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {StyleSheet} from 'react-native';
55
import {Constants} from '../../helpers';
66
import {Colors} from '../../style';
77
import {BaseComponent} from '../../commons';
8+
import {LogService} from '../../services';
89
import Modal from '../modal';
910
import View from '../view';
1011
import PanListenerView from '../panningViews/panListenerView';
@@ -59,9 +60,13 @@ class Dialog extends BaseComponent {
5960
*/
6061
useSafeArea: PropTypes.bool,
6162
/**
62-
* Called once the modal has been dissmissed (iOS only)
63+
* Called once the modal has been dismissed (iOS only) - Deprecated, use onDialogDismissed instead
6364
*/
6465
onModalDismissed: PropTypes.func,
66+
/**
67+
* Called once the dialog has been dismissed completely
68+
*/
69+
onDialogDismissed: PropTypes.func,
6570
/**
6671
* If this is added only the header will be pannable;
6772
* this allows for scrollable content (the children of the dialog)
@@ -93,6 +98,10 @@ class Dialog extends BaseComponent {
9398
};
9499

95100
this.setAlignment();
101+
102+
if (!_.isUndefined(props.onModalDismissed)) {
103+
LogService.deprecationWarn({component: 'Dialog', oldProp: 'onModalDismissed', newProp: 'onDialogDismissed'});
104+
}
96105
}
97106

98107
componentDidMount() {
@@ -137,9 +146,20 @@ class Dialog extends BaseComponent {
137146
onDismiss = () => {
138147
this.setState({modalVisibility: false}, () => {
139148
const props = this.getThemeProps();
140-
_.invoke(props, 'onDismiss', props);
149+
if (props.visible) {
150+
_.invoke(props, 'onDismiss', props);
151+
}
152+
// Parity with iOS Modal's onDismiss
153+
if (Constants.isAndroid) {
154+
_.invoke(props, 'onDialogDismissed', props);
155+
}
141156
});
142157
};
158+
159+
onModalDismissed = () => {
160+
_.invoke(this.props, 'onDialogDismissed', this.props);
161+
_.invoke(this.props, 'onModalDismissed', this.props);
162+
}
143163

144164
hideDialogView = () => {
145165
this.setState({dialogVisibility: false});
@@ -197,7 +217,7 @@ class Dialog extends BaseComponent {
197217

198218
render = () => {
199219
const {orientationKey, modalVisibility} = this.state;
200-
const {overlayBackgroundColor, onModalDismissed, supportedOrientations, accessibilityLabel} = this.getThemeProps();
220+
const {overlayBackgroundColor, supportedOrientations, accessibilityLabel} = this.getThemeProps();
201221

202222
return (
203223
<Modal
@@ -208,7 +228,7 @@ class Dialog extends BaseComponent {
208228
onBackgroundPress={this.hideDialogView}
209229
onRequestClose={this.hideDialogView}
210230
overlayBackgroundColor={overlayBackgroundColor}
211-
onDismiss={onModalDismissed}
231+
onDismiss={this.onModalDismissed}
212232
supportedOrientations={supportedOrientations}
213233
accessibilityLabel={accessibilityLabel}
214234
>

0 commit comments

Comments
 (0)