Skip to content

Commit

Permalink
more lint auto fixing
Browse files Browse the repository at this point in the history
Summary: ran `find js/react-native-github/ReactCommon | xargs arc lint -a`

Reviewed By: fkgozali

Differential Revision: D12902865

fbshipit-source-id: 9c68c0f7e28893e76df966ad4110299e89895454
  • Loading branch information
sahrens authored and facebook-github-bot committed Nov 2, 2018
1 parent 81e5d64 commit 10d41d4
Show file tree
Hide file tree
Showing 8 changed files with 324 additions and 228 deletions.
11 changes: 6 additions & 5 deletions ReactCommon/fabric/attributedstring/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

#pragma once

#include <fabric/attributedstring/conversions.h>
#include <fabric/attributedstring/primitives.h>
#include <fabric/attributedstring/AttributedString.h>
#include <fabric/attributedstring/ParagraphAttributes.h>
#include <fabric/attributedstring/TextAttributes.h>
#include <fabric/core/conversions.h>
#include <fabric/attributedstring/conversions.h>
#include <fabric/attributedstring/primitives.h>
#include <fabric/core/LayoutableShadowNode.h>
#include <fabric/core/ShadowNode.h>
#include <fabric/graphics/conversions.h>
#include <fabric/core/conversions.h>
#include <fabric/graphics/Geometry.h>
#include <fabric/graphics/conversions.h>
#include <folly/dynamic.h>

namespace facebook {
Expand Down Expand Up @@ -388,7 +388,8 @@ inline folly::dynamic toDynamic(
inline folly::dynamic toDynamic(const TextAttributes &textAttributes) {
auto _textAttributes = folly::dynamic::object();
if (textAttributes.foregroundColor) {
_textAttributes("foregroundColor", toDynamic(textAttributes.foregroundColor));
_textAttributes(
"foregroundColor", toDynamic(textAttributes.foregroundColor));
}
if (textAttributes.backgroundColor) {
_textAttributes(
Expand Down
3 changes: 1 addition & 2 deletions ReactCommon/fabric/components/view/ViewShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ const char ViewComponentName[] = "View";
bool ViewShadowNode::isLayoutOnly() const {
const auto &viewProps = *std::static_pointer_cast<const ViewProps>(props_);

return
viewProps.collapsable &&
return viewProps.collapsable &&
// Event listeners
!viewProps.onLayout &&
// Generic Props
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@
#import "NSTextStorage+FontScaling.h"

typedef NS_OPTIONS(NSInteger, RCTTextSizeComparisonOptions) {
RCTTextSizeComparisonSmaller = 1 << 0,
RCTTextSizeComparisonLarger = 1 << 1,
RCTTextSizeComparisonSmaller = 1 << 0,
RCTTextSizeComparisonLarger = 1 << 1,
RCTTextSizeComparisonWithinRange = 1 << 2,
};

@implementation NSTextStorage (FontScaling)

- (void)scaleFontSizeToFitSize:(CGSize)size
minimumFontSize:(CGFloat)minimumFontSize
maximumFontSize:(CGFloat)maximumFontSize
{
CGFloat bottomRatio = 1.0/128.0;
maximumFontSize:(CGFloat)maximumFontSize {
CGFloat bottomRatio = 1.0 / 128.0;
CGFloat topRatio = 128.0;
CGFloat ratio = 1.0;

Expand All @@ -32,13 +31,11 @@ - (void)scaleFontSizeToFitSize:(CGSize)size
minimumFontSize:minimumFontSize
maximumFontSize:maximumFontSize];

RCTTextSizeComparisonOptions comparsion =
[self compareToSize:size thresholdRatio:0.01];
RCTTextSizeComparisonOptions comparsion = [self compareToSize:size
thresholdRatio:0.01];

if (
(comparsion & RCTTextSizeComparisonWithinRange) &&
(comparsion & RCTTextSizeComparisonSmaller)
) {
if ((comparsion & RCTTextSizeComparisonWithinRange) &&
(comparsion & RCTTextSizeComparisonSmaller)) {
return;
} else if (comparsion & RCTTextSizeComparisonSmaller) {
bottomRatio = ratio;
Expand All @@ -50,11 +47,9 @@ - (void)scaleFontSizeToFitSize:(CGSize)size
ratio = (topRatio + bottomRatio) / 2.0;

CGFloat kRatioThreshold = 0.005;
if (
ABS(topRatio - bottomRatio) < kRatioThreshold ||
if (ABS(topRatio - bottomRatio) < kRatioThreshold ||
ABS(topRatio - ratio) < kRatioThreshold ||
ABS(bottomRatio - ratio) < kRatioThreshold
) {
ABS(bottomRatio - ratio) < kRatioThreshold) {
[self replaceCharactersInRange:(NSRange){0, self.length}
withAttributedString:originalAttributedString];

Expand All @@ -69,37 +64,38 @@ - (void)scaleFontSizeToFitSize:(CGSize)size
}
}


- (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size thresholdRatio:(CGFloat)thresholdRatio
{
- (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size
thresholdRatio:(CGFloat)thresholdRatio {
NSLayoutManager *layoutManager = self.layoutManagers.firstObject;
NSTextContainer *textContainer = layoutManager.textContainers.firstObject;

[layoutManager ensureLayoutForTextContainer:textContainer];

// Does it fit the text container?
NSRange glyphRange = [layoutManager glyphRangeForTextContainer:textContainer];
NSRange truncatedGlyphRange = [layoutManager truncatedGlyphRangeInLineFragmentForGlyphAtIndex:glyphRange.length - 1];
NSRange truncatedGlyphRange = [layoutManager
truncatedGlyphRangeInLineFragmentForGlyphAtIndex:glyphRange.length - 1];

if (truncatedGlyphRange.location != NSNotFound) {
return RCTTextSizeComparisonLarger;
}

CGSize measuredSize = [layoutManager usedRectForTextContainer:textContainer].size;
CGSize measuredSize =
[layoutManager usedRectForTextContainer:textContainer].size;

// Does it fit the size?
BOOL fitsSize =
size.width >= measuredSize.width &&
size.height >= measuredSize.height;
size.width >= measuredSize.width && size.height >= measuredSize.height;

CGSize thresholdSize = (CGSize){
size.width * thresholdRatio,
size.height * thresholdRatio,
size.width * thresholdRatio,
size.height * thresholdRatio,
};

RCTTextSizeComparisonOptions result = 0;

result |= (fitsSize) ? RCTTextSizeComparisonSmaller : RCTTextSizeComparisonLarger;
result |=
(fitsSize) ? RCTTextSizeComparisonSmaller : RCTTextSizeComparisonLarger;

if (ABS(measuredSize.width - size.width) < thresholdSize.width) {
result = result | RCTTextSizeComparisonWithinRange;
Expand All @@ -110,26 +106,28 @@ - (RCTTextSizeComparisonOptions)compareToSize:(CGSize)size thresholdRatio:(CGFlo

- (void)scaleFontSizeWithRatio:(CGFloat)ratio
minimumFontSize:(CGFloat)minimumFontSize
maximumFontSize:(CGFloat)maximumFontSize
{
maximumFontSize:(CGFloat)maximumFontSize {
[self beginEditing];

[self enumerateAttribute:NSFontAttributeName
inRange:(NSRange){0, self.length}
options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:
^(UIFont *_Nullable font, NSRange range, BOOL *_Nonnull stop) {
if (!font) {
return;
}

CGFloat fontSize = MAX(MIN(font.pointSize * ratio, maximumFontSize), minimumFontSize);

[self addAttribute:NSFontAttributeName
value:[font fontWithSize:fontSize]
range:range];
}
];
[self
enumerateAttribute:NSFontAttributeName
inRange:(NSRange){0, self.length}
options:
NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
usingBlock:^(
UIFont *_Nullable font, NSRange range, BOOL *_Nonnull stop) {
if (!font) {
return;
}

CGFloat fontSize =
MAX(MIN(font.pointSize * ratio, maximumFontSize),
minimumFontSize);

[self addAttribute:NSFontAttributeName
value:[font fontWithSize:fontSize]
range:range];
}];

[self endEditing];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static UIFontWeight RCTUIFontWeightFromFloat(CGFloat fontWeight) {

fontDescriptor =
[fontDescriptor fontDescriptorWithSymbolicTraits:symbolicTraits];
font =
[UIFont fontWithDescriptor:fontDescriptor size:fontProperties.size];
font = [UIFont fontWithDescriptor:fontDescriptor
size:fontProperties.size];
}

{
Expand Down
16 changes: 8 additions & 8 deletions ReactCommon/fabric/uimanager/ComponentDescriptorRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ static const std::string componentNameByReactViewName(std::string viewName) {
}

static const RawProps rawPropsFromDynamic(const folly::dynamic object) {
// TODO: Convert this to something smarter, probably returning `std::iterator`.
// TODO: Convert this to something smarter, probably returning
// `std::iterator`.
RawProps result;

if (object.isNull()) {
Expand All @@ -103,13 +104,12 @@ SharedShadowNode ComponentDescriptorRegistry::createNode(Tag tag, const std::str
const SharedComponentDescriptor &componentDescriptor = (*this)[componentName];
RawProps rawProps = rawPropsFromDynamic(props);

SharedShadowNode shadowNode =
componentDescriptor->createShadowNode({
.tag = tag,
.rootTag = rootTag,
.eventEmitter = componentDescriptor->createEventEmitter(std::move(eventTarget), tag),
.props = componentDescriptor->cloneProps(nullptr, rawProps)
});
SharedShadowNode shadowNode = componentDescriptor->createShadowNode(
{.tag = tag,
.rootTag = rootTag,
.eventEmitter =
componentDescriptor->createEventEmitter(std::move(eventTarget), tag),
.props = componentDescriptor->cloneProps(nullptr, rawProps)});
return shadowNode;
}

Expand Down
10 changes: 8 additions & 2 deletions ReactCommon/fabric/uimanager/FabricUIManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ void FabricUIManager::stopSurface(SurfaceId surfaceId) const {
(*executor_)([this, surfaceId] { stopSurfaceFunction_(surfaceId); });
}

SharedShadowNode FabricUIManager::createNode(int tag, std::string viewName, int rootTag, folly::dynamic props, SharedEventTarget eventTarget) const {
SharedShadowNode shadowNode = componentDescriptorRegistry_->createNode(tag, viewName, rootTag, props, eventTarget);
SharedShadowNode FabricUIManager::createNode(
int tag,
std::string viewName,
int rootTag,
folly::dynamic props,
SharedEventTarget eventTarget) const {
SharedShadowNode shadowNode = componentDescriptorRegistry_->createNode(
tag, viewName, rootTag, props, eventTarget);
if (delegate_) {
delegate_->uiManagerDidCreateShadowNode(shadowNode);
}
Expand Down
Loading

0 comments on commit 10d41d4

Please sign in to comment.