mirror of
https://github.com/status-im/react-native.git
synced 2025-01-22 15:29:07 +00:00
3c8c01791f
Summary: Pretty straightforward. Reviewed By: fkgozali Differential Revision: D8344063 fbshipit-source-id: e6d35353cb3f3e374d2f2b723a612eda2d19c8b7
152 lines
4.0 KiB
Plaintext
152 lines
4.0 KiB
Plaintext
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*/
|
|
|
|
#import "RCTViewComponentView.h"
|
|
|
|
#import <fabric/view/ViewProps.h>
|
|
#import <fabric/view/ViewEventEmitter.h>
|
|
|
|
#import "RCTConversions.h"
|
|
|
|
using namespace facebook::react;
|
|
|
|
@implementation RCTViewComponentView
|
|
- (void)setContentView:(UIView *)contentView
|
|
{
|
|
if (_contentView) {
|
|
[_contentView removeFromSuperview];
|
|
}
|
|
|
|
_contentView = contentView;
|
|
|
|
if (_contentView) {
|
|
[self addSubview:_contentView];
|
|
}
|
|
}
|
|
|
|
- (void)layoutSubviews
|
|
{
|
|
[super layoutSubviews];
|
|
|
|
if (_contentView) {
|
|
_contentView.frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
|
|
}
|
|
}
|
|
|
|
- (BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event
|
|
{
|
|
if (UIEdgeInsetsEqualToEdgeInsets(self.hitTestEdgeInsets, UIEdgeInsetsZero)) {
|
|
return [super pointInside:point withEvent:event];
|
|
}
|
|
CGRect hitFrame = UIEdgeInsetsInsetRect(self.bounds, self.hitTestEdgeInsets);
|
|
return CGRectContainsPoint(hitFrame, point);
|
|
}
|
|
|
|
- (void)updateProps:(SharedProps)props
|
|
oldProps:(SharedProps)oldProps
|
|
{
|
|
if (!oldProps) {
|
|
oldProps = _props ?: std::make_shared<ViewProps>();
|
|
}
|
|
_props = props;
|
|
|
|
auto oldViewProps = *std::dynamic_pointer_cast<const ViewProps>(oldProps);
|
|
auto newViewProps = *std::dynamic_pointer_cast<const ViewProps>(props);
|
|
|
|
// `opacity`
|
|
if (oldViewProps.opacity != newViewProps.opacity) {
|
|
self.layer.opacity = (CGFloat)newViewProps.opacity;
|
|
}
|
|
|
|
// `backgroundColor`
|
|
if (oldViewProps.backgroundColor != newViewProps.backgroundColor) {
|
|
self.backgroundColor = RCTUIColorFromSharedColor(newViewProps.backgroundColor);
|
|
}
|
|
|
|
// `foregroundColor`
|
|
if (oldViewProps.foregroundColor != newViewProps.foregroundColor) {
|
|
self.foregroundColor = RCTUIColorFromSharedColor(newViewProps.foregroundColor);
|
|
}
|
|
|
|
// `backfaceVisibility`
|
|
if (oldViewProps.backfaceVisibility != newViewProps.backfaceVisibility) {
|
|
self.layer.doubleSided = newViewProps.backfaceVisibility;
|
|
}
|
|
|
|
// `shouldRasterize`
|
|
if (oldViewProps.shouldRasterize != newViewProps.shouldRasterize) {
|
|
self.layer.shouldRasterize = newViewProps.shouldRasterize;
|
|
self.layer.rasterizationScale = newViewProps.shouldRasterize ? [UIScreen mainScreen].scale : 1.0;
|
|
}
|
|
|
|
// `pointerEvents`
|
|
if (oldViewProps.pointerEvents != newViewProps.pointerEvents) {
|
|
self.userInteractionEnabled = newViewProps.pointerEvents != PointerEventsMode::None;
|
|
}
|
|
|
|
}
|
|
|
|
// TODO: Implement all sutable non-layout <View> props.
|
|
// `hitSlop`
|
|
if (oldViewProps.hitSlop != newViewProps.hitSlop) {
|
|
self.hitTestEdgeInsets = RCTUIEdgeInsetsFromEdgeInsets(newViewProps.hitSlop);
|
|
}
|
|
|
|
// `zIndex`
|
|
if (oldViewProps.zIndex != newViewProps.zIndex) {
|
|
self.layer.zPosition = (CGFloat)newViewProps.zIndex;
|
|
}
|
|
|
|
// `nativeId`
|
|
if (oldViewProps.nativeId != newViewProps.nativeId) {
|
|
self.nativeId = [NSString stringWithCString:newViewProps.nativeId.c_str()
|
|
encoding:NSASCIIStringEncoding];
|
|
}
|
|
}
|
|
|
|
- (void)updateEventEmitter:(SharedEventEmitter)eventEmitter
|
|
{
|
|
assert(std::dynamic_pointer_cast<const ViewEventEmitter>(eventEmitter));
|
|
_eventEmitter = std::static_pointer_cast<const ViewEventEmitter>(eventEmitter);
|
|
}
|
|
|
|
- (void)updateLayoutMetrics:(LayoutMetrics)layoutMetrics
|
|
oldLayoutMetrics:(LayoutMetrics)oldLayoutMetrics
|
|
{
|
|
_layoutMetrics = layoutMetrics;
|
|
|
|
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
|
|
|
|
}
|
|
|
|
#pragma mark - Accessibility Events
|
|
|
|
- (BOOL)accessibilityActivate
|
|
{
|
|
_eventEmitter->onAccessibilityTap();
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)accessibilityPerformMagicTap
|
|
{
|
|
_eventEmitter->onAccessibilityMagicTap();
|
|
return YES;
|
|
}
|
|
|
|
- (BOOL)didActivateAccessibilityCustomAction:(UIAccessibilityCustomAction *)action
|
|
{
|
|
_eventEmitter->onAccessibilityAction([action.name cStringUsingEncoding:NSASCIIStringEncoding]);
|
|
return YES;
|
|
}
|
|
|
|
- (SharedEventEmitter)touchEventEmitter
|
|
{
|
|
return _eventEmitter;
|
|
}
|
|
|
|
@end
|