fix(mobile): scale inline pills with Dynamic Type (#11792)
This commit is contained in:
1 parent
549d182aaa
commit
9d4bb550a6
2 files changed
+10
-2
No files matched your search
@@ -102,6 +102,7 @@ static inline NSAttributedString *T3MarkdownTextAttachmentString(
|
||||
static UIFont *T3ContextChipFont(NSDictionary *payload)
|
||||
{
|
||||
CGFloat size = MAX(10, MIN(40, [payload[@"fontSize"] doubleValue]));
|
||||
size *= payload[@"fontSizeMultiplier"] != nil ? [payload[@"fontSizeMultiplier"] doubleValue] : 1;
|
||||
return [UIFont fontWithName:@"DMSans-Medium" size:size]
|
||||
?: [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
|
||||
}
|
||||
|
||||
@@ -197,12 +197,19 @@ Size T3MarkdownTextShadowNode::measureContent(
|
||||
}
|
||||
if (props.nativeId.rfind("t3-chip:", 0) == 0 && fragmentLength > 0) {
|
||||
const std::string uri = props.nativeId.substr(3);
|
||||
NSDictionary *payload = T3ContextChipPayload([NSString stringWithUTF8String:uri.c_str()]);
|
||||
NSMutableDictionary *payload =
|
||||
[T3ContextChipPayload([NSString stringWithUTF8String:uri.c_str()]) mutableCopy];
|
||||
// Chips must scale with the paragraph or smaller Dynamic Type sizes clip them.
|
||||
// Store the scaled payload so measurement and the rendered bitmap use the same font.
|
||||
payload[@"fontSizeMultiplier"] = @(fontSizeMultiplier);
|
||||
NSData *data = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];
|
||||
NSString *scaledUri = [@"chip:" stringByAppendingString:
|
||||
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
|
||||
const CGFloat maxWidth = std::isfinite(layoutConstraints.maximumSize.width)
|
||||
? layoutConstraints.maximumSize.width : 320;
|
||||
const CGSize size = T3ContextChipSize(payload, maxWidth);
|
||||
attachmentRanges.push_back(T3MarkdownTextAttachmentRange{
|
||||
utf16Offset, 1, uri, false,
|
||||
utf16Offset, 1, std::string(scaledUri.UTF8String), false,
|
||||
static_cast<Float>(size.width), static_cast<Float>(size.height),
|
||||
});
|
||||
} else if (props.nativeId.rfind(FileAttachmentNativeIdPrefix, 0) == 0 && fragmentLength > 0) {
|
||||
|
||||
Reference in new issue
Block a user