Skip to content

Commit 08f89eb

Browse files
NickGerlemanfacebook-github-bot
authored andcommitted
Remove yoga::Style::Edges usage in AndroidTextInputComponentDescriptor (facebook#41598)
Summary: Pull Request resolved: facebook#41598 This code merges native, Android provided theme text input padding, with Yoga style. We are removing operations on all edges as aggregate, so this replaces that. This was previously part of D50998164 Changelog: [Internal] Reviewed By: javache Differential Revision: D51503493 fbshipit-source-id: c6e2f3183a05861745fdd8f044d12e3dd8205804
1 parent c4519a0 commit 08f89eb

File tree

1 file changed

+26
-27
lines changed

1 file changed

+26
-27
lines changed

packages/react-native/ReactCommon/react/renderer/components/textinput/androidtextinput/react/renderer/components/androidtextinput/AndroidTextInputComponentDescriptor.h

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class AndroidTextInputComponentDescriptor final
4040
const ShadowNodeFamily::Shared& family) const override {
4141
int surfaceId = family->getSurfaceId();
4242

43-
yoga::Style::Edges theme;
43+
ThemePadding theme;
4444
// TODO: figure out RTL/start/end/left/right stuff here
4545
if (surfaceIdToThemePaddingMap_.find(surfaceId) !=
4646
surfaceIdToThemePaddingMap_.end()) {
@@ -59,11 +59,10 @@ class AndroidTextInputComponentDescriptor final
5959
fabricUIManager, surfaceId, defaultTextInputPaddingArray)) {
6060
jfloat* defaultTextInputPadding =
6161
env->GetFloatArrayElements(defaultTextInputPaddingArray, 0);
62-
theme[YGEdgeStart] = (YGValue){defaultTextInputPadding[0], YGUnitPoint};
63-
theme[YGEdgeEnd] = (YGValue){defaultTextInputPadding[1], YGUnitPoint};
64-
theme[YGEdgeTop] = (YGValue){defaultTextInputPadding[2], YGUnitPoint};
65-
theme[YGEdgeBottom] =
66-
(YGValue){defaultTextInputPadding[3], YGUnitPoint};
62+
theme.start = defaultTextInputPadding[0];
63+
theme.end = defaultTextInputPadding[1];
64+
theme.top = defaultTextInputPadding[2];
65+
theme.bottom = defaultTextInputPadding[3];
6766
surfaceIdToThemePaddingMap_.emplace(std::make_pair(surfaceId, theme));
6867
env->ReleaseFloatArrayElements(
6968
defaultTextInputPaddingArray, defaultTextInputPadding, JNI_ABORT);
@@ -73,14 +72,7 @@ class AndroidTextInputComponentDescriptor final
7372

7473
return std::make_shared<AndroidTextInputShadowNode::ConcreteState>(
7574
std::make_shared<const AndroidTextInputState>(AndroidTextInputState(
76-
0,
77-
{},
78-
{},
79-
{},
80-
((YGValue)theme[YGEdgeStart]).value,
81-
((YGValue)theme[YGEdgeEnd]).value,
82-
((YGValue)theme[YGEdgeTop]).value,
83-
((YGValue)theme[YGEdgeBottom]).value)),
75+
0, {}, {}, {}, theme.start, theme.end, theme.top, theme.bottom)),
8476
family);
8577
}
8678

@@ -99,7 +91,7 @@ class AndroidTextInputComponentDescriptor final
9991
int surfaceId = textInputShadowNode.getSurfaceId();
10092
if (surfaceIdToThemePaddingMap_.find(surfaceId) !=
10193
surfaceIdToThemePaddingMap_.end()) {
102-
yoga::Style::Edges theme = surfaceIdToThemePaddingMap_[surfaceId];
94+
const auto& theme = surfaceIdToThemePaddingMap_[surfaceId];
10395

10496
auto& textInputProps = textInputShadowNode.getConcreteProps();
10597

@@ -108,29 +100,33 @@ class AndroidTextInputComponentDescriptor final
108100
// TODO: T62959168 account for RTL and paddingLeft when setting default
109101
// paddingStart, and vice-versa with paddingRight/paddingEnd.
110102
// For now this assumes no RTL.
111-
yoga::Style::Edges result = textInputProps.yogaStyle.padding();
103+
auto& style = const_cast<yoga::Style&>(textInputProps.yogaStyle);
112104
bool changedPadding = false;
113105
if (!textInputProps.hasPadding && !textInputProps.hasPaddingStart &&
114106
!textInputProps.hasPaddingLeft &&
115107
!textInputProps.hasPaddingHorizontal) {
116108
changedPadding = true;
117-
result[YGEdgeStart] = theme[YGEdgeStart];
109+
style.padding()[YGEdgeStart] =
110+
yoga::CompactValue::of<YGUnitPoint>(theme.start);
118111
}
119112
if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd &&
120113
!textInputProps.hasPaddingRight &&
121114
!textInputProps.hasPaddingHorizontal) {
122115
changedPadding = true;
123-
result[YGEdgeEnd] = theme[YGEdgeEnd];
116+
style.padding()[YGEdgeEnd] =
117+
yoga::CompactValue::of<YGUnitPoint>(theme.end);
124118
}
125119
if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop &&
126120
!textInputProps.hasPaddingVertical) {
127121
changedPadding = true;
128-
result[YGEdgeTop] = theme[YGEdgeTop];
122+
style.padding()[YGEdgeTop] =
123+
yoga::CompactValue::of<YGUnitPoint>(theme.top);
129124
}
130125
if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom &&
131126
!textInputProps.hasPaddingVertical) {
132127
changedPadding = true;
133-
result[YGEdgeBottom] = theme[YGEdgeBottom];
128+
style.padding()[YGEdgeBottom] =
129+
yoga::CompactValue::of<YGUnitPoint>(theme.bottom);
134130
}
135131

136132
// If the TextInput initially does not have paddingLeft or paddingStart, a
@@ -141,21 +137,18 @@ class AndroidTextInputComponentDescriptor final
141137
if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft ||
142138
textInputProps.hasPaddingHorizontal) &&
143139
!textInputProps.hasPaddingStart) {
144-
result[YGEdgeStart] = YGValueUndefined;
140+
style.padding()[YGEdgeStart] = yoga::CompactValue::ofUndefined();
145141
}
146142
if ((textInputProps.hasPadding || textInputProps.hasPaddingRight ||
147143
textInputProps.hasPaddingHorizontal) &&
148144
!textInputProps.hasPaddingEnd) {
149-
result[YGEdgeEnd] = YGValueUndefined;
145+
style.padding()[YGEdgeEnd] = yoga::CompactValue::ofUndefined();
150146
}
151147

152148
// Note that this is expensive: on every adopt, we need to set the Yoga
153149
// props again, which normally only happens during prop parsing. Every
154150
// commit, state update, etc, will incur this cost.
155151
if (changedPadding) {
156-
// Set new props on node
157-
const_cast<AndroidTextInputProps&>(textInputProps).yogaStyle.padding() =
158-
result;
159152
// Communicate new props to Yoga part of the node
160153
textInputShadowNode.updateYogaProps();
161154
}
@@ -168,13 +161,19 @@ class AndroidTextInputComponentDescriptor final
168161
}
169162

170163
private:
164+
struct ThemePadding {
165+
float start{};
166+
float end{};
167+
float top{};
168+
float bottom{};
169+
};
170+
171171
// TODO T68526882: Unify with Binding::UIManagerJavaDescriptor
172172
constexpr static auto UIManagerJavaDescriptor =
173173
"com/facebook/react/fabric/FabricUIManager";
174174

175175
SharedTextLayoutManager textLayoutManager_;
176-
mutable std::unordered_map<int, yoga::Style::Edges>
177-
surfaceIdToThemePaddingMap_;
176+
mutable std::unordered_map<int, ThemePadding> surfaceIdToThemePaddingMap_;
178177
};
179178

180179
} // namespace facebook::react

0 commit comments

Comments
 (0)