Skip to content

Dialog - RN63 broke Modal's onDismiss method, this fixes our API #1026

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 3 commits into from
Nov 11, 2020
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ interface Props {
dialogVisibility?: boolean;
modalVisibility?: boolean;
overlayBackgroundColor?: string;
onFadeDone?: () => void;
}
declare const OverlayFadingBackground: {
({ testID, dialogVisibility, modalVisibility, overlayBackgroundColor }: Props): JSX.Element;
({ testID, dialogVisibility, modalVisibility, overlayBackgroundColor, onFadeDone }: Props): JSX.Element;
displayName: string;
};
export default OverlayFadingBackground;
8 changes: 5 additions & 3 deletions src/components/dialog/OverlayFadingBackground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ interface Props {
dialogVisibility?: boolean;
modalVisibility?: boolean;
overlayBackgroundColor?: string;
onFadeDone?: () => void;
}

const OverlayFadingBackground = ({
testID,
dialogVisibility,
modalVisibility,
overlayBackgroundColor
overlayBackgroundColor,
onFadeDone
}: Props) => {
const fadeAnimation = useRef(new Animated.Value(0)).current;

Expand All @@ -22,8 +24,8 @@ const OverlayFadingBackground = ({
toValue,
duration: 400,
useNativeDriver: true
}).start();
}, [fadeAnimation]);
}).start(onFadeDone);
}, [fadeAnimation, onFadeDone]);

useEffect(() => {
if (!dialogVisibility) {
Expand Down
14 changes: 13 additions & 1 deletion src/components/dialog/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@ class Dialog extends Component<DialogProps, DialogState> {
}
}

// TODO: revert adding this workaround once RN fixes https://github.com/facebook/react-native/issues/29455
onFadeDone = () => {
if (!this.state.modalVisibility) {
setTimeout(() => { // unfortunately this is needed if a modal needs to open on iOS
_.invoke(this.props, 'onDialogDismissed', this.props);
_.invoke(this.props, 'onModalDismissed', this.props);
}, 50);
}
}

onDismiss = () => {
this.setState({modalVisibility: false}, () => {
const props = this.props;
Expand Down Expand Up @@ -221,6 +231,7 @@ class Dialog extends Component<DialogProps, DialogState> {
const {useSafeArea, bottom, overlayBackgroundColor, testID} = this.props;
const addBottomSafeArea = Constants.isIphoneX && (useSafeArea && bottom);
const bottomInsets = Constants.getSafeAreaInsets().bottom - 8; // TODO: should this be here or in the input style?
const onFadeDone = Constants.isIOS ? this.onFadeDone : undefined;

return (
<View
Expand All @@ -233,6 +244,7 @@ class Dialog extends Component<DialogProps, DialogState> {
modalVisibility={modalVisibility}
dialogVisibility={dialogVisibility}
overlayBackgroundColor={overlayBackgroundColor}
onFadeDone={onFadeDone}
/>
{this.renderDialogView()}
{addBottomSafeArea && <View style={{marginTop: bottomInsets}}/>}
Expand All @@ -253,7 +265,7 @@ class Dialog extends Component<DialogProps, DialogState> {
animationType={'none'}
onBackgroundPress={this.hideDialogView}
onRequestClose={this.hideDialogView}
onDismiss={this.onModalDismissed}
// onDismiss={this.onModalDismissed}
supportedOrientations={supportedOrientations}
accessibilityLabel={accessibilityLabel}
>
Expand Down