Skip to content

Commit caea1da

Browse files
committed
Dialog - RN63 broke Modal's onDismiss method, this fixes our API (wix#1026)
* Dialog - RN63 broke Modal's onDismiss method, this fixes our API * Send onFadeDone only to iOS * Add a TODO (cherry picked from commit 7ee9fc1)
1 parent 8b27cf9 commit caea1da

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

generatedTypes/components/dialog/OverlayFadingBackground.d.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@ interface Props {
44
dialogVisibility?: boolean;
55
modalVisibility?: boolean;
66
overlayBackgroundColor?: string;
7+
onFadeDone?: () => void;
78
}
89
declare const OverlayFadingBackground: {
9-
({ testID, dialogVisibility, modalVisibility, overlayBackgroundColor }: Props): JSX.Element;
10+
({ testID, dialogVisibility, modalVisibility, overlayBackgroundColor, onFadeDone }: Props): JSX.Element;
1011
displayName: string;
1112
};
1213
export default OverlayFadingBackground;

src/components/dialog/OverlayFadingBackground.tsx

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@ interface Props {
77
dialogVisibility?: boolean;
88
modalVisibility?: boolean;
99
overlayBackgroundColor?: string;
10+
onFadeDone?: () => void;
1011
}
1112

1213
const OverlayFadingBackground = ({
1314
testID,
1415
dialogVisibility,
1516
modalVisibility,
16-
overlayBackgroundColor
17+
overlayBackgroundColor,
18+
onFadeDone
1719
}: Props) => {
1820
const fadeAnimation = useRef(new Animated.Value(0)).current;
1921

@@ -22,8 +24,8 @@ const OverlayFadingBackground = ({
2224
toValue,
2325
duration: 400,
2426
useNativeDriver: true
25-
}).start();
26-
}, [fadeAnimation]);
27+
}).start(onFadeDone);
28+
}, [fadeAnimation, onFadeDone]);
2729

2830
useEffect(() => {
2931
if (!dialogVisibility) {

src/components/dialog/index.tsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ class Dialog extends Component<DialogProps, DialogState> {
161161
}
162162
}
163163

164+
// TODO: revert adding this workaround once RN fixes https://github.com/facebook/react-native/issues/29455
165+
onFadeDone = () => {
166+
if (!this.state.modalVisibility) {
167+
setTimeout(() => { // unfortunately this is needed if a modal needs to open on iOS
168+
_.invoke(this.props, 'onDialogDismissed', this.props);
169+
_.invoke(this.props, 'onModalDismissed', this.props);
170+
}, 50);
171+
}
172+
}
173+
164174
onDismiss = () => {
165175
this.setState({modalVisibility: false}, () => {
166176
const props = this.props;
@@ -221,6 +231,7 @@ class Dialog extends Component<DialogProps, DialogState> {
221231
const {useSafeArea, bottom, overlayBackgroundColor, testID} = this.props;
222232
const addBottomSafeArea = Constants.isIphoneX && (useSafeArea && bottom);
223233
const bottomInsets = Constants.getSafeAreaInsets().bottom - 8; // TODO: should this be here or in the input style?
234+
const onFadeDone = Constants.isIOS ? this.onFadeDone : undefined;
224235

225236
return (
226237
<View
@@ -233,6 +244,7 @@ class Dialog extends Component<DialogProps, DialogState> {
233244
modalVisibility={modalVisibility}
234245
dialogVisibility={dialogVisibility}
235246
overlayBackgroundColor={overlayBackgroundColor}
247+
onFadeDone={onFadeDone}
236248
/>
237249
{this.renderDialogView()}
238250
{addBottomSafeArea && <View style={{marginTop: bottomInsets}}/>}
@@ -253,7 +265,7 @@ class Dialog extends Component<DialogProps, DialogState> {
253265
animationType={'none'}
254266
onBackgroundPress={this.hideDialogView}
255267
onRequestClose={this.hideDialogView}
256-
onDismiss={this.onModalDismissed}
268+
// onDismiss={this.onModalDismissed}
257269
supportedOrientations={supportedOrientations}
258270
accessibilityLabel={accessibilityLabel}
259271
>

0 commit comments

Comments
 (0)