-
-
Notifications
You must be signed in to change notification settings - Fork 262
fix: ios callbacks, zoom config, privacy manifest #336
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
27dbf21
22dd25a
fb26b37
aeff587
4f68547
0e885f9
07b070e
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 |
|---|---|---|
|
|
@@ -105,6 +105,9 @@ @implementation FLTPDFView { | |
| BOOL _defaultPageSet; | ||
| BOOL _isIPad; | ||
| BOOL _isScrolling; | ||
| CGFloat _maxScaleFactor; | ||
| CGFloat _minScaleFactor; | ||
| BOOL _hasSentInitialPage; | ||
| } | ||
|
|
||
| - (instancetype)initWithFrame:(CGRect)frame | ||
|
|
@@ -140,7 +143,10 @@ - (instancetype)initWithFrame:(CGRect)frame | |
|
|
||
|
|
||
| if (document == nil) { | ||
| [_controller invokeChannelMethod:@"onError" arguments:@{@"error" : @"cannot create document: File not in PDF format or corrupted."}]; | ||
| __weak __typeof__(self) weakSelf = self; | ||
| dispatch_async(dispatch_get_main_queue(), ^{ | ||
| [weakSelf->_controller invokeChannelMethod:@"onError" arguments:@{@"error" : @"cannot create document: File not in PDF format or corrupted."}]; | ||
| }); | ||
| } else { | ||
| _pdfView.autoresizesSubviews = YES; | ||
| _pdfView.autoresizingMask = UIViewAutoresizingFlexibleWidth; | ||
|
|
@@ -165,7 +171,13 @@ - (instancetype)initWithFrame:(CGRect)frame | |
| } | ||
| _pdfView.document = document; | ||
|
|
||
| _pdfView.maxScaleFactor = [args[@"maxZoom"] doubleValue]; | ||
| _maxScaleFactor = [args[@"maxZoom"] doubleValue]; | ||
| if (_maxScaleFactor <= 0) { | ||
| _maxScaleFactor = 4.0; | ||
| } | ||
| _minScaleFactor = [args[@"minZoom"] doubleValue]; | ||
|
|
||
| _pdfView.maxScaleFactor = _maxScaleFactor; | ||
|
Comment on lines
+174
to
+180
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. Zoom bounds are still init-only on iOS.
🤖 Prompt for AI Agents |
||
| _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit; | ||
|
|
||
| NSString* password = args[@"password"]; | ||
|
|
@@ -253,16 +265,29 @@ - (void)layoutSubviews { | |
| // Wrap layout updates in try-catch for safety | ||
| @try { | ||
| _pdfView.frame = self.frame; | ||
| _pdfView.minScaleFactor = _pdfView.scaleFactorForSizeToFit; | ||
| _pdfView.maxScaleFactor = 4.0; | ||
| CGFloat fitScale = _pdfView.scaleFactorForSizeToFit; | ||
| CGFloat minScale = (_minScaleFactor > 0) ? _minScaleFactor : fitScale; | ||
| _pdfView.minScaleFactor = minScale; | ||
| _pdfView.maxScaleFactor = fmax(_maxScaleFactor, minScale); | ||
| if (_autoSpacing) { | ||
| _pdfView.scaleFactor = _pdfView.scaleFactorForSizeToFit; | ||
| CGFloat clampedScale = fmin(fmax(fitScale, _pdfView.minScaleFactor), _pdfView.maxScaleFactor); | ||
| _pdfView.scaleFactor = clampedScale; | ||
| } | ||
|
|
||
| if (!_defaultPageSet && _defaultPage != nil) { | ||
| [_pdfView goToPage: _defaultPage]; | ||
| _defaultPageSet = true; | ||
| } | ||
|
|
||
| if (!_hasSentInitialPage && _defaultPageSet && _pdfView.document != nil && _pdfView.currentPage != nil) { | ||
| _hasSentInitialPage = YES; | ||
| NSUInteger currentPageIndex = [_pdfView.document indexForPage:_pdfView.currentPage]; | ||
| NSUInteger pageCount = [_pdfView.document pageCount]; | ||
| [_controller invokeChannelMethod:@"onPageChanged" arguments:@{ | ||
| @"page" : [NSNumber numberWithUnsignedLong:currentPageIndex], | ||
| @"total" : [NSNumber numberWithUnsignedLong:pageCount] | ||
| }]; | ||
| } | ||
| } @catch (NSException *exception) { | ||
| NSLog(@"Warning: Layout update failed: %@", exception.reason); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
| <plist version="1.0"> | ||
| <dict> | ||
| <key>NSPrivacyCollectedDataTypes</key> | ||
| <array/> | ||
| <key>NSPrivacyTracking</key> | ||
| <false/> | ||
| <key>NSPrivacyTrackingDomains</key> | ||
| <array/> | ||
| <key>NSPrivacyAccessedAPITypes</key> | ||
| <array/> | ||
| </dict> | ||
| </plist> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,7 +43,12 @@ class PDFView extends StatefulWidget { | |
| this.fitPolicy = FitPolicy.WIDTH, | ||
| this.preventLinkNavigation = false, | ||
| this.backgroundColor, | ||
| this.maxZoom = 4.0, | ||
| this.minZoom = 1.0, | ||
| }) : assert(filePath != null || pdfData != null), | ||
| assert(maxZoom > 0, 'maxZoom must be greater than 0'), | ||
| assert(minZoom > 0, 'minZoom must be greater than 0'), | ||
| assert(maxZoom >= minZoom, 'maxZoom must be >= minZoom'), | ||
|
Comment on lines
+46
to
+51
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. 🧩 Analysis chain🌐 Web query:
💡 Result: No.
So “fit-to-page” (or whatever fit behavior applies for the current display mode) corresponds to Sources Citations:
🏁 Script executed: # First, check the exact code at lines 46-51 in lib/flutter_pdfview.dart
cat -n lib/flutter_pdfview.dart | head -60 | tail -20Repository: endigo/flutter_pdfview Length of output: 892 🏁 Script executed: # Search for minZoom/maxZoom initialization and defaults
rg "minZoom|maxZoom" lib/flutter_pdfview.dart -A 2 -B 2Repository: endigo/flutter_pdfview Length of output: 1478 🏁 Script executed: # Check iOS implementation that maps minZoom to PDFView.minScaleFactor
rg "minZoom|minScaleFactor" ios/ -A 3 -B 1Repository: endigo/flutter_pdfview Length of output: 2279 🏁 Script executed: # Verify the _PDFViewSettings.toMap() behavior mentioned in the review
ast-grep --pattern 'toMap() { $$$ minZoom $$$ }'Repository: endigo/flutter_pdfview Length of output: 48 🏁 Script executed: # Check git history to see if minZoom was previously optional/nullable
git log --oneline -p lib/flutter_pdfview.dart 2>/dev/null | head -200 | grep -A5 -B5 "minZoom" | head -50Repository: endigo/flutter_pdfview Length of output: 893 🏁 Script executed: # Check if _PDFViewSettings defines minZoom as nullable in its class
rg "class _PDFViewSettings" lib/flutter_pdfview.dart -A 20 | grep -E "(minZoom|maxZoom|double\?)"Repository: endigo/flutter_pdfview Length of output: 101 Make The The iOS code already supports this: it uses 🤖 Prompt for AI Agents |
||
| super(key: key); | ||
|
|
||
| @override | ||
|
|
@@ -135,21 +140,27 @@ class PDFView extends StatefulWidget { | |
|
|
||
| /// Use to change the background color. ex : "#FF0000" => red | ||
| final Color? backgroundColor; | ||
|
|
||
| /// Maximum zoom level. Defaults to 4.0. | ||
| final double maxZoom; | ||
|
|
||
| /// Minimum zoom level. Defaults to 1.0 (fit to page). | ||
| final double minZoom; | ||
| } | ||
|
|
||
| class _PDFViewState extends State<PDFView> { | ||
| final Completer<PDFViewController> _controller = | ||
| Completer<PDFViewController>(); | ||
| Completer<PDFViewController>(); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| if (defaultTargetPlatform == TargetPlatform.android) { | ||
| return PlatformViewLink( | ||
| viewType: 'plugins.endigo.io/pdfview', | ||
| surfaceFactory: ( | ||
| BuildContext context, | ||
| PlatformViewController controller, | ||
| ) { | ||
| BuildContext context, | ||
| PlatformViewController controller, | ||
| ) { | ||
| return AndroidViewSurface( | ||
| controller: controller as AndroidViewController, | ||
| gestureRecognizers: widget.gestureRecognizers ?? | ||
|
|
@@ -197,7 +208,7 @@ class _PDFViewState extends State<PDFView> { | |
| void didUpdateWidget(PDFView oldWidget) { | ||
| super.didUpdateWidget(oldWidget); | ||
| _controller.future.then( | ||
| (PDFViewController controller) => controller._updateWidget(widget)); | ||
| (PDFViewController controller) => controller._updateWidget(widget)); | ||
| } | ||
|
|
||
| @override | ||
|
|
@@ -257,6 +268,8 @@ class _PDFViewSettings { | |
| this.fitPolicy, | ||
| this.preventLinkNavigation, | ||
| this.backgroundColor, | ||
| this.maxZoom, | ||
| this.minZoom, | ||
| }); | ||
|
|
||
| static _PDFViewSettings fromWidget(PDFView widget) { | ||
|
|
@@ -276,6 +289,8 @@ class _PDFViewSettings { | |
| fitPolicy: widget.fitPolicy, | ||
| preventLinkNavigation: widget.preventLinkNavigation, | ||
| backgroundColor: widget.backgroundColor, | ||
| maxZoom: widget.maxZoom, | ||
| minZoom: widget.minZoom, | ||
| ); | ||
| } | ||
|
|
||
|
|
@@ -296,6 +311,9 @@ class _PDFViewSettings { | |
|
|
||
| final Color? backgroundColor; | ||
|
|
||
| final double? maxZoom; | ||
| final double? minZoom; | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| Map<String, dynamic> toMap() { | ||
| return <String, dynamic>{ | ||
| 'enableSwipe': enableSwipe, | ||
|
|
@@ -313,6 +331,8 @@ class _PDFViewSettings { | |
| 'fitPolicy': fitPolicy.toString(), | ||
| 'preventLinkNavigation': preventLinkNavigation, | ||
| 'backgroundColor': backgroundColor?.value, | ||
| 'maxZoom': maxZoom, | ||
| 'minZoom': minZoom, | ||
| }; | ||
| } | ||
|
|
||
|
|
@@ -330,15 +350,21 @@ class _PDFViewSettings { | |
| if (preventLinkNavigation != newSettings.preventLinkNavigation) { | ||
| updates['preventLinkNavigation'] = newSettings.preventLinkNavigation; | ||
| } | ||
| if (maxZoom != newSettings.maxZoom) { | ||
| updates['maxZoom'] = newSettings.maxZoom; | ||
| } | ||
| if (minZoom != newSettings.minZoom) { | ||
| updates['minZoom'] = newSettings.minZoom; | ||
| } | ||
| return updates; | ||
| } | ||
| } | ||
|
|
||
| class PDFViewController { | ||
| PDFViewController._( | ||
| int id, | ||
| PDFView widget, | ||
| ) : _channel = MethodChannel('plugins.endigo.io/pdfview_$id'), | ||
| int id, | ||
| PDFView widget, | ||
| ) : _channel = MethodChannel('plugins.endigo.io/pdfview_$id'), | ||
| _widget = widget { | ||
| _settings = _PDFViewSettings.fromWidget(widget); | ||
| _channel.setMethodCallHandler(_onMethodCall); | ||
|
|
@@ -396,7 +422,7 @@ class PDFViewController { | |
|
|
||
| Future<bool?> setPage(int page) async { | ||
| final bool? isSet = | ||
| await _channel.invokeMethod('setPage', <String, dynamic>{ | ||
| await _channel.invokeMethod('setPage', <String, dynamic>{ | ||
| 'page': page, | ||
| }); | ||
| return isSet; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| name: flutter_pdfview | ||
| description: A Flutter plugin that provides a PDFView widget on Android and iOS. | ||
| version: 1.4.4 | ||
| version: 1.4.5 | ||
|
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. Version this as a breaking release. This PR also raises the iOS minimum to 13.0 in 🤖 Prompt for AI Agents |
||
| homepage: https://github.com/endigo/flutter_pdfview | ||
|
|
||
| environment: | ||
|
|
||
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.
Zoom updates will fail after the first rebuild on Android.
This only applies
maxZoomandminZoomduring creation.PDFViewController._updateSettings()now forwards those keys on rebuild, butapplySettings()still has nomaxZoomorminZoombranches, so the first runtime change falls into the default case and throwsIllegalArgumentException("Unknown PDFView setting").🤖 Prompt for AI Agents