Skip to content

Commit bd2b7d6

Browse files
sammy-SCfacebook-github-bot
authored andcommitted
Fix onDismiss in Modal
Summary: # Disclaimer: I might be missing something as the solution I implemented here seems like something that was considered by original author. If this solution isn't good, I have a plan B. # Problem: `onDismiss` prop isn't being called once the modal is dismissed, this diff fixes it. Also I've noticed that `onDismiss` is meant to only work on iOS, why is that? By landing this diff, it'll be called on Android as well so we need to change the docs (https://facebook.github.io/react-native/docs/modal.html#ondismiss). ## Video that shows the problem Following code is in playground.js P70222409 which just increments number everytime onDismiss is called {F166303269} Reviewed By: shergin Differential Revision: D16109536 fbshipit-source-id: 3fba56f5671912387b217f03b613dffd89614c9d
1 parent 5ec382d commit bd2b7d6

File tree

5 files changed

+4
-97
lines changed

5 files changed

+4
-97
lines changed

Libraries/Modal/Modal.js

+2-22
Original file line numberDiff line numberDiff line change
@@ -12,20 +12,13 @@
1212

1313
const AppContainer = require('../ReactNative/AppContainer');
1414
const I18nManager = require('../ReactNative/I18nManager');
15-
const NativeEventEmitter = require('../EventEmitter/NativeEventEmitter');
16-
import NativeModalManager from './NativeModalManager';
17-
const Platform = require('../Utilities/Platform');
1815
const React = require('react');
1916
const PropTypes = require('prop-types');
2017
const ScrollView = require('../Components/ScrollView/ScrollView');
2118
const StyleSheet = require('../StyleSheet/StyleSheet');
2219
const View = require('../Components/View/View');
2320

2421
import RCTModalHostView from './RCTModalHostViewNativeComponent';
25-
const ModalEventEmitter =
26-
Platform.OS === 'ios' && NativeModalManager != null
27-
? new NativeEventEmitter(NativeModalManager)
28-
: null;
2922

3023
import type EmitterSubscription from '../vendor/emitter/EmitterSubscription';
3124
import type {ViewProps} from '../Components/View/ViewPropTypes';
@@ -175,22 +168,9 @@ class Modal extends React.Component<Props> {
175168
};
176169
}
177170

178-
componentDidMount() {
179-
if (ModalEventEmitter) {
180-
this._eventSubscription = ModalEventEmitter.addListener(
181-
'modalDismissed',
182-
event => {
183-
if (event.modalID === this._identifier && this.props.onDismiss) {
184-
this.props.onDismiss();
185-
}
186-
},
187-
);
188-
}
189-
}
190-
191171
componentWillUnmount() {
192-
if (this._eventSubscription) {
193-
this._eventSubscription.remove();
172+
if (this.props.onDismiss != null) {
173+
this.props.onDismiss();
194174
}
195175
}
196176

Libraries/Modal/RCTModalHostViewNativeComponent.js

-8
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,6 @@ type NativeProps = $ReadOnly<{|
7878
*/
7979
onShow?: ?DirectEventHandler<null>,
8080

81-
/**
82-
* The `onDismiss` prop allows passing a function that will be called once
83-
* the modal has been dismissed.
84-
*
85-
* See https://facebook.github.io/react-native/docs/modal.html#ondismiss
86-
*/
87-
onDismiss?: ?BubblingEventHandler<null>,
88-
8981
/**
9082
* Deprecated. Use the `animationType` prop instead.
9183
*/

React/Views/RCTModalHostViewManager.m

+2-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#import "RCTBridge.h"
1111
#import "RCTModalHostView.h"
1212
#import "RCTModalHostViewController.h"
13-
#import "RCTModalManager.h"
1413
#import "RCTShadowView.h"
1514
#import "RCTUtils.h"
1615

@@ -81,15 +80,10 @@ - (void)presentModalHostView:(RCTModalHostView *)modalHostView withViewControlle
8180

8281
- (void)dismissModalHostView:(RCTModalHostView *)modalHostView withViewController:(RCTModalHostViewController *)viewController animated:(BOOL)animated
8382
{
84-
dispatch_block_t completionBlock = ^{
85-
if (modalHostView.identifier) {
86-
[[self.bridge moduleForClass:[RCTModalManager class]] modalDismissed:modalHostView.identifier];
87-
}
88-
};
8983
if (_dismissalBlock) {
90-
_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
84+
_dismissalBlock([modalHostView reactViewController], viewController, animated, nil);
9185
} else {
92-
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:completionBlock];
86+
[viewController.presentingViewController dismissViewControllerAnimated:animated completion:nil];
9387
}
9488
}
9589

React/Views/RCTModalManager.h

-17
This file was deleted.

React/Views/RCTModalManager.m

-42
This file was deleted.

0 commit comments

Comments
 (0)