Skip to content

Commit

Permalink
Fabric/Text: text module, rawtext part
Browse files Browse the repository at this point in the history
Summary: <RawText> component represents a purely regular string object in React.

Reviewed By: mdvacca

Differential Revision: D7751850

fbshipit-source-id: 54afe43e0c1ac063862f109ea07f0e7de3593573
  • Loading branch information
shergin authored and facebook-github-bot committed May 8, 2018
1 parent 05890a5 commit 02c3cd4
Show file tree
Hide file tree
Showing 8 changed files with 273 additions and 0 deletions.
9 changes: 9 additions & 0 deletions React.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,15 @@ Pod::Spec.new do |s|
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Folly\"" }
end

ss.subspec "text" do |sss|
sss.dependency "Folly", folly_version
sss.compiler_flags = folly_compiler_flags
sss.source_files = "ReactCommon/fabric/text/**/*.{cpp,h}"
sss.exclude_files = "**/tests/*"
sss.header_dir = "fabric/text"
sss.pod_target_xcconfig = { "HEADER_SEARCH_PATHS" => "\"$(PODS_TARGET_SRCROOT)/ReactCommon\" \"$(PODS_ROOT)/Folly\"" }
end

ss.subspec "textlayoutmanager" do |sss|
sss.dependency "Folly", folly_version
sss.compiler_flags = folly_compiler_flags
Expand Down
84 changes: 84 additions & 0 deletions ReactCommon/fabric/text/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
load("//configurations/buck/apple:flag_defs.bzl", "get_debug_preprocessor_flags", "get_fbobjc_enable_exception_lang_compiler_flags")
load("//ReactNative:DEFS.bzl", "IS_OSS_BUILD", "react_native_xplat_target", "rn_xplat_cxx_library", "get_apple_inspector_flags", "APPLE")

APPLE_COMPILER_FLAGS = []

if not IS_OSS_BUILD:
load("@xplat//configurations/buck/apple:flag_defs.bzl", "get_static_library_ios_flags", "flags")
APPLE_COMPILER_FLAGS = flags.get_flag_value(get_static_library_ios_flags(), 'compiler_flags')

rn_xplat_cxx_library(
name = "text",
srcs = glob(
["**/*.cpp"],
excludes = glob(["tests/**/*.cpp"]),
),
headers = glob(
["**/*.h"],
excludes = glob(["tests/**/*.h"]),
),
header_namespace = "",
exported_headers = subdir_glob(
[
("", "*.h"),
("paragraph", "*.h"),
("text", "*.h"),
("rawtext", "*.h"),
],
prefix = "fabric/text",
),
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
fbobjc_compiler_flags = APPLE_COMPILER_FLAGS,
fbobjc_preprocessor_flags = get_debug_preprocessor_flags() + get_apple_inspector_flags(),
fbobjc_tests = [
":tests",
],
force_static = True,
macosx_tests_override = [],
preprocessor_flags = [
"-DLOG_TAG=\"ReactNative\"",
"-DWITH_FBSYSTRACE=1",
],
tests = [],
visibility = ["PUBLIC"],
deps = [
"xplat//fbsystrace:fbsystrace",
"xplat//folly:headers_only",
"xplat//folly:memory",
"xplat//folly:molly",
"xplat//third-party/glog:glog",
react_native_xplat_target("fabric/attributedstring:attributedstring"),
react_native_xplat_target("fabric/core:core"),
react_native_xplat_target("fabric/debug:debug"),
react_native_xplat_target("fabric/graphics:graphics"),
react_native_xplat_target("fabric/textlayoutmanager:textlayoutmanager"),
react_native_xplat_target("fabric/view:view"),
],
)

if not IS_OSS_BUILD:
load("@xplat//build_defs:fb_xplat_cxx_test.bzl", "fb_xplat_cxx_test")

fb_xplat_cxx_test(
name = "tests",
srcs = glob(["tests/**/*.cpp"]),
headers = glob(["tests/**/*.h"]),
contacts = ["[email protected]"],
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
platforms = APPLE,
deps = [
"xplat//folly:molly",
"xplat//third-party/gmock:gtest",
":text",
],
)
27 changes: 27 additions & 0 deletions ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* 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.
*/

#pragma once

#include <fabric/core/ConcreteComponentDescriptor.h>
#include <fabric/text/RawTextShadowNode.h>

namespace facebook {
namespace react {

/*
* Descriptor for <RawText> component.
*/
class RawTextComponentDescriptor: public ConcreteComponentDescriptor<RawTextShadowNode> {
public:
ComponentName getComponentName() const override {
return "RawText";
}
};

} // namespace react
} // namespace facebook
37 changes: 37 additions & 0 deletions ReactCommon/fabric/text/rawtext/RawTextProps.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* 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.
*/

#include "RawTextProps.h"

#include <fabric/core/propsConversions.h>
#include <fabric/debug/DebugStringConvertibleItem.h>

namespace facebook {
namespace react {

void RawTextProps::apply(const RawProps &rawProps) {
Props::apply(rawProps);

applyRawProp(rawProps, "text", text_);
}

#pragma mark - Getters

std::string RawTextProps::getText() const {
return text_;
}

#pragma mark - DebugStringConvertible

SharedDebugStringConvertibleList RawTextProps::getDebugProps() const {
SharedDebugStringConvertibleList list = {};
list.push_back(std::make_shared<DebugStringConvertibleItem>("text", text_));
return list;
}

} // namespace react
} // namespace facebook
43 changes: 43 additions & 0 deletions ReactCommon/fabric/text/rawtext/RawTextProps.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* 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.
*/

#pragma once

#include <memory>

#include <fabric/core/Props.h>
#include <fabric/debug/DebugStringConvertible.h>

namespace facebook {
namespace react {

class RawTextProps;

using SharedRawTextProps = std::shared_ptr<const RawTextProps>;

class RawTextProps:
public Props {

public:

void apply(const RawProps &rawProps) override;

#pragma mark - Getters

std::string getText() const;

#pragma mark - DebugStringConvertible

SharedDebugStringConvertibleList getDebugProps() const override;

private:

std::string text_ {""};
};

} // namespace react
} // namespace facebook
20 changes: 20 additions & 0 deletions ReactCommon/fabric/text/rawtext/RawTextShadowNode.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/**
* 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.
*/

#include "RawTextShadowNode.h"

#include <fabric/debug/DebugStringConvertibleItem.h>

namespace facebook {
namespace react {

ComponentName RawTextShadowNode::getComponentName() const {
return ComponentName("RawText");
}

} // namespace react
} // namespace facebook
39 changes: 39 additions & 0 deletions ReactCommon/fabric/text/rawtext/RawTextShadowNode.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* 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.
*/

#pragma once

#include <memory>

#include <fabric/core/ConcreteShadowNode.h>
#include <fabric/core/ShadowNode.h>
#include <fabric/text/RawTextProps.h>

namespace facebook {
namespace react {

class RawTextShadowNode;

using SharedRawTextShadowNode = std::shared_ptr<const RawTextShadowNode>;

/*
* `ShadowNode` for <RawText> component, represents a purely regular string
* object in React. In a code fragment `<Text>Hello!</Text>`, "Hello!" part
* is represented as `<RawText text="Hello!"/>`.
* <RawText> component must not have any children.
*/
class RawTextShadowNode:
public ConcreteShadowNode<RawTextProps> {

public:
using ConcreteShadowNode::ConcreteShadowNode;

ComponentName getComponentName() const override;
};

} // namespace react
} // namespace facebook
14 changes: 14 additions & 0 deletions ReactCommon/fabric/text/tests/TextTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/**
* 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.
*/

#include <memory>

#include <gtest/gtest.h>

TEST(TextLayoutManagerTest, testSomething) {
// TODO:
}

0 comments on commit 02c3cd4

Please sign in to comment.