184 lines
6.2 KiB
Objective-C
184 lines
6.2 KiB
Objective-C
/**
|
|
* 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];
|
|
}
|
|
|
|
- (NSDictionary *)customBubblingEventTypes
|
|
{
|
|
return nil;
|
|
}
|
|
|
|
- (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, NSString)
|
|
RCT_EXPORT_VIEW_PROPERTY(hidden, BOOL)
|
|
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);
|
|
RCT_REMAP_VIEW_PROPERTY(shadowOpacity, layer.shadowOpacity, CGFloat)
|
|
RCT_REMAP_VIEW_PROPERTY(shadowRadius, layer.shadowRadius, CGFloat)
|
|
RCT_REMAP_VIEW_PROPERTY(borderColor, layer.borderColor, CGColor);
|
|
RCT_REMAP_VIEW_PROPERTY(borderRadius, layer.cornerRadius, CGFloat)
|
|
RCT_REMAP_VIEW_PROPERTY(borderWidth, layer.borderWidth, CGFloat)
|
|
RCT_REMAP_VIEW_PROPERTY(transformMatrix, layer.transform, CATransform3D)
|
|
RCT_CUSTOM_VIEW_PROPERTY(overflow, css_overflow, RCTView)
|
|
{
|
|
view.clipsToBounds = json ? ![RCTConvert css_overflow:json] : defaultView.clipsToBounds;
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(pointerEvents, RCTPointerEvents, RCTView)
|
|
{
|
|
if ([view respondsToSelector:@selector(setPointerEvents:)]) {
|
|
view.pointerEvents = json ? [RCTConvert RCTPointerEvents:json] : defaultView.pointerEvents;
|
|
return;
|
|
}
|
|
|
|
if (!json) {
|
|
view.userInteractionEnabled = defaultView.userInteractionEnabled;
|
|
return;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|
|
RCT_CUSTOM_VIEW_PROPERTY(removeClippedSubviews, BOOL, RCTView)
|
|
{
|
|
if ([view respondsToSelector:@selector(setRemoveClippedSubviews:)]) {
|
|
view.removeClippedSubviews = json ? [RCTConvert BOOL:json] : defaultView.removeClippedSubviews;
|
|
}
|
|
}
|
|
|
|
#pragma mark - ShadowView properties
|
|
|
|
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)
|
|
{
|
|
view.backgroundColor = json ? [RCTConvert UIColor:json] : defaultView.backgroundColor;
|
|
view.isBGColorExplicitlySet = json ? YES : defaultView.isBGColorExplicitlySet;
|
|
}
|
|
|
|
// Border properties - to be deprecated
|
|
|
|
RCT_REMAP_VIEW_PROPERTY(borderTopWidth, reactBorderTop.width, CGFloat);
|
|
RCT_REMAP_VIEW_PROPERTY(borderRightWidth, reactBorderRight.width, CGFloat);
|
|
RCT_REMAP_VIEW_PROPERTY(borderBottomWidth, reactBorderBottom.width, CGFloat);
|
|
RCT_REMAP_VIEW_PROPERTY(borderLeftWidth, reactBorderLeft.width, CGFloat);
|
|
RCT_REMAP_VIEW_PROPERTY(borderTopColor, reactBorderTop.color, UIColor);
|
|
RCT_REMAP_VIEW_PROPERTY(borderRightColor, reactBorderRight.color, UIColor);
|
|
RCT_REMAP_VIEW_PROPERTY(borderBottomColor, reactBorderBottom.color, UIColor);
|
|
RCT_REMAP_VIEW_PROPERTY(borderLeftColor, reactBorderLeft.color, UIColor);
|
|
|
|
@end
|