Skip to content

Commit 5bbcf71

Browse files
fix(mobile): scale inline pills with Dynamic Type
1 parent 9375c77 commit 5bbcf71

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎apps/mobile/modules/t3-markdown-text/ios/T3ContextChip.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ static inline NSAttributedString *T3MarkdownTextAttachmentString(
102102
static UIFont *T3ContextChipFont(NSDictionary *payload)
103103
{
104104
CGFloat size = MAX(10, MIN(40, [payload[@"fontSize"] doubleValue]));
105+
size *= payload[@"fontSizeMultiplier"] != nil ? [payload[@"fontSizeMultiplier"] doubleValue] : 1;
105106
return [UIFont fontWithName:@"DMSans-Medium" size:size]
106107
?: [UIFont systemFontOfSize:size weight:UIFontWeightMedium];
107108
}

‎apps/mobile/modules/t3-markdown-text/ios/T3MarkdownTextShadowNode.mm‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,12 +197,19 @@ static void applyAttachments(
197197
}
198198
if (props.nativeId.rfind("t3-chip:", 0) == 0 && fragmentLength > 0) {
199199
const std::string uri = props.nativeId.substr(3);
200-
NSDictionary *payload = T3ContextChipPayload([NSString stringWithUTF8String:uri.c_str()]);
200+
NSMutableDictionary *payload =
201+
[T3ContextChipPayload([NSString stringWithUTF8String:uri.c_str()]) mutableCopy];
202+
// Chips must scale with the paragraph or smaller Dynamic Type sizes clip them.
203+
// Store the scaled payload so measurement and the rendered bitmap use the same font.
204+
payload[@"fontSizeMultiplier"] = @(fontSizeMultiplier);
205+
NSData *data = [NSJSONSerialization dataWithJSONObject:payload options:0 error:nil];
206+
NSString *scaledUri = [@"chip:" stringByAppendingString:
207+
[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]];
201208
const CGFloat maxWidth = std::isfinite(layoutConstraints.maximumSize.width)
202209
? layoutConstraints.maximumSize.width : 320;
203210
const CGSize size = T3ContextChipSize(payload, maxWidth);
204211
attachmentRanges.push_back(T3MarkdownTextAttachmentRange{
205-
utf16Offset, 1, uri, false,
212+
utf16Offset, 1, std::string(scaledUri.UTF8String), false,
206213
static_cast<Float>(size.width), static_cast<Float>(size.height),
207214
});
208215
} else if (props.nativeId.rfind(FileAttachmentNativeIdPrefix, 0) == 0 && fragmentLength > 0) {

0 commit comments

Comments
 (0)