Files
react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm
Valentin Shergin 9101ebdfbb Fabric: More clang-format
Summary: Apparently, I haven't modify all files in D14018903. Here is the last (I hope) chunk.

Reviewed By: JoshuaGross

Differential Revision: D14058288

fbshipit-source-id: b21950cdd1aa9aa55b0c72fac0f8b44e4a7d131c
2019-02-13 15:25:00 -08:00

130 lines
3.8 KiB
Plaintext

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#import "RCTParagraphComponentView.h"
#import <react/components/text/ParagraphLocalData.h>
#import <react/components/text/ParagraphProps.h>
#import <react/components/text/ParagraphShadowNode.h>
#import <react/core/LocalData.h>
#import <react/graphics/Geometry.h>
#import <react/textlayoutmanager/RCTTextLayoutManager.h>
#import <react/textlayoutmanager/TextLayoutManager.h>
#import "RCTConversions.h"
using namespace facebook::react;
@implementation RCTParagraphComponentView {
SharedParagraphLocalData _paragraphLocalData;
ParagraphAttributes _paragraphAttributes;
}
- (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
static const auto defaultProps = std::make_shared<const ParagraphProps>();
_props = defaultProps;
self.isAccessibilityElement = YES;
self.accessibilityTraits |= UIAccessibilityTraitStaticText;
self.opaque = NO;
self.contentMode = UIViewContentModeRedraw;
}
return self;
}
#pragma mark - RCTComponentViewProtocol
+ (ComponentHandle)componentHandle
{
return ParagraphShadowNode::Handle();
}
- (void)updateProps:(SharedProps)props oldProps:(SharedProps)oldProps
{
const auto &paragraphProps = std::static_pointer_cast<const ParagraphProps>(props);
[super updateProps:props oldProps:oldProps];
assert(paragraphProps);
_paragraphAttributes = paragraphProps->paragraphAttributes;
}
- (void)updateLocalData:(SharedLocalData)localData oldLocalData:(SharedLocalData)oldLocalData
{
_paragraphLocalData = std::static_pointer_cast<const ParagraphLocalData>(localData);
assert(_paragraphLocalData);
[self setNeedsDisplay];
}
- (void)prepareForRecycle
{
[super prepareForRecycle];
_paragraphLocalData.reset();
}
- (void)drawRect:(CGRect)rect
{
if (!_paragraphLocalData) {
return;
}
SharedTextLayoutManager textLayoutManager = _paragraphLocalData->getTextLayoutManager();
RCTTextLayoutManager *nativeTextLayoutManager =
(__bridge RCTTextLayoutManager *)textLayoutManager->getNativeTextLayoutManager();
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
[nativeTextLayoutManager drawAttributedString:_paragraphLocalData->getAttributedString()
paragraphAttributes:_paragraphAttributes
frame:frame];
}
#pragma mark - Accessibility
- (NSString *)accessibilityLabel
{
NSString *superAccessibilityLabel = RCTNSStringFromStringNilIfEmpty(_props->accessibilityLabel);
if (superAccessibilityLabel) {
return superAccessibilityLabel;
}
if (!_paragraphLocalData) {
return nil;
}
return RCTNSStringFromString(_paragraphLocalData->getAttributedString().getString());
}
- (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
{
if (!_paragraphLocalData) {
return _eventEmitter;
}
SharedTextLayoutManager textLayoutManager = _paragraphLocalData->getTextLayoutManager();
RCTTextLayoutManager *nativeTextLayoutManager =
(__bridge RCTTextLayoutManager *)textLayoutManager->getNativeTextLayoutManager();
CGRect frame = RCTCGRectFromRect(_layoutMetrics.getContentFrame());
SharedEventEmitter eventEmitter =
[nativeTextLayoutManager getEventEmitterWithAttributeString:_paragraphLocalData->getAttributedString()
paragraphAttributes:_paragraphAttributes
frame:frame
atPoint:point];
if (!eventEmitter) {
return _eventEmitter;
}
assert(std::dynamic_pointer_cast<const TouchEventEmitter>(eventEmitter));
return std::static_pointer_cast<const TouchEventEmitter>(eventEmitter);
}
@end