Skip to content

Commit 80a7d7a

Browse files
TheWygodaclaude
andauthored
fix(ios): honour numeric Image.compress options (#422)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8f85623 commit 80a7d7a

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

‎harness/native-compressor.harness.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ describe('react-native-compressor native harness', () => {
133133
const metadata = await getImageMetaData(output);
134134
expect(metadata.ImageWidth).toBeGreaterThan(0);
135135
expect(metadata.ImageHeight).toBeGreaterThan(0);
136+
// the fixture is 16×16, so maxWidth/maxHeight must shrink it (#417)
137+
expect(metadata.ImageWidth).toBeLessThanOrEqual(8);
138+
expect(metadata.ImageHeight).toBeLessThanOrEqual(8);
136139
expect(metadata.size).toBeGreaterThan(0);
137140
expect(metadata.exif).toBeTruthy();
138141

‎ios/Image/ImageCompressorOptions.swift‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,18 @@ class ImageCompressorOptions: NSObject {
2828
switch key {
2929
case "compressionMethod":
3030
options.autoCompress = (value as? String ?? "") != "manual"
31+
// Nitro hands every JS number over as a Swift Double, which `as? Int` and
32+
// `as? Float` never match, so these options silently fell back to their
33+
// defaults (#417). NSNumber bridges a Double, an Int and an NSNumber alike,
34+
// the same cast VideoMain uses for its numeric options.
3135
case "maxWidth":
32-
options.maxWidth = (value as? Int) ?? 1280
36+
options.maxWidth = (value as? NSNumber)?.intValue ?? 1280
3337
case "maxHeight":
34-
options.maxHeight = (value as? Int) ?? 1280
38+
options.maxHeight = (value as? NSNumber)?.intValue ?? 1280
3539
case "progressDivider":
36-
options.progressDivider = (value as? Int) ?? 0
40+
options.progressDivider = (value as? NSNumber)?.intValue ?? 0
3741
case "quality":
38-
options.quality = (value as? Float) ?? 0.8
42+
options.quality = (value as? NSNumber)?.floatValue ?? 0.8
3943
case "input":
4044
options.parseInput(value as? String)
4145
case "output":

0 commit comments

Comments
 (0)