mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
309de462bd
Summary: iOS and other platforms have direct access to C++ StateT structs, whereas Java only has access to a Java map equivalent - state updates from Java can't update complex types, or must incur significant cost to reconstruct large objects from their folly::dynamic representation (not to mention the complexity of implementing the Java-to-C++ struct converters). Thus it's hard for Java to update StateT's with complex types on the C++ side. This diff makes a minor change to Android's updateState which uses both the folly::dynamic data from Java as well as the previous State, so each StateT can have fields that are read-only from the Java perspective. Motivation: For AndroidTextInput we need to set params from Java, without being able to send all of the State params from Java. In this diff, we introduce a new State constructor that takes the previous State value and a folly::dynamic. It is up to each State implementation how the additional parameter will be used. We migrate every existing component except for AndroidTextInput in this diff. Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D18672365 fbshipit-source-id: 4469e0a3c7658c204089c6fed39394979883f124
65 lines
1.6 KiB
C++
65 lines
1.6 KiB
C++
/*
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* 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 <react/attributedstring/AttributedString.h>
|
|
#include <react/attributedstring/ParagraphAttributes.h>
|
|
#include <react/textlayoutmanager/TextLayoutManager.h>
|
|
|
|
#ifdef ANDROID
|
|
#include <folly/dynamic.h>
|
|
#endif
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* State for <Paragraph> component.
|
|
* Represents what to render and how to render.
|
|
*/
|
|
class ParagraphState final {
|
|
public:
|
|
/*
|
|
* All content of <Paragraph> component represented as an `AttributedString`.
|
|
*/
|
|
AttributedString attributedString;
|
|
|
|
/*
|
|
* Represents all visual attributes of a paragraph of text represented as
|
|
* a ParagraphAttributes.
|
|
*/
|
|
ParagraphAttributes paragraphAttributes;
|
|
|
|
/*
|
|
* `TextLayoutManager` provides a connection to platform-specific
|
|
* text rendering infrastructure which is capable to render the
|
|
* `AttributedString`.
|
|
*/
|
|
SharedTextLayoutManager layoutManager;
|
|
|
|
#ifdef ANDROID
|
|
ParagraphState(
|
|
AttributedString const &attributedString,
|
|
ParagraphAttributes const ¶graphAttributes,
|
|
SharedTextLayoutManager const &layoutManager)
|
|
: attributedString(attributedString),
|
|
paragraphAttributes(paragraphAttributes),
|
|
layoutManager(layoutManager) {}
|
|
ParagraphState() = default;
|
|
ParagraphState(
|
|
ParagraphState const &previousState,
|
|
folly::dynamic const &data) {
|
|
assert(false && "Not supported");
|
|
};
|
|
folly::dynamic getDynamic() const;
|
|
#endif
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|