Add onShow callback for RCTModalHostView

Summary: Added ability to include a callback to the modal. The callback is invoked when the modal is shown.

Reviewed By: javache

Differential Revision: D3005212

fb-gh-sync-id: 12648e17bd1cf831daf65529b87ae8cfdb901c65
shipit-source-id: 12648e17bd1cf831daf65529b87ae8cfdb901c65
This commit is contained in:
Eric Lo 2016-03-03 12:42:41 -08:00 committed by Facebook Github Bot 9
parent 44997b47e2
commit 8c25181c44
4 changed files with 11 additions and 1 deletions

View File

@ -49,6 +49,7 @@ class Modal extends React.Component {
animated={this.props.animated}
transparent={this.props.transparent}
onDismiss={this.props.onDismiss}
onShow={this.props.onShow}
style={styles.modal}>
<View style={[styles.container, containerBackgroundColor]}>
{this.props.children}
@ -63,6 +64,7 @@ Modal.propTypes = {
transparent: PropTypes.bool,
visible: PropTypes.bool,
onDismiss: PropTypes.func,
onShow: PropTypes.func,
};
Modal.defaultProps = {

View File

@ -10,6 +10,7 @@
#import <UIKit/UIKit.h>
#import "RCTInvalidating.h"
#import "RCTView.h"
@class RCTBridge;
@ -18,6 +19,8 @@
@property (nonatomic, assign, getter=isAnimated) BOOL animated;
@property (nonatomic, assign, getter=isTransparent) BOOL transparent;
@property (nonatomic, copy) RCTDirectEventBlock onShow;
- (instancetype)initWithBridge:(RCTBridge *)bridge NS_DESIGNATED_INITIALIZER;
@end

View File

@ -86,7 +86,11 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:coder)
if (!_isPresented && self.window) {
RCTAssert(self.reactViewController, @"Can't present modal view controller without a presenting view controller");
[self.reactViewController presentViewController:_modalViewController animated:self.animated completion:nil];
[self.reactViewController presentViewController:_modalViewController animated:self.animated completion:^{
if (_onShow) {
_onShow(nil);
}
}];
_isPresented = YES;
}
}

View File

@ -40,5 +40,6 @@ RCT_EXPORT_MODULE()
RCT_EXPORT_VIEW_PROPERTY(animated, BOOL)
RCT_EXPORT_VIEW_PROPERTY(transparent, BOOL)
RCT_EXPORT_VIEW_PROPERTY(onShow, RCTDirectEventBlock)
@end