2015-07-28 14:31:26 +00: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 23:50:23 +00:00
|
|
|
#import "RCTModalHostViewController.h"
|
2016-04-21 15:56:46 +00:00
|
|
|
#import "RCTShadowView.h"
|
|
|
|
#import "RCTUtils.h"
|
|
|
|
|
2017-06-21 02:02:27 +00: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 15:56:46 +00: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 20:59:26 +00:00
|
|
|
((RCTShadowView *)subview).size = RCTScreenSize();
|
2016-04-21 15:56:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2016-08-23 23:50:23 +00:00
|
|
|
@interface RCTModalHostViewManager () <RCTModalHostViewInteractor>
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
@implementation RCTModalHostViewManager
|
2015-08-13 16:09:10 +00:00
|
|
|
{
|
|
|
|
NSHashTable *_hostViews;
|
|
|
|
}
|
2015-07-28 14:31:26 +00:00
|
|
|
|
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
|
|
|
- (UIView *)view
|
|
|
|
{
|
2016-08-23 23:50:23 +00:00
|
|
|
RCTModalHostView *view = [[RCTModalHostView alloc] initWithBridge:self.bridge];
|
|
|
|
view.delegate = self;
|
2016-08-08 22:53:53 +00:00
|
|
|
if (!_hostViews) {
|
2015-11-25 11:09:00 +00:00
|
|
|
_hostViews = [NSHashTable weakObjectsHashTable];
|
|
|
|
}
|
2015-08-13 16:09:10 +00:00
|
|
|
[_hostViews addObject:view];
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:50:23 +00: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
|
|
|
|
{
|
|
|
|
if (_dismissalBlock) {
|
|
|
|
_dismissalBlock([modalHostView reactViewController], viewController, animated, nil);
|
|
|
|
} else {
|
|
|
|
[viewController dismissViewControllerAnimated:animated completion:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-04-21 15:56:46 +00:00
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [RCTModalHostShadowView new];
|
|
|
|
}
|
|
|
|
|
2015-08-13 16:09:10 +00:00
|
|
|
- (void)invalidate
|
|
|
|
{
|
|
|
|
for (RCTModalHostView *hostView in _hostViews) {
|
|
|
|
[hostView invalidate];
|
|
|
|
}
|
|
|
|
[_hostViews removeAllObjects];
|
2015-07-28 14:31:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-28 22:59:11 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(animationType, NSString)
|
2017-06-21 02:02:27 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(presentationStyle, UIModalPresentationStyle)
|
2015-08-13 16:09:10 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(transparent, BOOL)
|
2016-03-03 20:42:41 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onShow, RCTDirectEventBlock)
|
2016-09-07 13:06:12 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(supportedOrientations, NSArray)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onOrientationChange, RCTDirectEventBlock)
|
2015-07-28 14:31:26 +00:00
|
|
|
|
2017-08-17 22:05:26 +00:00
|
|
|
#if TARGET_OS_TV
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(onRequestClose, RCTDirectEventBlock)
|
|
|
|
#endif
|
|
|
|
|
2015-07-28 14:31:26 +00:00
|
|
|
@end
|