@@ -49,6 +49,54 @@ static std::string convertFontWeight(
4949 return convertRawProp (context, rawProps, " fontWeight" , sourceValue, {});
5050}
5151
52+ static AndroidTextInputEvents convertRawProp (
53+ const PropsParserContext& context,
54+ const RawProps& rawProps,
55+ const AndroidTextInputEvents& sourceValue) {
56+ using Offset = AndroidTextInputEvents::Offset;
57+ AndroidTextInputEvents result{};
58+ result.set (
59+ Offset::KeyPress,
60+ convertRawProp (
61+ context,
62+ rawProps,
63+ " onKeyPress" ,
64+ sourceValue[Offset::KeyPress],
65+ false ));
66+ result.set (
67+ Offset::SelectionChange,
68+ convertRawProp (
69+ context,
70+ rawProps,
71+ " onSelectionChange" ,
72+ sourceValue[Offset::SelectionChange],
73+ false ));
74+ result.set (
75+ Offset::ContentSizeChange,
76+ convertRawProp (
77+ context,
78+ rawProps,
79+ " onContentSizeChange" ,
80+ sourceValue[Offset::ContentSizeChange],
81+ false ));
82+ result.set (
83+ Offset::Scroll,
84+ convertRawProp (
85+ context, rawProps, " onScroll" , sourceValue[Offset::Scroll], false ));
86+ return result;
87+ }
88+
89+ static void updateEventProp (
90+ folly::dynamic& result,
91+ const AndroidTextInputEvents& newEvents,
92+ const AndroidTextInputEvents& oldEvents,
93+ AndroidTextInputEvents::Offset offset,
94+ const char * name) {
95+ if (newEvents[offset] != oldEvents[offset]) {
96+ result[name] = newEvents[offset];
97+ }
98+ }
99+
52100AndroidTextInputProps::AndroidTextInputProps (
53101 const PropsParserContext &context,
54102 const AndroidTextInputProps &sourceProps,
@@ -167,16 +215,7 @@ AndroidTextInputProps::AndroidTextInputProps(
167215 {false })),
168216 fontWeight(convertFontWeight(context, rawProps, sourceProps.fontWeight)),
169217 fontFamily(convertRawProp(context, rawProps, " fontFamily" , sourceProps.fontFamily, {})),
170- onKeyPress(convertRawProp(context, rawProps, " onKeyPress" , sourceProps.onKeyPress, {false })),
171- onSelectionChange(convertRawProp(context, rawProps,
172- " onSelectionChange" ,
173- sourceProps.onSelectionChange,
174- {false })),
175- onContentSizeChange(convertRawProp(context, rawProps,
176- " onContentSizeChange" ,
177- sourceProps.onContentSizeChange,
178- {false })),
179- onScroll(convertRawProp(context, rawProps, " onScroll" , sourceProps.onScroll, {false })),
218+ textInputEvents(convertRawProp(context, rawProps, sourceProps.textInputEvents)),
180219 // See AndroidTextInputComponentDescriptor for usage
181220 // TODO T63008435: can these, and this feature, be removed entirely?
182221 hasPadding(hasValue(rawProps, sourceProps.hasPadding, " padding" )),
@@ -208,6 +247,16 @@ AndroidTextInputProps::AndroidTextInputProps(
208247 hasPaddingEnd(hasValue(rawProps, sourceProps.hasPaddingEnd, " paddingEnd" )) {
209248}
210249
250+ #define TEXT_INPUT_EVENT_CASE (eventType ) \
251+ case CONSTEXPR_RAW_PROPS_KEY_HASH (" on" #eventType): { \
252+ bool res = false ; \
253+ if (value.hasValue ()) { \
254+ fromRawValue (context, value, res); \
255+ } \
256+ textInputEvents.set (AndroidTextInputEvents::Offset::eventType, res); \
257+ return ; \
258+ }
259+
211260void AndroidTextInputProps::setProp (
212261 const PropsParserContext& context,
213262 RawPropsPropNameHash hash,
@@ -252,10 +301,10 @@ void AndroidTextInputProps::setProp(
252301 RAW_SET_PROP_SWITCH_CASE_BASIC (textAlign);
253302 RAW_SET_PROP_SWITCH_CASE_BASIC (includeFontPadding);
254303 RAW_SET_PROP_SWITCH_CASE_BASIC (fontFamily);
255- RAW_SET_PROP_SWITCH_CASE_BASIC (onKeyPress );
256- RAW_SET_PROP_SWITCH_CASE_BASIC (onSelectionChange );
257- RAW_SET_PROP_SWITCH_CASE_BASIC (onContentSizeChange );
258- RAW_SET_PROP_SWITCH_CASE_BASIC (onScroll );
304+ TEXT_INPUT_EVENT_CASE (KeyPress );
305+ TEXT_INPUT_EVENT_CASE (SelectionChange );
306+ TEXT_INPUT_EVENT_CASE (ContentSizeChange );
307+ TEXT_INPUT_EVENT_CASE (Scroll );
259308
260309 case CONSTEXPR_RAW_PROPS_KEY_HASH (" value" ): {
261310 fromRawValue (context, value, this ->value , {});
@@ -665,20 +714,25 @@ folly::dynamic AndroidTextInputProps::getDiffProps(
665714 : folly::dynamic (nullptr );
666715 }
667716
668- if (onKeyPress != oldProps->onKeyPress ) {
669- result[" onKeyPress" ] = onKeyPress;
670- }
671-
672- if (onSelectionChange != oldProps->onSelectionChange ) {
673- result[" onSelectionChange" ] = onSelectionChange;
674- }
675-
676- if (onContentSizeChange != oldProps->onContentSizeChange ) {
677- result[" onContentSizeChange" ] = onContentSizeChange;
678- }
679-
680- if (onScroll != oldProps->onScroll ) {
681- result[" onScroll" ] = onScroll;
717+ if (textInputEvents != oldProps->textInputEvents ) {
718+ using Offset = AndroidTextInputEvents::Offset;
719+ const auto & oldEvents = oldProps->textInputEvents ;
720+ updateEventProp (
721+ result, textInputEvents, oldEvents, Offset::KeyPress, " onKeyPress" );
722+ updateEventProp (
723+ result,
724+ textInputEvents,
725+ oldEvents,
726+ Offset::SelectionChange,
727+ " onSelectionChange" );
728+ updateEventProp (
729+ result,
730+ textInputEvents,
731+ oldEvents,
732+ Offset::ContentSizeChange,
733+ " onContentSizeChange" );
734+ updateEventProp (
735+ result, textInputEvents, oldEvents, Offset::Scroll, " onScroll" );
682736 }
683737
684738 return result;
0 commit comments