Skip to content

Commit fa7f4d0

Browse files
committed
fix: iOS scaling
1 parent 79796e0 commit fa7f4d0

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

ios/TabViewProvider.swift

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -198,54 +198,44 @@ import SDWebImageSVGCoder
198198
// TODO: Diff the arrays and update only changed items.
199199
// Now if the user passes `unfocusedIcon` we update every item.
200200
guard let imageSources = icons as? [RCTImageSource?] else { return }
201-
202-
201+
203202
for (index, imageSource) in imageSources.enumerated() {
204203
guard let imageSource = imageSource,
205-
let urlString = imageSource.request.url?.absoluteString else { continue }
206-
207-
let url = URL(string: urlString)
208-
let isSVG = url?.pathExtension.lowercased() == "svg"
209-
210-
// Configure SVG specific options if needed
211-
var options: SDWebImageOptions = [.continueInBackground]
204+
let url = imageSource.request.url else { continue }
205+
206+
let isSVG = url.pathExtension.lowercased() == "svg"
207+
208+
var options: SDWebImageOptions = [.continueInBackground,
209+
.scaleDownLargeImages,
210+
.avoidDecodeImage,
211+
.highPriority]
212+
212213
if isSVG {
213214
options.insert(.decodeFirstFrameOnly)
214215
}
215-
216-
// Create context options for SVG rendering
216+
217217
let context: [SDWebImageContextOption: Any]? = isSVG ? [
218-
.svgImageSize: iconSize,
219218
.imageThumbnailPixelSize: iconSize
220219
] : nil
221-
220+
222221
SDWebImageManager.shared.loadImage(
223222
with: url,
224223
options: options,
225224
context: context,
226225
progress: nil
227226
) { [weak self] (image, _, _, _, _, _) in
228227
guard let self = self else { return }
229-
230228
DispatchQueue.main.async {
231-
if let image = image {
229+
if let image {
232230
if isSVG {
233-
// SVG images are already sized correctly through the context options
234231
self.props.icons[index] = image
235232
} else {
236-
// Resize non-SVG images
237-
if let resizedImage = image.sd_resizedImage(
238-
with: self.iconSize,
239-
scaleMode: .aspectFit
240-
) {
241-
self.props.icons[index] = resizedImage
242-
}
233+
self.props.icons[index] = image.resizeImageTo(size: self.iconSize)
243234
}
244235
}
245236
}
246237
}
247238
}
248-
249239
}
250240

251241
private func parseTabData(from array: NSArray?) -> [TabInfo] {

0 commit comments

Comments
 (0)