Fabric/Text: text module, rawtext part

Summary: <RawText> component represents a purely regular string object in React.

Reviewed By: mdvacca

Differential Revision: D7751850

fbshipit-source-id: 54afe43e0c1ac063862f109ea07f0e7de3593573
This commit is contained in:
Valentin Shergin 2018-05-07 21:49:19 -07:00 committed by Facebook Github Bot
parent 05890a5942
commit 02c3cd4c4e
8 changed files with 273 additions and 0 deletions

View File

@ -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

View File

@ -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 = ["oncall+react_native@xmail.facebook.com"],
compiler_flags = [
"-fexceptions",
"-frtti",
"-std=c++14",
"-Wall",
],
platforms = APPLE,
deps = [
"xplat//folly:molly",
"xplat//third-party/gmock:gtest",
":text",
],
)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:
}