Skip to content
Open
Prev Previous commit
Next Next commit
Add comments to epsilon enabling
  • Loading branch information
Tony Du committed Apr 5, 2022
commit 6f6d712bb878a9c719d254aed58cb07622972251
15 changes: 10 additions & 5 deletions ios/RNTextSize.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#import <React/RCTUtils.h>
#else
#import "React/RCTConvert.h" // Required when used as a Pod in a Swift project
#import <React/RCTFont.h>
#import <React/RCTUtils.h>
#import "React/RCTFont.h"
#import "React/RCTUtils.h"
#endif

#import <CoreText/CoreText.h>
Expand Down Expand Up @@ -179,8 +179,9 @@ - (dispatch_queue_t)methodQueue {

NSMutableArray<NSNumber *> *result = [[NSMutableArray alloc] initWithCapacity:texts.count];

const CGFloat scaleMultiplier = _bridge ? _bridge.accessibilityManager.multiplier : 1.0;
const CGFloat epsilon = scaleMultiplier != 1.0 ? 0.001 : 0;
// When there's no font scaling, adding epsilon offsets the calculation
// by a bit, and when there is, it's required. This was tested empirically.
const CGFloat epsilon = [self fontScaleMultiplier] != 1.0 ? 0.001 : 0;

for (int ix = 0; ix < texts.count; ix++) {
NSString *text = texts[ix];
Expand Down Expand Up @@ -618,7 +619,7 @@ - (NSTextContainer *)textContainerFromOptions:(NSDictionary * _Nullable)options
const CGFloat lineHeight = CGFloatValueFrom(options[@"lineHeight"]);
if (!isnan(lineHeight)) {
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
const CGFloat scaleMultiplier = _bridge ? _bridge.accessibilityManager.multiplier : 1.0;
const CGFloat scaleMultiplier = [self fontScaleMultiplier];
[style setMinimumLineHeight:lineHeight * scaleMultiplier];
[style setMaximumLineHeight:lineHeight * scaleMultiplier];
[attributes setObject:style forKey:NSParagraphStyleAttributeName];
Expand All @@ -627,4 +628,8 @@ - (NSTextContainer *)textContainerFromOptions:(NSDictionary * _Nullable)options
return attributes;
}

- (CGFloat)fontScaleMultiplier {
return _bridge ? _bridge.accessibilityManager.multiplier : 1.0;
}

@end