Skip to content

Commit

Permalink
Revert D19235758: Implement onRequestClose for iOS 13+ modals
Browse files Browse the repository at this point in the history
Differential Revision:
D19235758

Original commit changeset: c0f1d946c77c

fbshipit-source-id: c4a9d7876aa8d07ff5b8419f097b02e9c28e2880
  • Loading branch information
shergin authored and facebook-github-bot committed Feb 6, 2020
1 parent 1e9db7b commit ed11a12
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 38 deletions.
3 changes: 1 addition & 2 deletions Libraries/Modal/Modal.js
Expand Up @@ -95,8 +95,7 @@ export type Props = $ReadOnly<{|

/**
* The `onRequestClose` callback is called when the user taps the hardware
* back button on Android, the menu button on Apple TV, or a modal is dismissed
* with a gesture on iOS 13+.
* back button on Android or the menu button on Apple TV.
*
* This is required on Apple TV and Android.
*
Expand Down
3 changes: 1 addition & 2 deletions Libraries/Modal/RCTModalHostViewNativeComponent.js
Expand Up @@ -70,8 +70,7 @@ type NativeProps = $ReadOnly<{|

/**
* The `onRequestClose` callback is called when the user taps the hardware
* back button on Android, the menu button on Apple TV, or a modal is dismissed
* with a gesture on iOS 13+.
* back button on Android or the menu button on Apple TV.
*
* This is required on Apple TV and Android.
*
Expand Down
Expand Up @@ -94,9 +94,7 @@ static UIModalPresentationStyle presentationConfiguration(ModalHostViewProps con
return {orientation};
}

@interface RCTModalHostViewComponentView () <
RCTFabricModalHostViewControllerDelegate,
UIAdaptivePresentationControllerDelegate>
@interface RCTModalHostViewComponentView () <RCTFabricModalHostViewControllerDelegate>

@end

Expand All @@ -115,7 +113,6 @@ - (instancetype)initWithFrame:(CGRect)frame
_viewController = [RCTFabricModalHostViewController new];
_viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
_viewController.delegate = self;
_viewController.presentationController.delegate = self;
}

return self;
Expand Down Expand Up @@ -220,19 +217,6 @@ - (void)unmountChildComponentView:(UIView<RCTComponentViewProtocol> *)childCompo
[childComponentView removeFromSuperview];
}

#pragma mark - UIAdaptivePresentationControllerDelegate

- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
{
if (!_eventEmitter) {
return;
}

assert(std::dynamic_pointer_cast<ModalHostViewEventEmitter const>(_eventEmitter));
auto eventEmitter = std::static_pointer_cast<ModalHostViewEventEmitter const>(_eventEmitter);
eventEmitter->onRequestClose({});
}

@end

Class<RCTComponentViewProtocol> RCTModalHostViewCls(void)
Expand Down
3 changes: 1 addition & 2 deletions React/Views/RCTModalHostView.h
Expand Up @@ -32,9 +32,8 @@
@property (nonatomic, copy) NSArray<NSString *> *supportedOrientations;
@property (nonatomic, copy) RCTDirectEventBlock onOrientationChange;

@property (nonatomic, copy) RCTDirectEventBlock onRequestClose;

#if TARGET_OS_TV
@property (nonatomic, copy) RCTDirectEventBlock onRequestClose;
@property (nonatomic, strong) RCTTVRemoteHandler *tvRemoteHandler;
#endif

Expand Down
16 changes: 1 addition & 15 deletions React/Views/RCTModalHostView.m
Expand Up @@ -20,10 +20,6 @@
#import "RCTTVRemoteHandler.h"
#endif

@interface RCTModalHostView () <UIAdaptivePresentationControllerDelegate>

@end

@implementation RCTModalHostView
{
__weak RCTBridge *_bridge;
Expand All @@ -50,7 +46,6 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
UIView *containerView = [UIView new];
containerView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
_modalViewController.view = containerView;
_modalViewController.presentationController.delegate = self;
_touchHandler = [[RCTTouchHandler alloc] initWithBridge:bridge];
#if TARGET_OS_TV
_menuButtonGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(menuButtonPressed:)];
Expand All @@ -75,21 +70,19 @@ - (void)menuButtonPressed:(__unused UIGestureRecognizer *)gestureRecognizer
_onRequestClose(nil);
}
}
#endif

- (void)setOnRequestClose:(RCTDirectEventBlock)onRequestClose
{
_onRequestClose = onRequestClose;
#if TARGET_OS_TV
if (_reactSubview) {
if (_onRequestClose && _menuButtonGestureRecognizer) {
[_reactSubview addGestureRecognizer:_menuButtonGestureRecognizer];
} else {
[_reactSubview removeGestureRecognizer:_menuButtonGestureRecognizer];
}
}
#endif
}
#endif

- (void)notifyForBoundsChange:(CGRect)newBounds
{
Expand Down Expand Up @@ -264,11 +257,4 @@ - (UIInterfaceOrientationMask)supportedOrientationsMask
}
#endif

- (void)presentationControllerDidDismiss:(UIPresentationController *)presentationController
{
if (_onRequestClose) {
_onRequestClose(nil);
}
}

@end
3 changes: 3 additions & 0 deletions React/Views/RCTModalHostViewManager.m
Expand Up @@ -108,6 +108,9 @@ - (void)invalidate
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber)
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray)
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock)

#if TARGET_OS_TV
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
#endif

@end

1 comment on commit ed11a12

@jacobp100
Copy link
Contributor

Choose a reason for hiding this comment

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

Out of interest, what was broken with this?

Please sign in to comment.