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] Fix text input rendering crashing by using layout metrics pixelScaleFactor #1817

Merged
merged 2 commits into from
Jun 7, 2023
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
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/Multiline/RCTUITextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, copy) NSString *text;
@property (nonatomic, assign) NSTextAlignment textAlignment;
@property (nonatomic, copy, nullable) NSAttributedString *attributedText;
@property (nonatomic, assign) CGFloat pointScaleFactor;
- (NSSize)sizeThatFits:(NSSize)size;
- (void)setReadablePasteBoardTypes:(NSArray<NSPasteboardType> *)readablePasteboardTypes;
#endif // macOS]
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/TextInput/Multiline/RCTUITextView.m
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ - (CGSize)placeholderSize
.size;
placeholderSize = CGSizeMake(RCTCeilPixelValue(placeholderSize.width), RCTCeilPixelValue(placeholderSize.height));
#else // [macOS
CGFloat scale = self.window.backingScaleFactor;
CGFloat scale = _pointScaleFactor ?: self.window.backingScaleFactor;
CGSize placeholderSize = [placeholder sizeWithAttributes:[self _placeholderTextAttributes]];
placeholderSize = CGSizeMake(RCTCeilPixelValue(placeholderSize.width, scale), RCTCeilPixelValue(placeholderSize.height, scale));
#endif // macOS]
Expand Down
3 changes: 3 additions & 0 deletions Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign, readonly) CGFloat zoomScale;
@property (nonatomic, assign, readonly) CGPoint contentOffset;
@property (nonatomic, assign, readonly) UIEdgeInsets contentInset;
#if TARGET_OS_OSX // [macOS
@property (nonatomic, assign) CGFloat pointScaleFactor;
#endif // macOS]
Saadnajmi marked this conversation as resolved.
Show resolved Hide resolved

// This protocol disallows direct access to `selectedTextRange` property because
// unwise usage of it can break the `delegate` behavior. So, we always have to
Expand Down
1 change: 1 addition & 0 deletions Libraries/Text/TextInput/Singleline/RCTUITextField.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, assign) BOOL enableFocusRing;
@property (nonatomic, strong, nullable) RCTUIColor *selectionColor;
@property (weak, nullable) id<RCTUITextFieldDelegate> delegate;
@property (nonatomic, assign) CGFloat pointScaleFactor;
#endif // macOS]

@end
Expand Down
2 changes: 1 addition & 1 deletion Libraries/Text/TextInput/Singleline/RCTUITextField.m
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ - (CGSize)intrinsicContentSize
size = CGSizeMake(RCTCeilPixelValue(size.width), RCTCeilPixelValue(size.height));
#else // [macOS
CGSize size = [text sizeWithAttributes:@{NSFontAttributeName: self.font}];
CGFloat scale = self.window.backingScaleFactor;
CGFloat scale = _pointScaleFactor ?: self.window.backingScaleFactor;
if (scale == 0.0 && RCTRunningInTestEnvironment()) {
// When running in the test environment the view is not on screen.
// Use a scaleFactor of 1 so that the test results are machine independent.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,9 @@ - (void)updateLayoutMetrics:(LayoutMetrics const &)layoutMetrics
{
[super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];

#if TARGET_OS_OSX // [macOS
_backedTextInputView.pointScaleFactor = layoutMetrics.pointScaleFactor;
#endif // macOS]
_backedTextInputView.frame =
UIEdgeInsetsInsetRect(self.bounds, RCTUIEdgeInsetsFromEdgeInsets(layoutMetrics.borderWidth));
_backedTextInputView.textContainerInset =
Expand Down