Skip to content
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 apps/mobile/modules/t3-markdown-text/ios/T3ContextChip.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,19 @@ static void applyAttachments(
}
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) {
Expand Down
Loading