Skip to content

[Fabric] Implement maxFontSizeMultiplier in Text Input #14639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "[Fabric] Implement maxFontSizeMultiplier in Text Input",
"packageName": "react-native-windows",
"email": "54227869+anupriya13@users.noreply.github.com",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,10 @@ void WindowsTextInputComponentView::updateProps(
oldTextInputProps.textAttributes.fontWeight != newTextInputProps.textAttributes.fontWeight ||
!facebook::react::floatEquality(
oldTextInputProps.textAttributes.letterSpacing, newTextInputProps.textAttributes.letterSpacing) ||
oldTextInputProps.textAttributes.fontFamily != newTextInputProps.textAttributes.fontFamily) {
oldTextInputProps.textAttributes.fontFamily != newTextInputProps.textAttributes.fontFamily ||
!facebook::react::floatEquality(
oldTextInputProps.textAttributes.maxFontSizeMultiplier,
newTextInputProps.textAttributes.maxFontSizeMultiplier)) {
m_propBitsMask |= TXTBIT_CHARFORMATCHANGE;
m_propBits |= TXTBIT_CHARFORMATCHANGE;
}
Expand Down Expand Up @@ -1351,9 +1354,15 @@ void WindowsTextInputComponentView::UpdateCharFormat() noexcept {

// set font size -- 15 to convert twips to pt
const auto &props = windowsTextInputProps();
float fontSize = m_fontSizeMultiplier *
float fontSize =
(std::isnan(props.textAttributes.fontSize) ? facebook::react::TextAttributes::defaultTextAttributes().fontSize
: props.textAttributes.fontSize);

// Apply maxFontSizeMultiplier if specified
auto maxFontSizeMultiplier = windowsTextInputProps().textAttributes.maxFontSizeMultiplier;
fontSize *=
Copy link
Contributor

Choose a reason for hiding this comment

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

This presumably changes the size that the text actually renders with. Is this accounted for in the layout? -- Basically I think TextLayoutManager needs to also account for this property to correctly calculate the layout of this text.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh i see. Thats part of the other PR.
Dont we need to get the font size from the layout? How do we get get the actual font size that the layout determined was appropriate?

Copy link
Contributor

Choose a reason for hiding this comment

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

With Text we reuse the same TextLayout object that was modified by TextLayoutManager. For TextInput, I think we'd have to extract the size that was calculated from the TextLayout (or otherwise get it from the TextLayoutManager), so that we can set it on the CHARFORMAT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I referred to Android / IOS implementations. Let me get back on this tomorrow.

(maxFontSizeMultiplier >= 1.0f) ? std::min(maxFontSizeMultiplier, m_fontSizeMultiplier) : m_fontSizeMultiplier;

// TODO get fontSize from props.textAttributes, or defaultTextAttributes, or fragment?
cfNew.dwMask |= CFM_SIZE;
cfNew.yHeight = static_cast<LONG>(fontSize * 15);
Expand Down
Loading