Skip to content

Fix/dialog on dismiss #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 26, 2020
Merged
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
28 changes: 24 additions & 4 deletions src/components/dialog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {StyleSheet} from 'react-native';
import {Constants} from '../../helpers';
import {Colors} from '../../style';
import {BaseComponent} from '../../commons';
import {LogService} from '../../services';
import Modal from '../modal';
import View from '../view';
import PanListenerView from '../panningViews/panListenerView';
Expand Down Expand Up @@ -59,9 +60,13 @@ class Dialog extends BaseComponent {
*/
useSafeArea: PropTypes.bool,
/**
* Called once the modal has been dissmissed (iOS only)
* Called once the modal has been dismissed (iOS only) - Deprecated, use onDialogDismissed instead
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add a warning?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done ✔️

*/
onModalDismissed: PropTypes.func,
/**
* Called once the dialog has been dismissed completely
*/
onDialogDismissed: PropTypes.func,
/**
* If this is added only the header will be pannable;
* this allows for scrollable content (the children of the dialog)
Expand Down Expand Up @@ -93,6 +98,10 @@ class Dialog extends BaseComponent {
};

this.setAlignment();

if (!_.isUndefined(props.onModalDismissed)) {
LogService.deprecationWarn({component: 'Dialog', oldProp: 'onModalDismissed', newProp: 'onDialogDismissed'});
}
}

componentDidMount() {
Expand Down Expand Up @@ -137,9 +146,20 @@ class Dialog extends BaseComponent {
onDismiss = () => {
this.setState({modalVisibility: false}, () => {
const props = this.getThemeProps();
_.invoke(props, 'onDismiss', props);
if (props.visible) {
_.invoke(props, 'onDismiss', props);
}
// Parity with iOS Modal's onDismiss
if (Constants.isAndroid) {
_.invoke(props, 'onDialogDismissed', props);
}
});
};

onModalDismissed = () => {
_.invoke(this.props, 'onDialogDismissed', this.props);
_.invoke(this.props, 'onModalDismissed', this.props);
}

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

render = () => {
const {orientationKey, modalVisibility} = this.state;
const {overlayBackgroundColor, onModalDismissed, supportedOrientations, accessibilityLabel} = this.getThemeProps();
const {overlayBackgroundColor, supportedOrientations, accessibilityLabel} = this.getThemeProps();

return (
<Modal
Expand All @@ -208,7 +228,7 @@ class Dialog extends BaseComponent {
onBackgroundPress={this.hideDialogView}
onRequestClose={this.hideDialogView}
overlayBackgroundColor={overlayBackgroundColor}
onDismiss={onModalDismissed}
onDismiss={this.onModalDismissed}
supportedOrientations={supportedOrientations}
accessibilityLabel={accessibilityLabel}
>
Expand Down