feat(PdfReader): add OnScaleChangedAsync parameter#756
Conversation
Reviewer's GuideAdds a new OnScaleChangedAsync callback to PdfReader so consumers can react to zoom changes, wiring it through both the Blazor component and the underlying pdf.js event bus. Sequence diagram for PdfReader scale change callback flowsequenceDiagram
actor User
participant BrowserPdfViewer
participant PdfJsEventBus
participant PdfReaderJs as PdfReader_js
participant DotNetInterop
participant PdfReader as PdfReader_component
User->>BrowserPdfViewer: Change zoom level
BrowserPdfViewer->>PdfJsEventBus: Emit scalechanging(scale)
PdfJsEventBus->>PdfReaderJs: scalechanging event
activate PdfReaderJs
PdfReaderJs->>PdfReaderJs: updateScaleValue(el, scale)
PdfReaderJs->>PdfReaderJs: Check options.triggerScaleChanged
alt triggerScaleChanged is true
PdfReaderJs->>DotNetInterop: invokeMethodAsync(ScaleChanged, scale)
activate DotNetInterop
DotNetInterop->>PdfReader_component: Invoke JSInvokable ScaleChanged(scale)
activate PdfReader_component
PdfReader_component->>PdfReader_component: if OnScaleChangedAsync != null
PdfReader_component->>PdfReader_component: await OnScaleChangedAsync(scale)
deactivate PdfReader_component
deactivate DotNetInterop
else triggerScaleChanged is false
PdfReaderJs-->>PdfJsEventBus: No .NET callback invoked
end
deactivate PdfReaderJs
Updated class diagram for PdfReader scale change supportclassDiagram
class PdfReader {
+Func~bool, Task~ OnTwoPagesOneViewAsync
+Func~float, Task~ OnScaleChangedAsync
+Task OnAfterRenderAsync(bool firstRender)
+Task PageChanged(uint pageIndex)
+Task ScaleChanged(float val)
}
class PdfReaderInteropOptions {
+bool TriggerPagesInit
+bool TriggerPagesLoaded
+bool TriggerPageChanged
+bool TriggerTowPagesOnViewChanged
+bool TriggerScaleChanged
}
PdfReader --> PdfReaderInteropOptions : configures
class PdfReaderJsInterop {
+void addEventBus(element el, object pdfViewer, object eventBus, object invoke, PdfReaderInteropOptions options)
}
PdfReader ..> PdfReaderJsInterop : uses via JS interop
PdfReaderJsInterop ..> PdfReader : invokes ScaleChanged(float val) via JSInvokable
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Pull request overview
This PR adds a new OnScaleChangedAsync callback parameter to the PdfReader component, enabling consumers to react to scale/zoom changes in the PDF viewer. This enhancement follows the existing pattern of event callbacks in the component (similar to OnPageChangedAsync, OnPagesInitAsync, etc.) and addresses issue #755.
Key Changes:
- Added
OnScaleChangedAsyncparameter to expose scale change events to component consumers - Implemented JavaScript event handler for the
scalechangingevent with callback to C# - Added
TriggerScaleChangedoption to control when the callback is invoked
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| PdfReader.razor.cs | Added OnScaleChangedAsync parameter property, ScaleChanged JSInvokable method, and TriggerScaleChanged option configuration |
| PdfReader.razor.js | Modified scalechanging event handler to invoke the C# callback asynchronously when enabled |
Comments suppressed due to low confidence (10)
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:121
- Unused variable title.
const title = el.querySelector('.bb-view-pdf-dialog-title');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:122
- Unused variable author.
const author = el.querySelector('.bb-view-pdf-dialog-author');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:123
- Unused variable subject.
const subject = el.querySelector('.bb-view-pdf-dialog-subject');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:124
- Unused variable keywords.
const keywords = el.querySelector('.bb-view-pdf-dialog-keywords');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:128
- Unused variable modified.
const modified = el.querySelector('.bb-view-pdf-dialog-modified');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:148
- Unused variable webview.
const webview = el.querySelector('.bb-view-pdf-dialog-webview');
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:462
- Unused variable scaleEl.
const scaleEl = el.querySelector(".bb-view-scale-input");
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:563
- The initial value of v is unused, since it is always overwritten.
let v = 100;
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:424
- Avoid automated semicolon insertion (94% of all statements in the enclosing function have an explicit semicolon).
})
src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js:486
- Avoid automated semicolon insertion (91% of all statements in the enclosing function have an explicit semicolon).
delete el.widths
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (options.triggerScaleChanged) { | ||
| await invoke.invokeMethodAsync("ScaleChanged", evt.scale); | ||
| } | ||
| }) |
There was a problem hiding this comment.
Missing semicolon at the end of the eventBus.on("scalechanging", ...) statement. All other event handler registrations in this function (lines 309, 325, 349, 365) end with semicolons for consistency.
| }) | |
| }); |
|
|
||
| /// <summary> | ||
| /// 缩放倍率更改回调方法 | ||
| /// </summary> |
There was a problem hiding this comment.
Missing <param> documentation for the val parameter. Other similar callback methods in this file (e.g., PagesInit, PagesLoaded, PageChanged) include <param> documentation for their parameters.
| /// </summary> | |
| /// </summary> | |
| /// <param name="val">缩放倍率值</param> |
| eventBus.on("scalechanging", async evt => { | ||
| updateScaleValue(el, evt.scale); | ||
|
|
||
| if (options.triggerScaleChanged) { |
There was a problem hiding this comment.
Inconsistent boolean check pattern. Other trigger checks in this function use strict equality comparison with === true (lines 306, 312, 346). Consider changing if (options.triggerScaleChanged) to if (options.triggerScaleChanged === true) for consistency.
| if (options.triggerScaleChanged) { | |
| if (options.triggerScaleChanged === true) { |
Link issues
fixes #755
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add support for notifying consumers when the PDF viewer scale changes in PdfReader.
New Features:
Enhancements: