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] Use the layout metrics to get the scale factor in component views. #1816

Merged
Merged
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
Expand Up @@ -54,22 +54,22 @@ - (void)_updateStateIfNecessary
}

UIEdgeInsets insets = [self _safeAreaInsets];
CGFloat scale = _layoutMetrics.pointScaleFactor; // [macOS]
#if !TARGET_OS_OSX // [macOS]
insets.left = RCTRoundPixelValue(insets.left);
insets.top = RCTRoundPixelValue(insets.top);
insets.right = RCTRoundPixelValue(insets.right);
insets.bottom = RCTRoundPixelValue(insets.bottom);
#else // [macOS
CGFloat scale = [[NSScreen mainScreen] backingScaleFactor];;
insets.left = RCTRoundPixelValue(insets.left, scale);
insets.top = RCTRoundPixelValue(insets.top, scale);
insets.right = RCTRoundPixelValue(insets.right, scale);
insets.bottom = RCTRoundPixelValue(insets.bottom, scale);
#endif // macOS]

auto newPadding = RCTEdgeInsetsFromUIEdgeInsets(insets);
auto threshold = 1.0 / RCTScreenScale() + 0.01; // Size of a pixel plus some small threshold.

auto threshold = 1.0 / scale + 0.01; // Size of a pixel plus some small threshold. [macOS]
_state->updateState(
[=](SafeAreaViewShadowNode::ConcreteState::Data const &oldData)
-> SafeAreaViewShadowNode::ConcreteState::SharedData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ - (void)invalidateLayer
RCTBorderColors borderColors = RCTCreateRCTBorderColorsFromBorderColors(borderMetrics.borderColors);

#if TARGET_OS_OSX // [macOS
CGFloat scaleFactor = self.window.backingScaleFactor;
CGFloat scaleFactor = _layoutMetrics.pointScaleFactor;
#else
// On iOS setting the scaleFactor to 0.0 will default to the device's native scale factor.
CGFloat scaleFactor = 0.0;
Expand All @@ -657,13 +657,13 @@ - (void)invalidateLayer
CGRect contentsCenter = CGRect{
CGPoint{imageCapInsets.left / imageSize.width, imageCapInsets.top / imageSize.height},
CGSize{(CGFloat)1.0 / imageSize.width, (CGFloat)1.0 / imageSize.height}};

#if !TARGET_OS_OSX // [macOS]
_borderLayer.contents = (id)image.CGImage;
_borderLayer.contentsScale = image.scale;
#else // [macOS
_borderLayer.contents = [image layerContentsForContentsScale:scaleFactor];
_borderLayer.contentsScale = RCTScreenScale();
_borderLayer.contentsScale = scaleFactor;
#endif // macOS]

BOOL isResizable = !UIEdgeInsetsEqualToEdgeInsets(image.capInsets, UIEdgeInsetsZero);
Expand Down