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 alloy committed Feb 25, 2020
1 parent 360b53d commit 8aeb5dc
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ static ModalHostViewOnOrientationChangeStruct onOrientationChangeStruct(CGRect r
return {orientation};
}

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

@end

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

return self;
Expand Down Expand Up @@ -217,17 +214,4 @@ - (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
3 changes: 1 addition & 2 deletions React/Views/RCTModalHostView.h
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 8aeb5dc

Please sign in to comment.