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 2 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": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,16 @@ void WindowsTextInputComponentView::updateProps(
m_propBits |= TXTBIT_CHARFORMATCHANGE;
}

// Uncomment below when this commit is merged in RNW:
// https://github.com/facebook/react-native/commit/97cf42f979e8303a3caeecb94cba1f5a82d1000c
// if (!facebook::react::floatEquality(
// oldTextInputProps.textAttributes.maxFontSizeMultiplier,
// newTextInputProps.textAttributes.maxFontSizeMultiplier)) {
// m_propBitsMask |= TXTBIT_CHARFORMATCHANGE;
// m_propBits |= TXTBIT_CHARFORMATCHANGE;
// m_maxFontSizeMultiplier = newTextInputProps.textAttributes.maxFontSizeMultiplier;
//}

if (oldTextInputProps.secureTextEntry != newTextInputProps.secureTextEntry) {
m_propBitsMask |= TXTBIT_USEPASSWORD;
if (newTextInputProps.secureTextEntry) {
Expand Down Expand Up @@ -1344,9 +1354,14 @@ 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
fontSize *= (m_maxFontSizeMultiplier >= 1.0f) ? std::min(m_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
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ struct WindowsTextInputComponentView
unsigned int m_imgWidth{0}, m_imgHeight{0};
std::shared_ptr<facebook::react::WindowsTextInputShadowNode::ConcreteState const> m_state;
float m_fontSizeMultiplier{1.0};
float m_maxFontSizeMultiplier{0.0};
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's not create duplicate members for all of the props. Instead, the property can be accessed using windowsTextInputProps().textAttributes.maxFontSizeMultiplier.

I think we should maybe hold off on this PR until the property exists on the props object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure we can wait when upstream changes are checked in.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#14650

This PR would include those changes, will uncomment it once this PR merged in.

int64_t m_mostRecentEventCount{0};
int m_nativeEventCount{0};
bool m_comingFromJS{false};
Expand Down
Loading