Skip to content

Commit 6f6d712

Browse files
author
Tony Du
committed
Add comments to epsilon enabling
1 parent 7372b98 commit 6f6d712

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

ios/RNTextSize.m

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
#import <React/RCTUtils.h>
77
#else
88
#import "React/RCTConvert.h" // Required when used as a Pod in a Swift project
9-
#import <React/RCTFont.h>
10-
#import <React/RCTUtils.h>
9+
#import "React/RCTFont.h"
10+
#import "React/RCTUtils.h"
1111
#endif
1212

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

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

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

185186
for (int ix = 0; ix < texts.count; ix++) {
186187
NSString *text = texts[ix];
@@ -618,7 +619,7 @@ - (NSTextContainer *)textContainerFromOptions:(NSDictionary * _Nullable)options
618619
const CGFloat lineHeight = CGFloatValueFrom(options[@"lineHeight"]);
619620
if (!isnan(lineHeight)) {
620621
NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
621-
const CGFloat scaleMultiplier = _bridge ? _bridge.accessibilityManager.multiplier : 1.0;
622+
const CGFloat scaleMultiplier = [self fontScaleMultiplier];
622623
[style setMinimumLineHeight:lineHeight * scaleMultiplier];
623624
[style setMaximumLineHeight:lineHeight * scaleMultiplier];
624625
[attributes setObject:style forKey:NSParagraphStyleAttributeName];
@@ -627,4 +628,8 @@ - (NSTextContainer *)textContainerFromOptions:(NSDictionary * _Nullable)options
627628
return attributes;
628629
}
629630

631+
- (CGFloat)fontScaleMultiplier {
632+
return _bridge ? _bridge.accessibilityManager.multiplier : 1.0;
633+
}
634+
630635
@end

0 commit comments

Comments
 (0)