Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
fabOnReact committed Mar 25, 2022
1 parent b578637 commit 1e54f76
Show file tree
Hide file tree
Showing 12 changed files with 83 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextWatcher;
import android.util.Log;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.View;
Expand Down Expand Up @@ -1301,6 +1302,7 @@ public Object updateState(
}

ReadableNativeMap state = stateWrapper.getStateData();
Log.w("TESTING::ReactTextInputManager", "state: " + (state));

if (state == null) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ TextAttributes TextAttributes::defaultTextAttributes() {
textAttributes.backgroundColor = clearColor();
textAttributes.fontSize = 14.0;
textAttributes.fontSizeMultiplier = 1.0;
textAttributes.errorMessageAndroid = "TextAttributes defaultTextAttributes";
return textAttributes;
}();
return textAttributes;
Expand Down
4 changes: 3 additions & 1 deletion ReactCommon/react/renderer/attributedstring/TextAttributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class TextAttributes : public DebugStringConvertible {
// construction.
std::optional<LayoutDirection> layoutDirection{};
std::optional<AccessibilityRole> accessibilityRole{};
std::optional<std::string> errorMessageAndroid{"TextAttributes"};

#pragma mark - Operations

Expand Down Expand Up @@ -129,7 +130,8 @@ struct hash<facebook::react::TextAttributes> {
textAttributes.textShadowColor,
textAttributes.isHighlighted,
textAttributes.layoutDirection,
textAttributes.accessibilityRole);
textAttributes.accessibilityRole,
textAttributes.errorMessageAndroid);
}
};
} // namespace std
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ void ParagraphShadowNode::updateStateIfNeeded(Content const &content) {
return;
}

// content.attributedString.errorMessageAndroid = "updateStateIfNeeded";
setStateData(ParagraphState{
content.attributedString,
content.paragraphAttributes,
Expand All @@ -132,6 +133,7 @@ Size ParagraphShadowNode::measureContent(
auto string = BaseTextShadowNode::getEmptyPlaceholder();
auto textAttributes = TextAttributes::defaultTextAttributes();
textAttributes.fontSizeMultiplier = layoutContext.fontSizeMultiplier;
textAttributes.errorMessageAndroid = "error";
textAttributes.apply(getConcreteProps().textAttributes);
attributedString.appendFragment({string, textAttributes, {}});
}
Expand Down
5 changes: 3 additions & 2 deletions ReactCommon/react/renderer/components/text/conversions.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ inline folly::dynamic toDynamic(ParagraphState const &paragraphState) {
folly::dynamic newState = folly::dynamic::object();
newState["attributedString"] = toDynamic(paragraphState.attributedString);
newState["paragraphAttributes"] =
toDynamic(paragraphState.paragraphAttributes);
newState["hash"] = newState["attributedString"]["hash"];
toDynamic(paragraphState.paragraphAttributes);
newState["hash"] = 1987; // newState["attributedString"]["hash"];
newState["errorMessageAndroid"] = "conversions.h";
return newState;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <yoga/YGValue.h>

#include <react/renderer/core/ConcreteComponentDescriptor.h>

#include <string>
namespace facebook {
namespace react {

Expand Down Expand Up @@ -70,6 +70,7 @@ class AndroidTextInputComponentDescriptor final
env->DeleteLocalRef(defaultTextInputPaddingArray);
}

std::string error = "AndroidTextInputComponentDescriptor";
return std::make_shared<AndroidTextInputShadowNode::ConcreteState>(
std::make_shared<AndroidTextInputState const>(AndroidTextInputState(
0,
Expand All @@ -81,7 +82,8 @@ class AndroidTextInputComponentDescriptor final
((YGValue)theme[YGEdgeStart]).value,
((YGValue)theme[YGEdgeEnd]).value,
((YGValue)theme[YGEdgeTop]).value,
((YGValue)theme[YGEdgeBottom]).value)),
((YGValue)theme[YGEdgeBottom]).value,
error)),
family);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,42 @@ AndroidTextInputProps::AndroidTextInputProps(
"autoComplete",
sourceProps.autoComplete,
{})),
returnKeyLabel(convertRawProp(context, rawProps,
returnKeyLabel(convertRawProp(
context,
rawProps,
"returnKeyLabel",
sourceProps.returnKeyLabel,
{})),
numberOfLines(convertRawProp(context, rawProps,
numberOfLines(convertRawProp(
context,
rawProps,
"numberOfLines",
sourceProps.numberOfLines,
{0})),
disableFullscreenUI(convertRawProp(context, rawProps,
disableFullscreenUI(convertRawProp(
context,
rawProps,
"disableFullscreenUI",
sourceProps.disableFullscreenUI,
{false})),
textBreakStrategy(convertRawProp(context, rawProps,
textBreakStrategy(convertRawProp(
context,
rawProps,
"textBreakStrategy",
sourceProps.textBreakStrategy,
{})),
underlineColorAndroid(convertRawProp(context, rawProps,
underlineColorAndroid(convertRawProp(
context,
rawProps,
"underlineColorAndroid",
sourceProps.underlineColorAndroid,
{})),
errorMessageAndroid(convertRawProp(
context,
rawProps,
"errorMessageAndroid",
sourceProps.errorMessageAndroid,
{})),
inlineImageLeft(convertRawProp(context, rawProps,
"inlineImageLeft",
sourceProps.inlineImageLeft,
Expand Down Expand Up @@ -267,6 +283,7 @@ folly::dynamic AndroidTextInputProps::getDynamic() const {
props["disableFullscreenUI"] = disableFullscreenUI;
props["textBreakStrategy"] = textBreakStrategy;
props["underlineColorAndroid"] = toAndroidRepr(underlineColorAndroid);
props["errorMessageAndroid"] = errorMessageAndroid;
props["inlineImageLeft"] = inlineImageLeft;
props["inlineImagePadding"] = inlineImagePadding;
props["importantForAutofill"] = importantForAutofill;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class AndroidTextInputProps final : public ViewProps, public BaseTextProps {
const bool disableFullscreenUI{false};
const std::string textBreakStrategy{};
const SharedColor underlineColorAndroid{};
const std::string errorMessageAndroid{};
const std::string inlineImageLeft{};
const int inlineImagePadding{0};
const std::string importantForAutofill{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include "AndroidTextInputShadowNode.h"

#include <glog/logging.h>
#include <fbjni/fbjni.h>
#include <react/debug/react_native_assert.h>
#include <react/jni/ReadableNativeMap.h>
Expand All @@ -16,7 +17,7 @@
#include <react/renderer/core/LayoutConstraints.h>
#include <react/renderer/core/LayoutContext.h>
#include <react/renderer/core/conversions.h>

#include <string>
#include <utility>

using namespace facebook::jni;
Expand Down Expand Up @@ -146,12 +147,18 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {
? 0
: getConcreteProps().mostRecentEventCount);
auto newAttributedString = getMostRecentAttributedString();

// std::string mostRecentEventCountToString =
// std::to_string(state.mostRecentEventCount);
// std::string defaultTextAttributesToString =
// std::to_string(defaultTextAttributes);
// LOG(ERROR) << "TESTING: state.errorMessageAndroid" + state.errorMessageAndroid;
// LOG(ERROR) << "TESTING: defaultTextAttributes" + defaultTextAttributesToString;
// Even if we're here and updating state, it may be only to update the layout
// manager If that is the case, make sure we don't update text: pass in the
// current attributedString unchanged, and pass in zero for the "event count"
// so no changes are applied There's no way to prevent a state update from
// flowing to Java, so we just ensure it's a noop in those cases.
std::string test = "AndroidTextInputShadowNode";
setStateData(AndroidTextInputState{
newEventCount,
newAttributedString,
Expand All @@ -162,7 +169,8 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {
state.defaultThemePaddingStart,
state.defaultThemePaddingEnd,
state.defaultThemePaddingTop,
state.defaultThemePaddingBottom});
state.defaultThemePaddingBottom,
test});
}

#pragma mark - LayoutableShadowNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/

#include "AndroidTextInputState.h"
#include <glog/logging.h>

#include <logger/react_native_log.h>
#include <glog/logging.h>
#include <logger/react_native_log.h>
#include "AndroidTextInputState.h"
#include <iostream>
#include <react/renderer/components/text/conversions.h>
#include <react/renderer/debug/debugStringConvertibleUtils.h>
#include <string>

#include <utility>

using namespace std;
namespace facebook {
namespace react {

Expand All @@ -25,7 +31,8 @@ AndroidTextInputState::AndroidTextInputState(
float defaultThemePaddingStart,
float defaultThemePaddingEnd,
float defaultThemePaddingTop,
float defaultThemePaddingBottom)
float defaultThemePaddingBottom,
std::string defaultErrorMessageAndroid)
: mostRecentEventCount(mostRecentEventCount),
attributedString(std::move(attributedString)),
reactTreeAttributedString(std::move(reactTreeAttributedString)),
Expand All @@ -35,7 +42,8 @@ AndroidTextInputState::AndroidTextInputState(
defaultThemePaddingStart(defaultThemePaddingStart),
defaultThemePaddingEnd(defaultThemePaddingEnd),
defaultThemePaddingTop(defaultThemePaddingTop),
defaultThemePaddingBottom(defaultThemePaddingBottom) {}
defaultThemePaddingBottom(defaultThemePaddingBottom),
defaultErrorMessageAndroid(defaultErrorMessageAndroid) {}

AndroidTextInputState::AndroidTextInputState(
AndroidTextInputState const &previousState,
Expand All @@ -51,6 +59,7 @@ AndroidTextInputState::AndroidTextInputState(
attributedString(previousState.attributedString),
reactTreeAttributedString(previousState.reactTreeAttributedString),
paragraphAttributes(previousState.paragraphAttributes),
errorMessageAndroid(previousState.errorMessageAndroid),
defaultTextAttributes(previousState.defaultTextAttributes),
defaultParentShadowView(previousState.defaultParentShadowView),
defaultThemePaddingStart(data.getDefault(
Expand All @@ -68,7 +77,11 @@ AndroidTextInputState::AndroidTextInputState(
defaultThemePaddingBottom(data.getDefault(
"themePaddingBottom",
previousState.defaultThemePaddingBottom)
.getDouble()){};
.getDouble()),
defaultErrorMessageAndroid(data.getDefault(
"defaultErrorMessageAndroid",
previousState.defaultErrorMessageAndroid)
.getString()) {};

#ifdef ANDROID
folly::dynamic AndroidTextInputState::getDynamic() const {
Expand All @@ -80,12 +93,14 @@ folly::dynamic AndroidTextInputState::getDynamic() const {
// called from Java to trigger a relayout with a `cachedAttributedStringId`,
// so Java has all up-to-date information and we should pass an empty map
// through.

if (cachedAttributedStringId == 0) {
newState["mostRecentEventCount"] = mostRecentEventCount;
newState["attributedString"] = toDynamic(attributedString);
newState["hash"] = newState["attributedString"]["hash"];
newState["paragraphAttributes"] =
toDynamic(paragraphAttributes); // TODO: can we memoize this in Java?
newState["paragraphAttributes"] = toDynamic(
paragraphAttributes); // TODO: can we memoize this in Java?
newState["errorMessageAndroid"] = errorMessageAndroid;
}
return newState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <react/renderer/attributedstring/AttributedString.h>
#include <react/renderer/attributedstring/ParagraphAttributes.h>
#include <react/renderer/textlayoutmanager/TextLayoutManager.h>
#include <string>

#ifdef ANDROID
#include <folly/dynamic.h>
Expand Down Expand Up @@ -54,6 +55,8 @@ class AndroidTextInputState final {
*/
ParagraphAttributes paragraphAttributes{};

std::string errorMessageAndroid{};

/**
* Default TextAttributes used if we need to construct a new Fragment.
* Only used if text is inserted into an AttributedString with no existing
Expand All @@ -76,6 +79,7 @@ class AndroidTextInputState final {
float defaultThemePaddingEnd{NAN};
float defaultThemePaddingTop{NAN};
float defaultThemePaddingBottom{NAN};
std::string defaultErrorMessageAndroid{};

AndroidTextInputState(
int64_t mostRecentEventCount,
Expand All @@ -87,7 +91,8 @@ class AndroidTextInputState final {
float defaultThemePaddingStart,
float defaultThemePaddingEnd,
float defaultThemePaddingTop,
float defaultThemePaddingBottom);
float defaultThemePaddingBottom,
std::string defaultErrorMessageAndroid);

AndroidTextInputState() = default;
AndroidTextInputState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ TextInputProps::TextInputProps(
"underlineColorAndroid",
sourceProps.underlineColorAndroid,
{})),
errorMessageAndroid(convertRawProp(
context,
rawProps,
"errorMessageAndroid",
sourceProps.errorMessageAndroid,
{})),
text(convertRawProp(context, rawProps, "text", sourceProps.text, {})),
mostRecentEventCount(convertRawProp(
context,
Expand Down

0 comments on commit 1e54f76

Please sign in to comment.