2015-07-28 07:31:26 -07:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import "RCTModalHostViewManager.h"
|
|
|
|
|
|
|
|
#import "RCTBridge.h"
|
|
|
|
#import "RCTModalHostView.h"
|
2016-08-23 16:50:23 -07:00
|
|
|
#import "RCTModalHostViewController.h"
|
2017-09-21 14:46:42 -07:00
|
|
|
#import "RCTModalManager.h"
|
2016-04-21 08:56:46 -07:00
|
|
|
#import "RCTShadowView.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
2017-06-20 19:02:27 -07:00
|
|
|
@implementation RCTConvert (RCTModalHostView)
|
|
|
|
|
|
|
|
RCT_ENUM_CONVERTER(UIModalPresentationStyle, (@{
|
|
|
|
@"fullScreen": @(UIModalPresentationFullScreen),
|
|
|
|
#if !TARGET_OS_TV
|
|
|
|
@"pageSheet": @(UIModalPresentationPageSheet),
|
|
|
|
@"formSheet": @(UIModalPresentationFormSheet),
|
|
|
|
#endif
|
|
|
|
@"overFullScreen": @(UIModalPresentationOverFullScreen),
|
|
|
|
}), UIModalPresentationFullScreen, integerValue)
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2016-04-21 08:56:46 -07:00
|
|
|
@interface RCTModalHostShadowView : RCTShadowView
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation RCTModalHostShadowView
|
|
|
|
|
|
|
|
- (void)insertReactSubview:(id<RCTComponent>)subview atIndex:(NSInteger)atIndex
|
|
|
|
{
|
|
|
|
[super insertReactSubview:subview atIndex:atIndex];
|
|
|
|
if ([subview isKindOfClass:[RCTShadowView class]]) {
|
Deprecating/removing `setFrame`, `setLeftTop`, and co.
Summary:
Motivation:
* `RCTShadowView`'s `frame` property actually represents computed layout of the view. We must not use it as a setter for yoga node styles;
* Using `frame` and `setLeftTop` in existing way actually works only for view with absolute positioning, so it is super rare and special case;
* Internally, setting `frame` only make sense to `RootView`, and in that case there we always must not change `origin` we are introducing `setSize` method.
Changes:
* `[-RCTShadowView setFrame:]` was removed, `frame` property is readonly now;
* `[-RCTShadowView setLeftTop:]` was removed; no replacement provided;
* `[-RCTShadowView size]` read-write property was added;
* `[-RCTUIManager setFrame:forView:]` was deprecated, use (just introduced) `setSize:forView:` instead;
* `[-RCTUIManager setSize:forView:]` was added.
If you are still need some of removed methods, you are probably doing something wrong. Consider using `setIntrinsicContentSize`-family methods,
`setSize`-family methods, or (in the worst case) accessing `yogaNode` directly.
Reviewed By: javache
Differential Revision: D4491384
fbshipit-source-id: 56dd84567324c5a86e4c870a41c38322dc1224d2
2017-02-01 12:59:26 -08:00
|
|
|
((RCTShadowView *)subview).size = RCTScreenSize();
|
2016-04-21 08:56:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2015-07-28 07:31:26 -07:00
|
|
|
|
2016-08-23 16:50:23 -07:00
|
|
|
@interface RCTModalHostViewManager () <RCTModalHostViewInteractor>
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-07-28 07:31:26 -07:00
|
|
|
@implementation RCTModalHostViewManager
|
2015-08-13 15:09:10 -01:00
|
|
|
{
|
|
|
|
NSHashTable *_hostViews;
|
|
|
|
}
|
2015-07-28 07:31:26 -07:00
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
|
|
|
- (UIView *)view
|
|
|
|
{
|
2016-08-23 16:50:23 -07:00
|
|
|
RCTModalHostView *view = [[RCTModalHostView alloc] initWithBridge:self.bridge];
|
|
|
|
view.delegate = self;
|
2016-08-08 15:53:53 -07:00
|
|
|
if (!_hostViews) {
|
2015-11-25 03:09:00 -08:00
|
|
|
_hostViews = [NSHashTable weakObjectsHashTable];
|
|
|
|
}
|
2015-08-13 15:09:10 -01:00
|
|
|
[_hostViews addObject:view];
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2016-08-23 16:50:23 -07:00
|
|
|
- (void)presentModalHostView:(RCTModalHostView *)modalHostView withViewController:(RCTModalHostViewController *)viewController animated:(BOOL)animated
|
|
|
|
{
|
|
|
|
dispatch_block_t completionBlock = ^{
|
|
|
|
if (modalHostView.onShow) {
|
|
|
|
modalHostView.onShow(nil);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
if (_presentationBlock) {
|
|
|
|
_presentationBlock([modalHostView reactViewController], viewController, animated, completionBlock);
|
|
|
|
} else {
|
|
|
|
[[modalHostView reactViewController] presentViewController:viewController animated:animated completion:completionBlock];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)dismissModalHostView:(RCTModalHostView *)modalHostView withViewController:(RCTModalHostViewController *)viewController animated:(BOOL)animated
|
|
|
|
{
|
2017-09-21 14:46:42 -07:00
|
|
|
dispatch_block_t completionBlock = ^{
|
|
|
|
if (modalHostView.identifier) {
|
|
|
|
[[self.bridge moduleForClass:[RCTModalManager class]] modalDismissed:modalHostView.identifier];
|
|
|
|
}
|
|
|
|
};
|
2016-08-23 16:50:23 -07:00
|
|
|
if (_dismissalBlock) {
|
2017-09-21 14:46:42 -07:00
|
|
|
_dismissalBlock([modalHostView reactViewController], viewController, animated, completionBlock);
|
2016-08-23 16:50:23 -07:00
|
|
|
} else {
|
2017-09-21 14:46:42 -07:00
|
|
|
[viewController dismissViewControllerAnimated:animated completion:completionBlock];
|
2016-08-23 16:50:23 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-21 08:56:46 -07:00
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [RCTModalHostShadowView new];
|
|
|
|
}
|
|
|
|
|
2015-08-13 15:09:10 -01:00
|
|
|
- (void)invalidate
|
|
|
|
{
|
|
|
|
for (RCTModalHostView *hostView in _hostViews) {
|
|
|
|
[hostView invalidate];
|
|
|
|
}
|
|
|
|
[_hostViews removeAllObjects];
|
2015-07-28 07:31:26 -07:00
|
|
|
}
|
|
|
|
|
2016-04-28 15:59:11 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(animationType, NSString)
|
2017-06-20 19:02:27 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(presentationStyle, UIModalPresentationStyle)
|
2015-08-13 15:09:10 -01:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(transparent, BOOL)
|
2016-03-03 12:42:41 -08:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onShow, RCTDirectEventBlock)
|
2017-09-21 14:46:42 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(identifier, NSNumber)
|
2016-09-07 06:06:12 -07:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock)
|
2015-07-28 07:31:26 -07:00
|
|
|
|
2017-08-17 15:05:26 -07:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
|
|
|
|
#endif
|
|
|
|
|
2015-07-28 07:31:26 -07:00
|
|
|
@end
|