Skip to content

Commit aa7fa18

Browse files
Merge pull request #55 from marllonfrizzo/fix/ios-scale-issues
Workaround fix for PDF rendering issue when scaleFactorForSizeToFit is zero
2 parents 9aa1ff7 + f03f1e2 commit aa7fa18

1 file changed

Lines changed: 14 additions & 7 deletions

File tree

ios/ReactNativePdfRendererLibrary/RNPDFView.mm

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,20 @@ -(void) setParams:(NSDictionary*) params {
6161
self.document = pdfDocument;
6262
});
6363

64-
dispatch_async(dispatch_get_main_queue(), ^{
65-
self.minScaleFactor = self.scaleFactorForSizeToFit;
66-
if (maxZoom > 0) {
67-
self.maxScaleFactor = self.scaleFactorForSizeToFit * maxZoom;
68-
}
69-
[self setNeedsLayout];
70-
});
64+
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
65+
// In certain scenarios, scaleFactorForSizeToFit may be 0.
66+
// This results in invalid calculations for the CoreGraphics API, affecting the PDF positioning.
67+
// Consequence: PDF displayed in the wrong position and zoom unavailable.
68+
// This is a temporary workaround to handle the production bug until a better approach is implemented.
69+
sleep(1);
70+
71+
dispatch_async(dispatch_get_main_queue(), ^{
72+
self.minScaleFactor = self.scaleFactorForSizeToFit == 0 ? 1 : self.scaleFactorForSizeToFit;
73+
if (maxZoom > 0) {
74+
self.maxScaleFactor = maxZoom * self.minScaleFactor;
75+
}
76+
[self setNeedsLayout];
77+
});
7178
} else {
7279
self.document = nil;
7380
}

0 commit comments

Comments
 (0)