-
-
Notifications
You must be signed in to change notification settings - Fork 261
feat:Add spacing parameter to PDF viewer for customizable page spacing #335
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 |
|---|---|---|
|
|
@@ -32,6 +32,7 @@ class PDFView extends StatefulWidget { | |
| this.password, | ||
| this.nightMode = false, | ||
| this.autoSpacing = true, | ||
| this.spacing = 0, | ||
|
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. Reject negative spacing at the API boundary.
Small guard- }) : assert(filePath != null || pdfData != null),
+ }) : assert(filePath != null || pdfData != null),
+ assert(spacing >= 0),
super(key: key);Also applies to: 103-104 🤖 Prompt for AI Agents |
||
| this.pageFling = true, | ||
| this.pageSnap = true, | ||
| this.enableAntialiasing = true, | ||
|
|
@@ -99,6 +100,9 @@ class PDFView extends StatefulWidget { | |
| /// Indicates whether or not the PDF viewer automatically adds spacing between pages. If set to true, spacing is added. | ||
| final bool autoSpacing; | ||
|
|
||
| /// Indicates the amount of spacing between pages in the PDF document. | ||
| final int spacing; | ||
|
|
||
| /// Indicates whether or not the user can "fling" pages in the PDF document. If set to true, page flinging is enabled. | ||
| final bool pageFling; | ||
|
|
||
|
|
@@ -247,6 +251,7 @@ class _PDFViewSettings { | |
| this.password, | ||
| this.nightMode, | ||
| this.autoSpacing, | ||
| this.spacing, | ||
| this.pageFling, | ||
|
Comment on lines
+254
to
255
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.
These additions carry Also applies to: 274-275, 313-313 🤖 Prompt for AI Agents |
||
| this.pageSnap, | ||
| this.enableAntialiasing, | ||
|
|
@@ -266,6 +271,7 @@ class _PDFViewSettings { | |
| password: widget.password, | ||
| nightMode: widget.nightMode, | ||
| autoSpacing: widget.autoSpacing, | ||
| spacing: widget.spacing, | ||
| pageFling: widget.pageFling, | ||
| pageSnap: widget.pageSnap, | ||
| enableAntialiasing: widget.enableAntialiasing, | ||
|
|
@@ -284,6 +290,7 @@ class _PDFViewSettings { | |
| final String? password; | ||
| final bool? nightMode; | ||
| final bool? autoSpacing; | ||
| final int? spacing; | ||
| final bool? pageFling; | ||
| final bool? pageSnap; | ||
| final bool? enableAntialiasing; | ||
|
|
@@ -303,6 +310,7 @@ class _PDFViewSettings { | |
| 'password': password, | ||
| 'nightMode': nightMode, | ||
| 'autoSpacing': autoSpacing, | ||
| 'spacing': spacing, | ||
| 'pageFling': pageFling, | ||
| 'pageSnap': pageSnap, | ||
| 'enableAntialiasing': enableAntialiasing, | ||
|
|
||
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.
🧩 Analysis chain
🌐 Web query:
In Apple's PDFKit, how does PDFView.pageBreakMargins affect inter-page spacing when displayDirection is horizontal? Do left/right insets control the visible gap in horizontal paging modes?💡 Result:
PDFView.pageBreakMarginsis only used for the page-break “spacing” layout whendisplaysPageBreaks == true: it defines extra inset around each page’s frame (top/left/bottom/right), and PDFKit uses that to create the visible separation between adjacent pages. By default, when page breaks are shown, the margins are non‑zero; if page breaks are off, the margins are effectively zero. Negative values are clamped to0. [1][2]So when
displayDirection == .horizontalin a scroll/continuous layout, the visible gap between pages horizontally is produced by the trailing margin of the left page (right) plus the leading margin of the next page (left) (top/bottom mainly affect vertical padding around the page, not the left↔right inter-page gap). [1]In contrast, in “paging” setups that aren’t using PDFKit’s page-break spacing (commonly when you enable
usePageViewController(true)),pageBreakMarginstypically won’t control the inter-page gap because pages aren’t laid out in the same continuous “page breaks” container. (There’s no public API in PDFKit to set UIPageViewController’s internal inter-page spacing.) [1]Sources:
[1] ComPDFKit
CPDFViewdocs describingdisplaysPageBreaksandpageBreakMarginssemantics (mirrors Apple PDFKit behavior) (developers.compdf.com)[2] Monkeybread
PDFViewMBS.pageBreakMarginsnotes on defaults + clamping (monkeybreadsoftware.net)Citations:
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 333
🏁 Script executed:
# Read the full FlutterPDFView.m to understand initialization and context wc -l ios/flutter_pdfview/Sources/flutter_pdfview/FlutterPDFView.mRepository: endigo/flutter_pdfview
Length of output: 130
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 7515
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 793
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 1270
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 2745
🏁 Script executed:
Repository: endigo/flutter_pdfview
Length of output: 48
Inter-page spacing will not be visible without enabling page breaks on iOS.
pageBreakMarginsonly affects spacing whendisplaysPageBreaksistrue. The current code never enables page breaks, so the spacing parameter has no effect regardless of inset direction. Even with the conditional inset fix for horizontal/vertical paging, the feature won't work until_pdfView.displaysPageBreaks = YESis set during initialization. Additionally, when using horizontal paging (displayDirection = kPDFDisplayDirectionHorizontal), the visible inter-page gap is controlled by left/right insets, not top/bottom—soUIEdgeInsetsMake(_spacing, 0, _spacing, 0)produces no horizontal spacing.Possible fix
🤖 Prompt for AI Agents