Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/components/BootstrapBlazor.PdfReader/PdfReader.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public partial class PdfReader
public uint CurrentPage { get; set; }

/// <summary>
/// 获得/设置 当前缩放倍率 默认 null 使用 100%
/// 获得/设置 当前旋转角度 默认 0 数值范围 0 90 180 270
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment describes the CurrentRotation property but appears in the diff as replacing the previous CurrentScale comment. While the comment itself is correct for CurrentRotation, verify this is intentional and that CurrentScale was truly removed. If CurrentScale was actually removed as a breaking change, this should be documented in the PR description or CHANGELOG.

Copilot uses AI. Check for mistakes.
/// </summary>
[Parameter]
public string? CurrentScale { get; set; }
public int CurrentRotation { get; set; }

/// <summary>
/// 获得/设置 是否适配当前页面宽度 默认 false
Expand Down Expand Up @@ -109,6 +109,12 @@ public partial class PdfReader
[Parameter]
public Func<float, Task>? OnScaleChangedAsync { get; set; }

/// <summary>
/// 页面旋转回调方法
/// </summary>
[Parameter]
public Func<int, Task>? OnRotationChanged { get; set; }
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The callback parameter name 'OnRotationChanged' is inconsistent with the naming convention used by other callbacks in this class. All other callback parameters follow the 'OnXxxAsync' pattern (e.g., 'OnPagesInitAsync', 'OnPageChangedAsync', 'OnScaleChangedAsync'). This should be renamed to 'OnRotationChangedAsync' to maintain consistency.

Suggested change
public Func<int, Task>? OnRotationChanged { get; set; }
public Func<int, Task>? OnRotationChangedAsync { get; set; }

Copilot uses AI. Check for mistakes.

/// <summary>
/// 获得/设置 更多按钮图标 默认为 null 使用内置图标
/// </summary>
Expand Down Expand Up @@ -142,6 +148,7 @@ public partial class PdfReader

private string? _docTitle;
private uint _currentPage;
private float _currentRotation;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Use a consistent integer type for rotation instead of mixing int and float.

CurrentRotation is an int with documented discrete values (0, 90, 180, 270), but the backing field is a float. This mismatch is unnecessary and could mask accidental non-discrete values in future changes. Please make _currentRotation an int so the type matches the public API, the value domain, and the comparisons in OnAfterRenderAsync.

Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Type mismatch: The field '_currentRotation' is declared as 'float', but the 'CurrentRotation' property is 'int'. This inconsistency could lead to type conversion issues. Since rotation angles are discrete values (0, 90, 180, 270) as documented, '_currentRotation' should be 'int' to match the property type.

Suggested change
private float _currentRotation;
private int _currentRotation;

Copilot uses AI. Check for mistakes.
private string? _url;
private string? _dropdownItemCheckIcon;
private string? _dropdownItemDefaultIcon;
Expand Down Expand Up @@ -195,6 +202,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
_currentPage = CurrentPage;
await NavigateToPageAsync(_currentPage);
}
if (_currentRotation != CurrentRotation)
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Equality checks on floating point values can yield unexpected results.

Copilot uses AI. Check for mistakes.
{
_currentRotation = CurrentRotation;
await InvokeVoidAsync("rotate", Id, _currentRotation);
}
if (_showToolbar != ShowToolbar)
{
_showToolbar = ShowToolbar;
Expand Down Expand Up @@ -232,7 +244,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
TriggerPagesLoaded = OnPagesLoadedAsync != null,
TriggerPageChanged = OnPageChangedAsync != null,
TriggerTowPagesOnViewChanged = OnTwoPagesOneViewAsync != null,
TriggerScaleChanged = OnScaleChangedAsync != null
TriggerScaleChanged = OnScaleChangedAsync != null,
TriggerRotationChanged = OnRotationChanged != null,
});

/// <summary>
Expand Down Expand Up @@ -334,4 +347,18 @@ public async Task Printing()
await OnPrintingAsync();
}
}

/// <summary>
/// 页面旋转回调方法
/// </summary>
/// <param name="angle"></param>
/// <returns></returns>
[JSInvokable]
public async Task RotationChanged(int angle)
{
if (OnRotationChanged != null)
{
await OnRotationChanged(angle);
}
}
}
6 changes: 5 additions & 1 deletion src/components/BootstrapBlazor.PdfReader/PdfReader.razor.js
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,15 @@ const addEventBus = (el, pdfViewer, eventBus, invoke, options) => {
}
})

eventBus.on("rotationchanging", evt => {
eventBus.on("rotationchanging", async evt => {
const thumbnailsContainer = el.querySelector(".bb-view-thumbnails");
if (thumbnailsContainer) {
thumbnailsContainer.style.setProperty('--thumb-rotate', `${evt.pagesRotation}deg`);
}

if (options.triggerRotationChanged) {
await invoke.invokeMethodAsync("RotationChanged", evt.pagesRotation);
}
})
}

Expand Down