Fix TextInput left/right padding

Summary:
This fixes two things:

1) Currently it only respects Start and End padding, and if there's a Theme default, it will override Left/Right padding. Whoops.
2) Currently it doesn't respect when a TextInput starts with padding, but then is removed.

This resolves both.

It still does not account for RTL support.

Changelog: [Internal] Fix AndroidTextInput padding

Reviewed By: mdvacca

Differential Revision: D20573151

fbshipit-source-id: e89791641b6699e728cde9dbd661a8c21485fbc8
This commit is contained in:
Joshua Gross authored and Facebook GitHub Bot committed 2020-03-20 18:47:31 -07:00
1 parent 987b902dc0
commit fb9a7be2bd
3 files changed
+103 -33

No files matched your search

@@ -107,27 +107,56 @@ class AndroidTextInputComponentDescriptor final
// Override padding
// Node is still unsealed during adoption, before layout is complete
// TODO: T62959168 account for RTL and paddingLeft when setting default
// paddingStart, and vice-versa with paddingRight/paddingEnd
// paddingStart, and vice-versa with paddingRight/paddingEnd.
// For now this assumes no RTL.
YGStyle::Edges result =
textInputShadowNode->getConcreteProps().yogaStyle.padding();
bool changedPadding = false;
if (!textInputShadowNode->getConcreteProps().hasPaddingStart) {
if (!textInputShadowNode->getConcreteProps().hasPadding &&
!textInputShadowNode->getConcreteProps().hasPaddingStart &&
!textInputShadowNode->getConcreteProps().hasPaddingLeft &&
!textInputShadowNode->getConcreteProps().hasPaddingHorizontal) {
changedPadding = true;
result[YGEdgeStart] = theme[YGEdgeStart];
}
if (!textInputShadowNode->getConcreteProps().hasPaddingEnd) {
if (!textInputShadowNode->getConcreteProps().hasPadding &&
!textInputShadowNode->getConcreteProps().hasPaddingEnd &&
!textInputShadowNode->getConcreteProps().hasPaddingRight &&
!textInputShadowNode->getConcreteProps().hasPaddingHorizontal) {
changedPadding = true;
result[YGEdgeEnd] = theme[YGEdgeEnd];
}
if (!textInputShadowNode->getConcreteProps().hasPaddingTop) {
if (!textInputShadowNode->getConcreteProps().hasPadding &&
!textInputShadowNode->getConcreteProps().hasPaddingTop &&
!textInputShadowNode->getConcreteProps().hasPaddingVertical) {
changedPadding = true;
result[YGEdgeTop] = theme[YGEdgeTop];
}
if (!textInputShadowNode->getConcreteProps().hasPaddingBottom) {
if (!textInputShadowNode->getConcreteProps().hasPadding &&
!textInputShadowNode->getConcreteProps().hasPaddingBottom &&
!textInputShadowNode->getConcreteProps().hasPaddingVertical) {
changedPadding = true;
result[YGEdgeBottom] = theme[YGEdgeBottom];
}
// If the TextInput initially does not have paddingLeft or paddingStart, a
// paddingStart may be set from the theme. If that happens, when there's a
// paddingLeft update, we must explicitly unset paddingStart... (same with
// paddingEnd)
// TODO: support RTL
if ((textInputShadowNode->getConcreteProps().hasPadding ||
textInputShadowNode->getConcreteProps().hasPaddingLeft ||
textInputShadowNode->getConcreteProps().hasPaddingHorizontal) &&
!textInputShadowNode->getConcreteProps().hasPaddingStart) {
result[YGEdgeStart] = YGValueUndefined;
}
if ((textInputShadowNode->getConcreteProps().hasPadding ||
textInputShadowNode->getConcreteProps().hasPaddingRight ||
textInputShadowNode->getConcreteProps().hasPaddingHorizontal) &&
!textInputShadowNode->getConcreteProps().hasPaddingEnd) {
result[YGEdgeEnd] = YGValueUndefined;
}
// Note that this is expensive: on every adopt, we need to set the Yoga
// props again, which normally only happens during prop parsing. Every
// commit, state update, etc, will incur this cost.