Repository navigation
[fabric] Fixed updating font size after system change #53767
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -233,75 +233,14 @@ Size SurfaceHandler::measure( | |
| return rootShadowNode->getLayoutMetrics().frame.size; | ||
| } | ||
|
|
||
| std::shared_ptr<const ShadowNode> SurfaceHandler::dirtyMeasurableNodesRecursive( | ||
| std::shared_ptr<const ShadowNode> node) const { | ||
| const auto nodeHasChildren = !node->getChildren().empty(); | ||
| const auto isMeasurableYogaNode = | ||
| node->getTraits().check(ShadowNodeTraits::Trait::MeasurableYogaNode); | ||
|
|
||
| // Node is not measurable and has no children, its layout will not be affected | ||
| if (!nodeHasChildren && !isMeasurableYogaNode) { | ||
| return nullptr; | ||
| void SurfaceHandler::dirtyMeasurableNodes(std::shared_ptr<const ShadowNode> node) const { | ||
| if (auto* layoutableNode = dynamic_cast<const YogaLayoutableShadowNode*>(node.get())) { | ||
| // Only cast away const where needed | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove this comment, it is not valid. |
||
| const_cast<YogaLayoutableShadowNode*>(layoutableNode)->dirtyLayout(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if it's safe to dirty a potentially sealed node.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this was what was done previously as well? I couldn't find a place where we checked for sealed or not in the previous code.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, the node was cloned before marking it as dirty - the new node is always unsealed. You also can't really check if a node is sealed or not, since that information is preserved only in debug builds. |
||
| } | ||
|
|
||
| ShadowNode::SharedListOfShared newChildren = | ||
| ShadowNodeFragment::childrenPlaceholder(); | ||
|
|
||
| if (nodeHasChildren) { | ||
| std::shared_ptr<std::vector<std::shared_ptr<const ShadowNode>>> | ||
| newChildrenMutable = nullptr; | ||
| for (size_t i = 0; i < node->getChildren().size(); i++) { | ||
| const auto& child = node->getChildren()[i]; | ||
|
|
||
| if (const auto& layoutableNode = | ||
| std::dynamic_pointer_cast<const YogaLayoutableShadowNode>( | ||
| child)) { | ||
| auto newChild = dirtyMeasurableNodesRecursive(layoutableNode); | ||
|
|
||
| if (newChild != nullptr) { | ||
| if (newChildrenMutable == nullptr) { | ||
| newChildrenMutable = std::make_shared< | ||
| std::vector<std::shared_ptr<const ShadowNode>>>( | ||
| node->getChildren()); | ||
| newChildren = newChildrenMutable; | ||
| } | ||
|
|
||
| (*newChildrenMutable)[i] = newChild; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Node is not measurable and its children were not dirtied, its layout will | ||
| // not be affected | ||
| if (!isMeasurableYogaNode && newChildrenMutable == nullptr) { | ||
| return nullptr; | ||
| } | ||
| } | ||
|
|
||
| const auto newNode = node->getComponentDescriptor().cloneShadowNode( | ||
| *node, | ||
| { | ||
| .children = newChildren, | ||
| // Preserve the original state of the node | ||
| .state = node->getState(), | ||
| }); | ||
|
|
||
| if (isMeasurableYogaNode) { | ||
| std::static_pointer_cast<YogaLayoutableShadowNode>(newNode)->dirtyLayout(); | ||
| } | ||
|
|
||
| return newNode; | ||
| } | ||
|
|
||
| void SurfaceHandler::dirtyMeasurableNodes(ShadowNode& root) const { | ||
| for (const auto& child : root.getChildren()) { | ||
| if (const auto& layoutableNode = | ||
| std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(child)) { | ||
| const auto newChild = dirtyMeasurableNodesRecursive(layoutableNode); | ||
| if (newChild != nullptr) { | ||
| root.replaceChild(*child, newChild); | ||
| } | ||
| } | ||
| for (const auto& child : node->getChildren()) { | ||
| dirtyMeasurableNodes(child); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -344,7 +283,7 @@ void SurfaceHandler::constraintLayout( | |
| layoutContext.fontSizeMultiplier != | ||
| oldRootShadowNode.getConcreteProps() | ||
| .layoutContext.fontSizeMultiplier) { | ||
| dirtyMeasurableNodes(*newRoot); | ||
| dirtyMeasurableNodes(newRoot); | ||
| } | ||
|
|
||
| return newRoot; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might check the traits before trying the dynamic cast - I believe this would be faster than trying to call dynamic_cast if we'd like to optimize this further (I left optimization out since this is a thing that doesn't happen that often)