@@ -50,31 +50,23 @@ AttributedString AndroidTextInputShadowNode::getAttributedString() const {
50
50
fragment.textAttributes .backgroundColor = clearColor ();
51
51
fragment.parentShadowView = ShadowView (*this );
52
52
attributedString.prependFragment (fragment);
53
-
54
- // We know this is not empty, because we at least have the `text` value
55
- return attributedString;
56
- }
57
-
58
- // No need to use placeholder if we have text at this point.
59
- if (!attributedString.isEmpty ()) {
60
- return attributedString;
61
53
}
62
54
63
- return getPlaceholderAttributedString ( false ) ;
55
+ return attributedString ;
64
56
}
65
57
66
58
// For measurement purposes, we want to make sure that there's at least a
67
59
// single character in the string so that the measured height is greater
68
60
// than zero. Otherwise, empty TextInputs with no placeholder don't
69
61
// display at all.
70
- AttributedString AndroidTextInputShadowNode::getPlaceholderAttributedString (
71
- bool ensureMinimumLength) const {
62
+ AttributedString AndroidTextInputShadowNode::getPlaceholderAttributedString ()
63
+ const {
72
64
// Return placeholder text, since text and children are empty.
73
65
auto textAttributedString = AttributedString{};
74
66
auto fragment = AttributedString::Fragment{};
75
67
fragment.string = getProps ()->placeholder ;
76
68
77
- if (fragment.string .empty () && ensureMinimumLength ) {
69
+ if (fragment.string .empty ()) {
78
70
fragment.string = " " ;
79
71
}
80
72
@@ -123,13 +115,23 @@ void AndroidTextInputShadowNode::updateStateIfNeeded() {
123
115
auto defaultTextAttributes = TextAttributes::defaultTextAttributes ();
124
116
defaultTextAttributes.apply (getProps ()->textAttributes );
125
117
126
- setStateData (AndroidTextInputState{state.mostRecentEventCount ,
127
- reactTreeAttributedString,
128
- reactTreeAttributedString,
129
- getProps ()->paragraphAttributes ,
130
- defaultTextAttributes,
131
- ShadowView (*this ),
132
- textLayoutManager_});
118
+ // Even if we're here and updating state, it may be only to update the layout
119
+ // manager If that is the case, make sure we don't update text: pass in the
120
+ // current attributedString unchanged, and pass in zero for the "event count"
121
+ // so no changes are applied There's no way to prevent a state update from
122
+ // flowing to Java, so we just ensure it's a noop in those cases.
123
+ setStateData (AndroidTextInputState{
124
+ (state.reactTreeAttributedString == reactTreeAttributedString
125
+ ? 0
126
+ : getProps ()->mostRecentEventCount ),
127
+ (state.reactTreeAttributedString == reactTreeAttributedString
128
+ ? state.attributedString
129
+ : reactTreeAttributedString),
130
+ reactTreeAttributedString,
131
+ getProps ()->paragraphAttributes ,
132
+ defaultTextAttributes,
133
+ ShadowView (*this ),
134
+ textLayoutManager_});
133
135
}
134
136
135
137
#pragma mark - LayoutableShadowNode
@@ -141,7 +143,7 @@ Size AndroidTextInputShadowNode::measure(
141
143
AttributedString attributedString = state.attributedString ;
142
144
143
145
if (attributedString.isEmpty ()) {
144
- attributedString = getPlaceholderAttributedString (true );
146
+ attributedString = getPlaceholderAttributedString ();
145
147
}
146
148
147
149
if (attributedString.isEmpty ()) {
0 commit comments