From 02c3cd4c4e712dea004713c271f0ae0d5a03ac96 Mon Sep 17 00:00:00 2001 From: Valentin Shergin Date: Mon, 7 May 2018 21:49:19 -0700 Subject: [PATCH] Fabric/Text: text module, rawtext part Summary: component represents a purely regular string object in React. Reviewed By: mdvacca Differential Revision: D7751850 fbshipit-source-id: 54afe43e0c1ac063862f109ea07f0e7de3593573 --- React.podspec | 9 ++ ReactCommon/fabric/text/BUCK | 84 +++++++++++++++++++ .../text/rawtext/RawTextComponentDescriptor.h | 27 ++++++ .../fabric/text/rawtext/RawTextProps.cpp | 37 ++++++++ .../fabric/text/rawtext/RawTextProps.h | 43 ++++++++++ .../fabric/text/rawtext/RawTextShadowNode.cpp | 20 +++++ .../fabric/text/rawtext/RawTextShadowNode.h | 39 +++++++++ ReactCommon/fabric/text/tests/TextTest.cpp | 14 ++++ 8 files changed, 273 insertions(+) create mode 100644 ReactCommon/fabric/text/BUCK create mode 100644 ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h create mode 100644 ReactCommon/fabric/text/rawtext/RawTextProps.cpp create mode 100644 ReactCommon/fabric/text/rawtext/RawTextProps.h create mode 100644 ReactCommon/fabric/text/rawtext/RawTextShadowNode.cpp create mode 100644 ReactCommon/fabric/text/rawtext/RawTextShadowNode.h create mode 100644 ReactCommon/fabric/text/tests/TextTest.cpp diff --git a/React.podspec b/React.podspec index 44d6ef7f5..9305d94ea 100644 --- a/React.podspec +++ b/React.podspec @@ -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 diff --git a/ReactCommon/fabric/text/BUCK b/ReactCommon/fabric/text/BUCK new file mode 100644 index 000000000..20a30de39 --- /dev/null +++ b/ReactCommon/fabric/text/BUCK @@ -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", + ], + ) diff --git a/ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h b/ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h new file mode 100644 index 000000000..6f615fa3c --- /dev/null +++ b/ReactCommon/fabric/text/rawtext/RawTextComponentDescriptor.h @@ -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 +#include + +namespace facebook { +namespace react { + +/* + * Descriptor for component. + */ +class RawTextComponentDescriptor: public ConcreteComponentDescriptor { +public: + ComponentName getComponentName() const override { + return "RawText"; + } +}; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/text/rawtext/RawTextProps.cpp b/ReactCommon/fabric/text/rawtext/RawTextProps.cpp new file mode 100644 index 000000000..d985188c9 --- /dev/null +++ b/ReactCommon/fabric/text/rawtext/RawTextProps.cpp @@ -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 +#include + +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("text", text_)); + return list; +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/text/rawtext/RawTextProps.h b/ReactCommon/fabric/text/rawtext/RawTextProps.h new file mode 100644 index 000000000..4dd84f8fb --- /dev/null +++ b/ReactCommon/fabric/text/rawtext/RawTextProps.h @@ -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 + +#include +#include + +namespace facebook { +namespace react { + +class RawTextProps; + +using SharedRawTextProps = std::shared_ptr; + +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 diff --git a/ReactCommon/fabric/text/rawtext/RawTextShadowNode.cpp b/ReactCommon/fabric/text/rawtext/RawTextShadowNode.cpp new file mode 100644 index 000000000..730e4aabb --- /dev/null +++ b/ReactCommon/fabric/text/rawtext/RawTextShadowNode.cpp @@ -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 + +namespace facebook { +namespace react { + +ComponentName RawTextShadowNode::getComponentName() const { + return ComponentName("RawText"); +} + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/text/rawtext/RawTextShadowNode.h b/ReactCommon/fabric/text/rawtext/RawTextShadowNode.h new file mode 100644 index 000000000..f4a2e2ffc --- /dev/null +++ b/ReactCommon/fabric/text/rawtext/RawTextShadowNode.h @@ -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 + +#include +#include +#include + +namespace facebook { +namespace react { + +class RawTextShadowNode; + +using SharedRawTextShadowNode = std::shared_ptr; + +/* + * `ShadowNode` for component, represents a purely regular string + * object in React. In a code fragment `Hello!`, "Hello!" part + * is represented as ``. + * component must not have any children. + */ +class RawTextShadowNode: + public ConcreteShadowNode { + +public: + using ConcreteShadowNode::ConcreteShadowNode; + + ComponentName getComponentName() const override; +}; + +} // namespace react +} // namespace facebook diff --git a/ReactCommon/fabric/text/tests/TextTest.cpp b/ReactCommon/fabric/text/tests/TextTest.cpp new file mode 100644 index 000000000..55ae97a50 --- /dev/null +++ b/ReactCommon/fabric/text/tests/TextTest.cpp @@ -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 + +#include + +TEST(TextLayoutManagerTest, testSomething) { + // TODO: +}