react-native/ReactKit/Views/RCTViewManager.m

170 lines
5.2 KiB
Mathematica
Raw Normal View History

/**
* 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 "RCTViewManager.h"
#import "RCTBridge.h"
#import "RCTConvert.h"
#import "RCTEventDispatcher.h"
#import "RCTLog.h"
#import "RCTShadowView.h"
#import "RCTUtils.h"
#import "RCTView.h"
@implementation RCTViewManager
@synthesize bridge = _bridge;
+ (NSString *)moduleName
{
// Default implementation, works in most cases
NSString *name = NSStringFromClass(self);
if ([name hasPrefix:@"RK"]) {
name = [name stringByReplacingCharactersInRange:(NSRange){0,@"RK".length} withString:@"RCT"];
}
if ([name hasPrefix:@"RCTUI"]) {
name = [name substringFromIndex:@"RCT".length];
}
return name;
}
- (UIView *)view
{
return [[RCTView alloc] init];
}
- (RCTShadowView *)shadowView
{
return [[RCTShadowView alloc] init];
}
2015-03-25 00:37:03 +00:00
- (NSDictionary *)customBubblingEventTypes
{
return nil;
}
2015-03-25 00:37:03 +00:00
- (NSDictionary *)customDirectEventTypes
{
return nil;
}
- (NSDictionary *)constantsToExport
{
return nil;
}
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowView:(RCTShadowView *)shadowView
{
return nil;
}
- (RCTViewManagerUIBlock)uiBlockToAmendWithShadowViewRegistry:(RCTSparseArray *)shadowViewRegistry
{
return nil;
}
#pragma mark - View properties
RCT_EXPORT_VIEW_PROPERTY(accessibilityLabel)
RCT_EXPORT_VIEW_PROPERTY(hidden)
RCT_EXPORT_VIEW_PROPERTY(backgroundColor)
RCT_REMAP_VIEW_PROPERTY(accessible, isAccessibilityElement)
RCT_REMAP_VIEW_PROPERTY(testID, accessibilityIdentifier)
RCT_REMAP_VIEW_PROPERTY(opacity, alpha)
RCT_REMAP_VIEW_PROPERTY(shadowColor, layer.shadowColor);
RCT_REMAP_VIEW_PROPERTY(shadowOffset, layer.shadowOffset);
RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity)
RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius)
RCT_REMAP_VIEW_PROPERTY(borderColor, layer.borderColor);
RCT_REMAP_VIEW_PROPERTY(borderRadius, layer.cornerRadius)
RCT_REMAP_VIEW_PROPERTY(borderWidth, layer.borderWidth)
RCT_REMAP_VIEW_PROPERTY(transformMatrix, layer.transform)
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_VIEW_PROPERTY(overflow, UIView)
{
view.clipsToBounds = json ? ![RCTConvert css_overflow:json] : defaultView.clipsToBounds;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTView)
{
if ([view respondsToSelector:@selector(setPointerEvents:)]) {
view.pointerEvents = json ? [RCTConvert RCTPointerEvents:json] : defaultView.pointerEvents;
return;
}
if (!json) {
view.userInteractionEnabled = defaultView.userInteractionEnabled;
return;
}
2015-03-25 00:37:03 +00:00
switch ([RCTConvert RCTPointerEvents:json]) {
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
// supported in `ReactKit`. "auto" may override a parent's "none".
// 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-25 00:37:03 +00:00
RCT_CUSTOM_VIEW_PROPERTY(removeClippedSubviews, RCTView)
{
if ([view respondsToSelector:@selector(setRemoveClippedSubviews:)]) {
view.removeClippedSubviews = json ? [RCTConvert BOOL:json] : defaultView.removeClippedSubviews;
}
}
#pragma mark - ShadowView properties
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(backgroundColor, RCTShadowView)
{
view.backgroundColor = json ? [RCTConvert UIColor:json] : defaultView.backgroundColor;
view.isBGColorExplicitlySet = json ? YES : defaultView.isBGColorExplicitlySet;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(flexDirection, RCTShadowView)
{
view.flexDirection = json? [RCTConvert css_flex_direction_t:json] : defaultView.flexDirection;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(flexWrap, RCTShadowView)
{
view.flexWrap = json ? [RCTConvert css_wrap_type_t:json] : defaultView.flexWrap;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(justifyContent, RCTShadowView)
{
view.justifyContent = json ? [RCTConvert css_justify_t:json] : defaultView.justifyContent;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(alignItems, RCTShadowView)
{
view.alignItems = json ? [RCTConvert css_align_t:json] : defaultView.alignItems;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(alignSelf, RCTShadowView)
{
view.alignSelf = json ? [RCTConvert css_align_t:json] : defaultView.alignSelf;
}
2015-03-15 23:08:42 +00:00
RCT_CUSTOM_SHADOW_PROPERTY(position, RCTShadowView)
{
view.positionType = json ? [RCTConvert css_position_type_t:json] : defaultView.positionType;
}
2015-03-25 00:37:03 +00:00
// Border properties - to be deprecated
RCT_REMAP_VIEW_PROPERTY(borderTopWidth, reactBorderTop.width);
RCT_REMAP_VIEW_PROPERTY(borderRightWidth, reactBorderRight.width);
RCT_REMAP_VIEW_PROPERTY(borderBottomWidth, reactBorderBottom.width);
RCT_REMAP_VIEW_PROPERTY(borderLeftWidth, reactBorderLeft.width);
RCT_REMAP_VIEW_PROPERTY(borderTopColor, reactBorderTop.color);
RCT_REMAP_VIEW_PROPERTY(borderRightColor, reactBorderRight.color);
RCT_REMAP_VIEW_PROPERTY(borderBottomColor, reactBorderBottom.color);
RCT_REMAP_VIEW_PROPERTY(borderLeftColor, reactBorderLeft.color);
@end