mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
0556e86d09
Summary: Support for modifying AndroidTextInputs with multiple Fragments was added on the Java side in a previous diff. This diff adds support on the C++ side for the following scenario: A <TextInput> is initially given contents via children <Text> notes, which represents multiple Fragments (that could have different TextAttributes like color, font size, backgroundcolor, etc). The Android EditText view must get this initial data, and then all updates after that on the Android side must flow to C++ so that the C++ ShadowNode can perform layout and measurement with up-to-date data. At the same time, the <TextInput> node could be updated from the JS side. All else equal, this would cause the native Android EditText to be replaced with the old, original contents of the <TextInput> that may not have been updated at all from the JS side. To mitigate this, we keep track of two AttributedStrings with Fragments on the C++ side: the AttributedString representing the values coming from <TextInput> children, from JS (`treeAttributedString`); and the AttributedString representing the current value the user is interacting with (`attributedString`). If the children from JS don't change, we don't update Android/Java with that AttributedString. If the children from JS do change, we overwrite any user input with the tree from JS. Changelog: [Internal] Reviewed By: shergin, mdvacca Differential Revision: D18785976 fbshipit-source-id: a1f3a935e02379cabca8ab62a39cb3c0cf3fbca5
30 lines
880 B
C++
30 lines
880 B
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.
|
|
*/
|
|
|
|
#include "AndroidTextInputState.h"
|
|
|
|
#include <react/components/text/conversions.h>
|
|
#include <react/debug/debugStringConvertibleUtils.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
#ifdef ANDROID
|
|
folly::dynamic AndroidTextInputState::getDynamic() const {
|
|
// Java doesn't need all fields, so we don't pass them along.
|
|
folly::dynamic newState = folly::dynamic::object();
|
|
newState["mostRecentEventCount"] = mostRecentEventCount;
|
|
newState["attributedString"] = toDynamic(attributedString);
|
|
newState["paragraphAttributes"] = toDynamic(paragraphAttributes);
|
|
newState["hash"] = newState["attributedString"]["hash"];
|
|
return newState;
|
|
}
|
|
#endif
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|