Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions change/react-native-windows-fix-textinput-placeholder.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Fix placeholder layout constraints fed physical px instead of DIPs; fix no-op NaN fontSize guard in CreatePlaceholderLayout",
"packageName": "react-native-windows",
"email": "collindanielschneide@gmail.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1690,16 +1690,21 @@ winrt::com_ptr<::IDWriteTextLayout> WindowsTextInputComponentView::CreatePlaceho
const auto &props = windowsTextInputProps();
facebook::react::TextAttributes textAttributes = props.textAttributes;
if (std::isnan(props.textAttributes.fontSize)) {
facebook::react::TextAttributes::defaultTextAttributes().fontSize;
textAttributes.fontSize = facebook::react::TextAttributes::defaultTextAttributes().fontSize;
}
textAttributes.fontSizeMultiplier = m_fontSizeMultiplier;
fragment1.string = props.placeholder;
fragment1.textAttributes = textAttributes;
attributedString.appendFragment(std::move(fragment1));

facebook::react::LayoutConstraints constraints;
constraints.maximumSize.width = static_cast<FLOAT>(m_imgWidth);
constraints.maximumSize.height = static_cast<FLOAT>(m_imgHeight);
// m_imgWidth/m_imgHeight are physical pixels (frame * pointScaleFactor), but
// LayoutConstraints are expressed in DIPs. Feeding physical px laid the
// placeholder out in a box pointScaleFactor x too large, so the placeholder was
// measured/positioned at a different height than the typed text. Convert to DIPs.
const float scale = m_layoutMetrics.pointScaleFactor != 0.0f ? m_layoutMetrics.pointScaleFactor : 1.0f;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont think we should need the != 0 protection here -- unless that is something you saw?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right — no, we didn't see it hit zero; that was purely defensive around the new division. LayoutMetrics::pointScaleFactor has a default member initializer of 1.0, and EmptyLayoutMetrics only designates .frame, so even the pre-layout sentinel inherits 1.0 — there's no normal path where it's 0 here. I'll drop the guard and just divide by m_layoutMetrics.pointScaleFactor.

constraints.maximumSize.width = static_cast<FLOAT>(m_imgWidth) / scale;
constraints.maximumSize.height = static_cast<FLOAT>(m_imgHeight) / scale;

facebook::react::WindowsTextLayoutManager::GetTextLayout(
facebook::react::AttributedStringBox(attributedString), {} /*TODO*/, constraints, textLayout);
Expand Down
Loading