Skip to content

Commit 6e3bc8a

Browse files
NickGerlemanpull[bot]
authored andcommitted
Fix AndroidTextInputProps Detection of Padding (#41643)
Summary: Pull Request resolved: #41643 Code in `AndroidTextInputComponentDescriptor` will rewrite Yoga props for padding based on Android theme, if a value isn't supplied. It determines this by adding props in `AndroidTextInputProps` which reads Yoga RawProps to tell if they were set. RawProps are keyed using separate prefix/name/suffix, instead of the combined string name of the prop. This means that searching for the name `paddingLeft`, would be different from reading one with a name of `padding` and a suffix of `Left`. This updates the keying, based on the changes in D51510562. We should refactor this in the future (D20109605, introducing this code, admitted as much). We already have a phase, for aliased props, where we transform input props into the Yoga style (they don't need to be 1:1). This doesn't depend on RawProps, extra props, or prop mutations. Changelog: [Android][Fixed] - Fix AndroidTextInputProps Detection of Padding Reviewed By: GijsWeterings Differential Revision: D51566900 fbshipit-source-id: ca744b23d71382941903da42d86ad3eef7b65de8
1 parent 5c141c2 commit 6e3bc8a

File tree

1 file changed

+12
-28
lines changed
  • packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput

1 file changed

+12
-28
lines changed

packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputProps.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,9 @@
1313

1414
namespace facebook::react {
1515

16-
static bool hasValue(
17-
const RawProps& rawProps,
18-
bool defaultValue,
19-
const char* name,
20-
const char* prefix,
21-
const char* suffix) {
22-
auto rawValue = rawProps.at(name, prefix, suffix);
16+
static bool
17+
hasValue(const RawProps& rawProps, bool defaultValue, const char* name) {
18+
auto rawValue = rawProps.at(name, nullptr, nullptr);
2319

2420
// No change to prop - use default
2521
if (rawValue == nullptr) {
@@ -217,47 +213,35 @@ AndroidTextInputProps::AndroidTextInputProps(
217213
convertRawProp(context, rawProps, sourceProps.paragraphAttributes, {})),
218214
// See AndroidTextInputComponentDescriptor for usage
219215
// TODO T63008435: can these, and this feature, be removed entirely?
220-
hasPadding(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPadding : hasValue(rawProps, sourceProps.hasPadding, "", "padding", "")),
216+
hasPadding(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPadding : hasValue(rawProps, sourceProps.hasPadding, "padding")),
221217
hasPaddingHorizontal(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingHorizontal : hasValue(
222218
rawProps,
223219
sourceProps.hasPaddingHorizontal,
224-
"Horizontal",
225-
"padding",
226-
"")),
220+
"paddingHorizontal")),
227221
hasPaddingVertical(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingVertical : hasValue(
228222
rawProps,
229223
sourceProps.hasPaddingVertical,
230-
"Vertical",
231-
"padding",
232-
"")),
224+
"paddingVertical")),
233225
hasPaddingLeft(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingLeft : hasValue(
234226
rawProps,
235227
sourceProps.hasPaddingLeft,
236-
"Left",
237-
"padding",
238-
"")),
228+
"paddingLeft")),
239229
hasPaddingTop(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingTop :
240-
hasValue(rawProps, sourceProps.hasPaddingTop, "Top", "padding", "")),
230+
hasValue(rawProps, sourceProps.hasPaddingTop, "paddingTop")),
241231
hasPaddingRight(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingRight : hasValue(
242232
rawProps,
243233
sourceProps.hasPaddingRight,
244-
"Right",
245-
"padding",
246-
"")),
234+
"paddingRight")),
247235
hasPaddingBottom(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingBottom : hasValue(
248236
rawProps,
249237
sourceProps.hasPaddingBottom,
250-
"Bottom",
251-
"padding",
252-
"")),
238+
"paddingBottom")),
253239
hasPaddingStart(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingStart : hasValue(
254240
rawProps,
255241
sourceProps.hasPaddingStart,
256-
"Start",
257-
"padding",
258-
"")),
242+
"paddingStart")),
259243
hasPaddingEnd(CoreFeatures::enablePropIteratorSetter? sourceProps.hasPaddingEnd :
260-
hasValue(rawProps, sourceProps.hasPaddingEnd, "End", "padding", "")) {
244+
hasValue(rawProps, sourceProps.hasPaddingEnd, "paddingEnd")) {
261245
}
262246

263247
void AndroidTextInputProps::setProp(

0 commit comments

Comments
 (0)