Skip to content
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

[Fabric] Point scale factor update support #1844

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions React/Base/Surface/RCTSurfaceProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ NS_ASSUME_NONNULL_BEGIN
- (void)start;
- (void)stop;

- (void)updateLayoutContextWithPointScaleFactor:(CGFloat)pointScaleFactor;

@end

NS_ASSUME_NONNULL_END
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,11 @@ - (void)didMoveToWindow
[self _updateViews];
}

- (void)viewDidChangeBackingProperties
{
[_surface updateLayoutContextWithPointScaleFactor:self.window.backingScaleFactor];
}

Comment on lines +251 to +255
Copy link
Collaborator

Choose a reason for hiding this comment

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

Would this also work in didMoveToWindow? Asking since this method isn't in uiview whereas the latter is in both.

#pragma mark - RCTSurfaceDelegate

- (void)surface:(__unused RCTSurface *)surface didChangeStage:(RCTSurfaceStage)stage
Expand Down
9 changes: 7 additions & 2 deletions React/Fabric/Surface/RCTFabricSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -170,21 +170,26 @@ - (void)_propagateStageChange
}
}

- (void)_updateLayoutContext
- (void)updateLayoutContextWithPointScaleFactor:(CGFloat)pointScaleFactor
{
auto layoutConstraints = _surfaceHandler->getLayoutConstraints();
layoutConstraints.layoutDirection = RCTLayoutDirection([[RCTI18nUtil sharedInstance] isRTL]);

auto layoutContext = _surfaceHandler->getLayoutContext();

layoutContext.pointScaleFactor = RCTScreenScale();
layoutContext.pointScaleFactor = pointScaleFactor;
layoutContext.swapLeftAndRightInRTL =
[[RCTI18nUtil sharedInstance] isRTL] && [[RCTI18nUtil sharedInstance] doLeftAndRightSwapInRTL];
layoutContext.fontSizeMultiplier = RCTFontSizeMultiplier();

_surfaceHandler->constraintLayout(layoutConstraints, layoutContext);
}

- (void)_updateLayoutContext
{
[self updateLayoutContextWithPointScaleFactor:RCTScreenScale()];
}

#pragma mark - Properties Management

- (NSDictionary *)properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ void YogaLayoutableShadowNode::dirtyLayout() {
yogaNode_.setDirty(true);
}

void YogaLayoutableShadowNode::dirtyLayoutAndPropagateDownwards() {
yogaNode_.markDirtyAndPropogateDownwards();
}

bool YogaLayoutableShadowNode::getIsLayoutClean() const {
return !yogaNode_.isDirty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode {

void cleanLayout() override;
void dirtyLayout() override;
void dirtyLayoutAndPropagateDownwards() override;
bool getIsLayoutClean() const override;

/*
Expand Down
1 change: 1 addition & 0 deletions ReactCommon/react/renderer/core/LayoutableShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ class LayoutableShadowNode : public ShadowNode {
*/
virtual void cleanLayout() = 0;
virtual void dirtyLayout() = 0;
virtual void dirtyLayoutAndPropagateDownwards() = 0;
virtual bool getIsLayoutClean() const = 0;

/*
Expand Down
11 changes: 11 additions & 0 deletions ReactCommon/react/renderer/core/ShadowNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,17 @@ ShadowNode::Unshared ShadowNode::clone(
}
}

ShadowNode::Unshared ShadowNode::cloneRecursive() const {
auto clonedChildren = std::make_shared<ShadowNode::ListOfShared>(*children_);
auto nonConstChildren =
std::const_pointer_cast<ShadowNode::ListOfShared>(clonedChildren);
for (auto iter = nonConstChildren->begin(); iter != nonConstChildren->end(); iter++) {
auto sharedChild = *iter;
*iter = sharedChild->cloneRecursive();
}
return clone({.children = nonConstChildren});
}

ContextContainer::Shared ShadowNode::getContextContainer() const {
return family_->componentDescriptor_.getContextContainer();
}
Expand Down
6 changes: 6 additions & 0 deletions ReactCommon/react/renderer/core/ShadowNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ class ShadowNode : public Sealable, public DebugStringConvertible {
* Clones the shadow node using stored `cloneFunction`.
*/
Unshared clone(const ShadowNodeFragment &fragment) const;

/*
* Clones the shadow node recursively.
*/
Unshared cloneRecursive() const;


/*
* Clones the node (and partially the tree starting from the node) by
Expand Down
6 changes: 4 additions & 2 deletions ReactCommon/react/renderer/scheduler/SurfaceHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,10 @@ void SurfaceHandler::constraintLayout(
react_native_assert(
link_.shadowTree && "`link_.shadowTree` must not be null.");
link_.shadowTree->commit([&](RootShadowNode const &oldRootShadowNode) {
return oldRootShadowNode.clone(
propsParserContext, layoutConstraints, layoutContext);
auto newRootShadowNode = std::static_pointer_cast<RootShadowNode>(oldRootShadowNode.clone(
propsParserContext, layoutConstraints, layoutContext)->cloneRecursive());
newRootShadowNode->dirtyLayoutAndPropagateDownwards();
return newRootShadowNode;
});
}
}
Expand Down