-
-
Notifications
You must be signed in to change notification settings - Fork 260
feat: add maxZoom support for iOS and Android #326
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -165,7 +165,11 @@ - (instancetype)initWithFrame:(CGRect)frame | |
| } | ||
| _pdfView.document = document; | ||
|
|
||
| _pdfView.maxScaleFactor = [args[@"maxZoom"] doubleValue]; | ||
| NSNumber *maxZoom = args[@"maxZoom"]; | ||
| if (maxZoom != nil && [maxZoom isKindOfClass:[NSNumber class]]) { | ||
| _pdfView.maxScaleFactor = [maxZoom doubleValue]; | ||
| } | ||
|
|
||
|
Comment on lines
+168
to
+172
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. iOS: maxZoom should be relative to fit and not get overwritten on layout; clamp double‑tap to max.
Apply this diff in the changed block to compute max relative to fit and remember the multiple: - NSNumber *maxZoom = args[@"maxZoom"];
- if (maxZoom != nil && [maxZoom isKindOfClass:[NSNumber class]]) {
- _pdfView.maxScaleFactor = [maxZoom doubleValue];
- }
+ NSNumber *maxZoom = args[@"maxZoom"];
+ if ([maxZoom isKindOfClass:[NSNumber class]]) {
+ _maxZoomMultiple = MAX(1.0, [maxZoom doubleValue]); // store the multiple
+ _pdfView.maxScaleFactor = _pdfView.scaleFactorForSizeToFit * _maxZoomMultiple;
+ }Add an ivar and a sensible default (outside the changed lines): // Near other ivars
double _maxZoomMultiple;
// In -initWithFrame:... before using it
_maxZoomMultiple = 3.0;Update layout to recompute absolute max from the current fit scale and clamp the current zoom (outside the changed lines): // In -layoutSubviews (replace the hard-coded 4.0)
_pdfView.maxScaleFactor = _pdfView.scaleFactorForSizeToFit * (_maxZoomMultiple > 1.0 ? _maxZoomMultiple : 3.0);
if (_pdfView.scaleFactor > _pdfView.maxScaleFactor) {
_pdfView.scaleFactor = _pdfView.maxScaleFactor;
}Respect max on double‑tap zoom (outside the changed lines): // Where scaleFactor is set to scaleFactorForSizeToFit * 2
CGFloat target = MIN(self->_pdfView.scaleFactorForSizeToFit * 2.0, self->_pdfView.maxScaleFactor);
self->_pdfView.scaleFactor = target;Also applies to: 257-264, 341-348 🤖 Prompt for AI Agents |
||
| _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit; | ||
|
|
||
| NSString* password = args[@"password"]; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Android Zoom Bug Causes Inconsistency
Android's
maxZoomparameter is multiplied by 2, leading to inconsistent maximum zoom levels compared to iOS. The implementation also castsmaxZoomtoNumberwithout a type check, which could cause aClassCastExceptionat runtime.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note on Android maxZoom implementation
On Android, the underlying PDFView (from
android-pdf-viewer) uses a different internal scaling model compared to iOS PDFKit.If we pass the same numeric value for
maxZoomdirectly, the perceived zoom level on Android will look significantly smaller than on iOS.To make the behavior consistent across platforms, the Android implementation multiplies
maxZoomby 2.This way, when developers pass the same
maxZoomvalue in Dart, the visual zoom level on Android and iOS appears similar.