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;
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