diff --git a/ios/Platform/Platform/Features/Reader/Views/ArticleView.swift b/ios/Platform/Platform/Features/Reader/Views/ArticleView.swift index aab286c..5400642 100644 --- a/ios/Platform/Platform/Features/Reader/Views/ArticleView.swift +++ b/ios/Platform/Platform/Features/Reader/Views/ArticleView.swift @@ -156,7 +156,7 @@ enum ArticleHTMLBuilder { .article-meta { font-size: 13px; color: #8B6914; line-height: 1.4; } - img { max-width: 100%; height: auto; border-radius: 8px; margin: 12px 0; } + img { max-width: 100%; height: auto; max-height: 600px; object-fit: contain; border-radius: 8px; margin: 12px 0; } a { color: #8B6914; } h1, h2, h3, h4 { line-height: 1.3; margin-top: 24px; margin-bottom: 8px; } pre, code { background: #f5f0e8; border-radius: 6px; padding: 2px 6px; font-size: 15px; overflow-x: auto; } @@ -214,9 +214,27 @@ enum ArticleHTMLBuilder {

\(titleHTML)

\(meta)
-
\(body)
+
\(optimizeImages(body))
""" } + + /// Add loading="lazy" and decoding="async" to all tags. + /// This tells WebKit to decode images off the main thread and + /// only when they approach the viewport, preventing scroll freezes + /// from large/mismatched-type images (e.g. WebP served as .jpeg). + private static let imgTagRegex = try! NSRegularExpression( + pattern: #"]*loading=)([^>]*)>"#, + options: .caseInsensitive + ) + + private static func optimizeImages(_ html: String) -> String { + let range = NSRange(html.startIndex..., in: html) + return imgTagRegex.stringByReplacingMatches( + in: html, + range: range, + withTemplate: #""# + ) + } }