2015-03-23 20:28:42 +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.
|
|
|
|
*/
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
#import "RCTViewManager.h"
|
|
|
|
|
2015-03-01 23:33:55 +00:00
|
|
|
#import "RCTBridge.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTConvert.h"
|
|
|
|
#import "RCTEventDispatcher.h"
|
|
|
|
#import "RCTLog.h"
|
|
|
|
#import "RCTShadowView.h"
|
2015-04-18 17:43:20 +00:00
|
|
|
#import "RCTUIManager.h"
|
2015-03-01 23:33:55 +00:00
|
|
|
#import "RCTUtils.h"
|
2015-02-20 04:10:52 +00:00
|
|
|
#import "RCTView.h"
|
|
|
|
|
|
|
|
@implementation RCTViewManager
|
|
|
|
|
2015-04-08 12:42:43 +00:00
|
|
|
@synthesize bridge = _bridge;
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-04-08 15:52:48 +00:00
|
|
|
RCT_EXPORT_MODULE()
|
|
|
|
|
2015-04-18 17:43:20 +00:00
|
|
|
- (dispatch_queue_t)methodQueue
|
|
|
|
{
|
|
|
|
return [_bridge.uiManager methodQueue];
|
|
|
|
}
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
- (UIView *)view
|
|
|
|
{
|
|
|
|
return [[RCTView alloc] init];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (RCTShadowView *)shadowView
|
|
|
|
{
|
|
|
|
return [[RCTShadowView alloc] init];
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
- (NSDictionary *)customBubblingEventTypes
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
- (NSDictionary *)customDirectEventTypes
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-03-01 23:33:55 +00:00
|
|
|
- (NSDictionary *)constantsToExport
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2015-03-17 14:04:39 +00:00
|
|
|
#pragma mark - View properties
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_VIEW_PROPERTY(accessibilityLabel, NSString)
|
|
|
|
RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(accessible, isAccessibilityElement, BOOL)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier, NSString)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(opacity, alpha, CGFloat)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(shadowColor, layer.shadowColor, CGColor);
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(shadowOffset, layer.shadowOffset, CGSize);
|
2015-04-01 00:34:51 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity, float)
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius, CGFloat)
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(transformMatrix, layer.transform, CATransform3D)
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(overflow, css_overflow, RCTView)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
view.clipsToBounds = json ? ![RCTConvert css_overflow:json] : defaultView.clipsToBounds;
|
|
|
|
}
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTPointerEvents, RCTView)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
|
|
|
if ([view respondsToSelector:@selector(setPointerEvents:)]) {
|
|
|
|
view.pointerEvents = json ? [RCTConvert RCTPointerEvents:json] : defaultView.pointerEvents;
|
|
|
|
return;
|
|
|
|
}
|
2015-03-01 23:33:55 +00:00
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
if (!json) {
|
|
|
|
view.userInteractionEnabled = defaultView.userInteractionEnabled;
|
|
|
|
return;
|
|
|
|
}
|
2015-03-01 23:33:55 +00:00
|
|
|
|
2015-03-25 00:37:03 +00:00
|
|
|
switch ([RCTConvert RCTPointerEvents:json]) {
|
2015-02-20 04:10:52 +00:00
|
|
|
case RCTPointerEventsUnspecified:
|
|
|
|
// Pointer events "unspecified" acts as if a stylesheet had not specified,
|
|
|
|
// which is different than "auto" in CSS (which cannot and will not be
|
2015-03-26 09:58:06 +00:00
|
|
|
// supported in `React`. "auto" may override a parent's "none".
|
2015-02-20 04:10:52 +00:00
|
|
|
// Unspecified values do not.
|
|
|
|
// This wouldn't override a container view's `userInteractionEnabled = NO`
|
|
|
|
view.userInteractionEnabled = YES;
|
|
|
|
case RCTPointerEventsNone:
|
|
|
|
view.userInteractionEnabled = NO;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
RCTLogError(@"UIView base class does not support pointerEvent value: %@", json);
|
|
|
|
}
|
|
|
|
}
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(removeClippedSubviews, BOOL, RCTView)
|
2015-03-25 00:37:03 +00:00
|
|
|
{
|
|
|
|
if ([view respondsToSelector:@selector(setRemoveClippedSubviews:)]) {
|
|
|
|
view.removeClippedSubviews = json ? [RCTConvert BOOL:json] : defaultView.removeClippedSubviews;
|
|
|
|
}
|
|
|
|
}
|
2015-03-26 08:43:17 +00:00
|
|
|
RCT_REMAP_VIEW_PROPERTY(borderRadius, layer.cornerRadius, CGFloat)
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(borderColor, CGColor, RCTView)
|
|
|
|
{
|
|
|
|
if ([view respondsToSelector:@selector(setBorderColor:)]) {
|
|
|
|
view.borderColor = json ? [RCTConvert CGColor:json] : defaultView.borderColor;
|
|
|
|
} else {
|
|
|
|
view.layer.borderColor = json ? [RCTConvert CGColor:json] : defaultView.layer.borderColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(borderWidth, CGFloat, RCTView)
|
|
|
|
{
|
|
|
|
if ([view respondsToSelector:@selector(setBorderWidth:)]) {
|
|
|
|
view.borderWidth = json ? [RCTConvert CGFloat:json] : defaultView.borderWidth;
|
|
|
|
} else {
|
|
|
|
view.layer.borderWidth = json ? [RCTConvert CGFloat:json] : defaultView.layer.borderWidth;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define RCT_VIEW_BORDER_PROPERTY(SIDE) \
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Width, CGFloat, RCTView) \
|
|
|
|
{ \
|
|
|
|
if ([view respondsToSelector:@selector(setBorder##SIDE##Width:)]) { \
|
|
|
|
view.border##SIDE##Width = json ? [RCTConvert CGFloat:json] : defaultView.border##SIDE##Width; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
RCT_CUSTOM_VIEW_PROPERTY(border##SIDE##Color, UIColor, RCTView) \
|
|
|
|
{ \
|
|
|
|
if ([view respondsToSelector:@selector(setBorder##SIDE##Color:)]) { \
|
|
|
|
view.border##SIDE##Color = json ? [RCTConvert CGColor:json] : defaultView.border##SIDE##Color; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
RCT_VIEW_BORDER_PROPERTY(Top)
|
|
|
|
RCT_VIEW_BORDER_PROPERTY(Right)
|
|
|
|
RCT_VIEW_BORDER_PROPERTY(Bottom)
|
|
|
|
RCT_VIEW_BORDER_PROPERTY(Left)
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-17 14:04:39 +00:00
|
|
|
#pragma mark - ShadowView properties
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-26 04:29:28 +00:00
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(top, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(right, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(bottom, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(left, CGFloat);
|
|
|
|
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(width, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(height, CGFloat);
|
|
|
|
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(borderTopWidth, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(borderRightWidth, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(borderBottomWidth, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(borderLeftWidth, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(borderWidth, CGFloat);
|
|
|
|
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginTop, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginRight, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginBottom, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginLeft, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginVertical, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(marginHorizontal, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(margin, CGFloat);
|
|
|
|
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingTop, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingRight, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingBottom, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingLeft, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingVertical, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(paddingHorizontal, CGFloat);
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(padding, CGFloat);
|
|
|
|
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(flex, CGFloat)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(flexDirection, css_flex_direction_t)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(flexWrap, css_wrap_type_t)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(justifyContent, css_justify_t)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(alignItems, css_align_t)
|
|
|
|
RCT_EXPORT_SHADOW_PROPERTY(alignSelf, css_align_t)
|
|
|
|
RCT_REMAP_SHADOW_PROPERTY(position, positionType, css_position_type_t)
|
|
|
|
|
|
|
|
RCT_CUSTOM_SHADOW_PROPERTY(backgroundColor, UIColor, RCTShadowView)
|
2015-02-20 04:10:52 +00:00
|
|
|
{
|
2015-03-01 23:33:55 +00:00
|
|
|
view.backgroundColor = json ? [RCTConvert UIColor:json] : defaultView.backgroundColor;
|
|
|
|
view.isBGColorExplicitlySet = json ? YES : defaultView.isBGColorExplicitlySet;
|
2015-02-20 04:10:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|