Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@ AndroidTextInputProps::AndroidTextInputProps(
{false})),
fontWeight(convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})),
fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
onKeyPress(convertRawProp(context, rawProps, "onKeyPress", sourceProps.onKeyPress, {false})),
onSelectionChange(convertRawProp(context, rawProps,
"onSelectionChange",
sourceProps.onSelectionChange,
{false})),
onContentSizeChange(convertRawProp(context, rawProps,
"onContentSizeChange",
sourceProps.onContentSizeChange,
{false})),
onScroll(convertRawProp(context, rawProps, "onScroll", sourceProps.onScroll, {false})),
// See AndroidTextInputComponentDescriptor for usage
// TODO T63008435: can these, and this feature, be removed entirely?
hasPadding(hasValue(rawProps, sourceProps.hasPadding, "padding")),
Expand Down Expand Up @@ -227,6 +237,10 @@ void AndroidTextInputProps::setProp(
RAW_SET_PROP_SWITCH_CASE_BASIC(includeFontPadding);
RAW_SET_PROP_SWITCH_CASE_BASIC(fontWeight);
RAW_SET_PROP_SWITCH_CASE_BASIC(fontFamily);
RAW_SET_PROP_SWITCH_CASE_BASIC(onKeyPress);
RAW_SET_PROP_SWITCH_CASE_BASIC(onSelectionChange);
RAW_SET_PROP_SWITCH_CASE_BASIC(onContentSizeChange);
RAW_SET_PROP_SWITCH_CASE_BASIC(onScroll);

case CONSTEXPR_RAW_PROPS_KEY_HASH("value"): {
fromRawValue(context, value, this->value, {});
Expand Down Expand Up @@ -628,6 +642,22 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
: folly::dynamic(nullptr);
}

if (onKeyPress != oldProps->onKeyPress) {
result["onKeyPress"] = onKeyPress;
}

if (onSelectionChange != oldProps->onSelectionChange) {
result["onSelectionChange"] = onSelectionChange;
}

if (onContentSizeChange != oldProps->onContentSizeChange) {
result["onContentSizeChange"] = onContentSizeChange;
}

if (onScroll != oldProps->onScroll) {
result["onScroll"] = onScroll;
}

return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ class AndroidTextInputProps final : public BaseTextInputProps {
std::string fontWeight{};
std::string fontFamily{};

/*
* Whether JS listens to these events. ReactTextInputManager only sets up the
* native watchers for them when these props are sent.
*/
bool onKeyPress{false};
bool onSelectionChange{false};
bool onContentSizeChange{false};
bool onScroll{false};

/**
* Auxiliary information to detect if these props are set or not.
* See AndroidTextInputComponentDescriptor for usage.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

#include <gtest/gtest.h>

#if defined(ANDROID) && defined(RN_SERIALIZABLE_STATE)

#include <react/renderer/components/androidtextinput/AndroidTextInputProps.h>
#include <react/test_utils/PropsPayloads.h>

namespace facebook::react {

// ReactTextInputManager only sets up the event watchers when these props are
// sent. JS sends a handler as `true`, and false resets it like null does.
TEST(AndroidTextInputPropsDiffTest, eventHandlerPropsAreSent) {
using folly::dynamic;
expectPayloadsMatchRawProps<AndroidTextInputProps>({
{dynamic::object("onKeyPress", true)("onSelectionChange", true)(
"onContentSizeChange", true)("onScroll", true)},
{dynamic::object("onKeyPress", nullptr)("onSelectionChange", nullptr)(
"onContentSizeChange", nullptr)("onScroll", nullptr),
dynamic::object("onKeyPress", false)("onSelectionChange", false)(
"onContentSizeChange", false)("onScroll", false)},
});
}

} // namespace facebook::react

#endif
4 changes: 4 additions & 0 deletions scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,10 @@ class facebook::react::AndroidTextInputProps : public facebook::react::BaseTextI
public bool hasPaddingTop;
public bool hasPaddingVertical;
public bool includeFontPadding;
public bool onContentSizeChange;
public bool onKeyPress;
public bool onScroll;
public bool onSelectionChange;
public bool secureTextEntry;
public bool selectTextOnFocus;
public bool showSoftInputOnFocus;
Expand Down
Loading