Skip to content

Commit

Permalink
Fabric: Enabling clang-format for half of Fabric modules
Browse files Browse the repository at this point in the history
Summary:
All code styles are terribly ugly. We have the only choise - choise something and embrace it.
This particular code style was borrowed from a neibour Fabric-friendly project because it follows established Facebook guides and respects client-side traditions.

Reviewed By: mdvacca

Differential Revision: D10218598

fbshipit-source-id: 8c4cf6713c07768566dadef479191661c79988f0
  • Loading branch information
shergin authored and facebook-github-bot committed Oct 5, 2018
1 parent 3d31beb commit 3ad5c9e
Show file tree
Hide file tree
Showing 100 changed files with 2,617 additions and 1,756 deletions.
87 changes: 87 additions & 0 deletions ReactCommon/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
---
AccessModifierOffset: -1
AlignAfterOpenBracket: AlwaysBreak
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlinesLeft: true
AlignOperands: false
AlignTrailingComments: false
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortBlocksOnASingleLine: false
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: true
AlwaysBreakTemplateDeclarations: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterClass: false
AfterControlStatement: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
IndentBraces: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Attach
BreakBeforeTernaryOperators: true
BreakConstructorInitializersBeforeComma: false
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: false
ColumnLimit: 80
CommentPragmas: '^ IWYU pragma:'
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DerivePointerAlignment: false
DisableFormat: false
ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ]
IncludeCategories:
- Regex: '^<.*\.h(pp)?>'
Priority: 1
- Regex: '^<.*'
Priority: 2
- Regex: '.*'
Priority: 3
IndentCaseLabels: true
IndentWidth: 2
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: false
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 1
NamespaceIndentation: None
ObjCBlockIndentWidth: 2
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: false
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 300
PenaltyBreakFirstLessLess: 120
PenaltyBreakString: 1000
PenaltyExcessCharacter: 1000000
PenaltyReturnTypeOnItsOwnLine: 200
PointerAlignment: Right
ReflowComments: true
SortIncludes: true
SpaceAfterCStyleCast: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInContainerLiterals: true
SpacesInCStyleCastParentheses: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 8
UseTab: Never
...
52 changes: 26 additions & 26 deletions ReactCommon/fabric/attributedstring/AttributedString.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,12 @@ using Fragments = AttributedString::Fragments;
#pragma mark - Fragment

bool Fragment::operator==(const Fragment &rhs) const {
return
std::tie(
string,
textAttributes,
shadowNode,
parentShadowNode
) ==
std::tie(
rhs.string,
rhs.textAttributes,
rhs.shadowNode,
rhs.parentShadowNode
);
return std::tie(string, textAttributes, shadowNode, parentShadowNode) ==
std::tie(
rhs.string,
rhs.textAttributes,
rhs.shadowNode,
rhs.parentShadowNode);
}

bool Fragment::operator!=(const Fragment &rhs) const {
Expand All @@ -49,22 +42,30 @@ void AttributedString::prependFragment(const Fragment &fragment) {
fragments_.insert(fragments_.begin(), fragment);
}

void AttributedString::appendAttributedString(const AttributedString &attributedString) {
void AttributedString::appendAttributedString(
const AttributedString &attributedString) {
ensureUnsealed();
fragments_.insert(fragments_.end(), attributedString.fragments_.begin(), attributedString.fragments_.end());
fragments_.insert(
fragments_.end(),
attributedString.fragments_.begin(),
attributedString.fragments_.end());
}

void AttributedString::prependAttributedString(const AttributedString &attributedString) {
void AttributedString::prependAttributedString(
const AttributedString &attributedString) {
ensureUnsealed();
fragments_.insert(fragments_.begin(), attributedString.fragments_.begin(), attributedString.fragments_.end());
fragments_.insert(
fragments_.begin(),
attributedString.fragments_.begin(),
attributedString.fragments_.end());
}

const std::vector<Fragment> &AttributedString::getFragments() const {
return fragments_;
}

std::string AttributedString::getString() const {
auto string = std::string {};
auto string = std::string{};
for (const auto &fragment : fragments_) {
string += fragment.string;
}
Expand All @@ -83,23 +84,22 @@ bool AttributedString::operator!=(const AttributedString &rhs) const {

#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList AttributedString::getDebugChildren() const {
auto list = SharedDebugStringConvertibleList {};
auto list = SharedDebugStringConvertibleList{};

for (auto &&fragment : fragments_) {
auto propsList = fragment.textAttributes.DebugStringConvertible::getDebugProps();
auto propsList =
fragment.textAttributes.DebugStringConvertible::getDebugProps();

if (fragment.shadowNode) {
propsList.push_back(std::make_shared<DebugStringConvertibleItem>("shadowNode", fragment.shadowNode->getDebugDescription()));
propsList.push_back(std::make_shared<DebugStringConvertibleItem>(
"shadowNode", fragment.shadowNode->getDebugDescription()));
}

list.push_back(
std::make_shared<DebugStringConvertibleItem>(
list.push_back(std::make_shared<DebugStringConvertibleItem>(
"Fragment",
fragment.string,
SharedDebugStringConvertibleList(),
propsList
)
);
propsList));
}

return list;
Expand Down
56 changes: 27 additions & 29 deletions ReactCommon/fabric/attributedstring/AttributedString.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ using SharedAttributedString = std::shared_ptr<const AttributedString>;
* `AttributedString` is basically a list of `Fragments` which have `string` and
* `textAttributes` + `shadowNode` associated with the `string`.
*/
class AttributedString:
public Sealable,
public DebugStringConvertible {

public:

class AttributedString : public Sealable, public DebugStringConvertible {
public:
class Fragment {

public:
public:
std::string string;
TextAttributes textAttributes;
SharedShadowNode shadowNode;
Expand Down Expand Up @@ -81,36 +76,39 @@ class AttributedString:
SharedDebugStringConvertibleList getDebugChildren() const override;
#endif

private:

private:
Fragments fragments_;
};

} // namespace react
} // namespace facebook

namespace std {
template <>
struct hash<facebook::react::AttributedString::Fragment> {
size_t operator()(const facebook::react::AttributedString::Fragment &fragment) const {
return
std::hash<decltype(fragment.string)>{}(fragment.string) +
std::hash<decltype(fragment.textAttributes)>{}(fragment.textAttributes) +
template <>
struct hash<facebook::react::AttributedString::Fragment> {
size_t operator()(
const facebook::react::AttributedString::Fragment &fragment) const {
return std::hash<decltype(fragment.string)>{}(fragment.string) +
std::hash<decltype(fragment.textAttributes)>{}(
fragment.textAttributes) +
std::hash<decltype(fragment.shadowNode)>{}(fragment.shadowNode) +
std::hash<decltype(fragment.parentShadowNode)>{}(fragment.parentShadowNode);
}
};

template <>
struct hash<facebook::react::AttributedString> {
size_t operator()(const facebook::react::AttributedString &attributedString) const {
auto result = size_t {0};
std::hash<decltype(fragment.parentShadowNode)>{}(
fragment.parentShadowNode);
}
};

for (const auto &fragment : attributedString.getFragments()) {
result += std::hash<facebook::react::AttributedString::Fragment>{}(fragment);
}
template <>
struct hash<facebook::react::AttributedString> {
size_t operator()(
const facebook::react::AttributedString &attributedString) const {
auto result = size_t{0};

return result;
for (const auto &fragment : attributedString.getFragments()) {
result +=
std::hash<facebook::react::AttributedString::Fragment>{}(fragment);
}
};

return result;
}
};
} // namespace std
13 changes: 6 additions & 7 deletions ReactCommon/fabric/attributedstring/ParagraphAttributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "ParagraphAttributes.h"

#include <fabric/attributedstring/conversions.h>
#include <fabric/graphics/conversions.h>
#include <fabric/debug/debugStringConvertibleUtils.h>
#include <fabric/graphics/conversions.h>

namespace facebook {
namespace react {
Expand All @@ -19,12 +19,11 @@ namespace react {
#if RN_DEBUG_STRING_CONVERTIBLE
SharedDebugStringConvertibleList ParagraphAttributes::getDebugProps() const {
return {
debugStringConvertibleItem("maximumNumberOfLines", maximumNumberOfLines),
debugStringConvertibleItem("ellipsizeMode", ellipsizeMode),
debugStringConvertibleItem("adjustsFontSizeToFit", adjustsFontSizeToFit),
debugStringConvertibleItem("minimumFontSize", minimumFontSize),
debugStringConvertibleItem("maximumFontSize", maximumFontSize)
};
debugStringConvertibleItem("maximumNumberOfLines", maximumNumberOfLines),
debugStringConvertibleItem("ellipsizeMode", ellipsizeMode),
debugStringConvertibleItem("adjustsFontSizeToFit", adjustsFontSizeToFit),
debugStringConvertibleItem("minimumFontSize", minimumFontSize),
debugStringConvertibleItem("maximumFontSize", maximumFontSize)};
}
#endif

Expand Down
17 changes: 7 additions & 10 deletions ReactCommon/fabric/attributedstring/ParagraphAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,33 @@ using SharedParagraphAttributes = std::shared_ptr<const ParagraphAttributes>;
* Two data structures, ParagraphAttributes and AttributedText, should be
* enough to define visual representation of a piece of text on the screen.
*/
class ParagraphAttributes:
public DebugStringConvertible {

public:

class ParagraphAttributes : public DebugStringConvertible {
public:
#pragma mark - Fields

/*
* Maximum number of lines which paragraph can take.
* Zero value represents "no limit".
*/
int maximumNumberOfLines {};
int maximumNumberOfLines{};

/*
* In case if a text cannot fit given boundaries, defines a place where
* an ellipsize should be placed.
*/
EllipsizeMode ellipsizeMode {};
EllipsizeMode ellipsizeMode{};

/*
* Enables font size adjustment to fit constrained boundaries.
*/
bool adjustsFontSizeToFit {};
bool adjustsFontSizeToFit{};

/*
* In case of font size adjustment enabled, defines minimum and maximum
* font sizes.
*/
Float minimumFontSize {std::numeric_limits<Float>::quiet_NaN()};
Float maximumFontSize {std::numeric_limits<Float>::quiet_NaN()};
Float minimumFontSize{std::numeric_limits<Float>::quiet_NaN()};
Float maximumFontSize{std::numeric_limits<Float>::quiet_NaN()};

#pragma mark - DebugStringConvertible

Expand Down
Loading

0 comments on commit 3ad5c9e

Please sign in to comment.