@@ -40,7 +40,7 @@ class AndroidTextInputComponentDescriptor final
40
40
const ShadowNodeFamily::Shared& family) const override {
41
41
int surfaceId = family->getSurfaceId ();
42
42
43
- yoga::Style::Edges theme;
43
+ ThemePadding theme;
44
44
// TODO: figure out RTL/start/end/left/right stuff here
45
45
if (surfaceIdToThemePaddingMap_.find (surfaceId) !=
46
46
surfaceIdToThemePaddingMap_.end ()) {
@@ -59,11 +59,10 @@ class AndroidTextInputComponentDescriptor final
59
59
fabricUIManager, surfaceId, defaultTextInputPaddingArray)) {
60
60
jfloat* defaultTextInputPadding =
61
61
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 ];
67
66
surfaceIdToThemePaddingMap_.emplace (std::make_pair (surfaceId, theme));
68
67
env->ReleaseFloatArrayElements (
69
68
defaultTextInputPaddingArray, defaultTextInputPadding, JNI_ABORT);
@@ -73,14 +72,7 @@ class AndroidTextInputComponentDescriptor final
73
72
74
73
return std::make_shared<AndroidTextInputShadowNode::ConcreteState>(
75
74
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 )),
84
76
family);
85
77
}
86
78
@@ -99,7 +91,7 @@ class AndroidTextInputComponentDescriptor final
99
91
int surfaceId = textInputShadowNode.getSurfaceId ();
100
92
if (surfaceIdToThemePaddingMap_.find (surfaceId) !=
101
93
surfaceIdToThemePaddingMap_.end ()) {
102
- yoga::Style::Edges theme = surfaceIdToThemePaddingMap_[surfaceId];
94
+ const auto & theme = surfaceIdToThemePaddingMap_[surfaceId];
103
95
104
96
auto & textInputProps = textInputShadowNode.getConcreteProps ();
105
97
@@ -108,29 +100,33 @@ class AndroidTextInputComponentDescriptor final
108
100
// TODO: T62959168 account for RTL and paddingLeft when setting default
109
101
// paddingStart, and vice-versa with paddingRight/paddingEnd.
110
102
// For now this assumes no RTL.
111
- yoga::Style::Edges result = textInputProps.yogaStyle . padding ( );
103
+ auto & style = const_cast <yoga::Style&>( textInputProps.yogaStyle );
112
104
bool changedPadding = false ;
113
105
if (!textInputProps.hasPadding && !textInputProps.hasPaddingStart &&
114
106
!textInputProps.hasPaddingLeft &&
115
107
!textInputProps.hasPaddingHorizontal ) {
116
108
changedPadding = true ;
117
- result[YGEdgeStart] = theme[YGEdgeStart];
109
+ style.padding ()[YGEdgeStart] =
110
+ yoga::CompactValue::of<YGUnitPoint>(theme.start );
118
111
}
119
112
if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd &&
120
113
!textInputProps.hasPaddingRight &&
121
114
!textInputProps.hasPaddingHorizontal ) {
122
115
changedPadding = true ;
123
- result[YGEdgeEnd] = theme[YGEdgeEnd];
116
+ style.padding ()[YGEdgeEnd] =
117
+ yoga::CompactValue::of<YGUnitPoint>(theme.end );
124
118
}
125
119
if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop &&
126
120
!textInputProps.hasPaddingVertical ) {
127
121
changedPadding = true ;
128
- result[YGEdgeTop] = theme[YGEdgeTop];
122
+ style.padding ()[YGEdgeTop] =
123
+ yoga::CompactValue::of<YGUnitPoint>(theme.top );
129
124
}
130
125
if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom &&
131
126
!textInputProps.hasPaddingVertical ) {
132
127
changedPadding = true ;
133
- result[YGEdgeBottom] = theme[YGEdgeBottom];
128
+ style.padding ()[YGEdgeBottom] =
129
+ yoga::CompactValue::of<YGUnitPoint>(theme.bottom );
134
130
}
135
131
136
132
// If the TextInput initially does not have paddingLeft or paddingStart, a
@@ -141,21 +137,18 @@ class AndroidTextInputComponentDescriptor final
141
137
if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft ||
142
138
textInputProps.hasPaddingHorizontal ) &&
143
139
!textInputProps.hasPaddingStart ) {
144
- result [YGEdgeStart] = YGValueUndefined ;
140
+ style. padding () [YGEdgeStart] = yoga::CompactValue::ofUndefined () ;
145
141
}
146
142
if ((textInputProps.hasPadding || textInputProps.hasPaddingRight ||
147
143
textInputProps.hasPaddingHorizontal ) &&
148
144
!textInputProps.hasPaddingEnd ) {
149
- result [YGEdgeEnd] = YGValueUndefined ;
145
+ style. padding () [YGEdgeEnd] = yoga::CompactValue::ofUndefined () ;
150
146
}
151
147
152
148
// Note that this is expensive: on every adopt, we need to set the Yoga
153
149
// props again, which normally only happens during prop parsing. Every
154
150
// commit, state update, etc, will incur this cost.
155
151
if (changedPadding) {
156
- // Set new props on node
157
- const_cast <AndroidTextInputProps&>(textInputProps).yogaStyle .padding () =
158
- result;
159
152
// Communicate new props to Yoga part of the node
160
153
textInputShadowNode.updateYogaProps ();
161
154
}
@@ -168,13 +161,19 @@ class AndroidTextInputComponentDescriptor final
168
161
}
169
162
170
163
private:
164
+ struct ThemePadding {
165
+ float start{};
166
+ float end{};
167
+ float top{};
168
+ float bottom{};
169
+ };
170
+
171
171
// TODO T68526882: Unify with Binding::UIManagerJavaDescriptor
172
172
constexpr static auto UIManagerJavaDescriptor =
173
173
" com/facebook/react/fabric/FabricUIManager" ;
174
174
175
175
SharedTextLayoutManager textLayoutManager_;
176
- mutable std::unordered_map<int , yoga::Style::Edges>
177
- surfaceIdToThemePaddingMap_;
176
+ mutable std::unordered_map<int , ThemePadding> surfaceIdToThemePaddingMap_;
178
177
};
179
178
180
179
} // namespace facebook::react
0 commit comments