Skip to content

Commit 2fc0579

Browse files
committed
feat: 增加 ScrollStrategy 参数
1 parent 280878f commit 2fc0579

3 files changed

Lines changed: 25 additions & 7 deletions

File tree

src/components/BootstrapBlazor.EmbedPDF/EmbedPDF.razor.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public partial class EmbedPDF
3737
/// 获得/设置 标签显示模式 默认值 <see cref="EmbedPDFTabBarMode.Always"/>
3838
/// </summary>
3939
[Parameter]
40-
public EmbedPDFScrollDirection ScrollDirection { get; set; } = EmbedPDFScrollDirection.Vertical;
40+
public EmbedPDFScrollStrategy ScrollStrategy { get; set; } = EmbedPDFScrollStrategy.Vertical;
4141

4242
/// <summary>
4343
/// 获得/设置 主题样式 默认 <see cref="EmbedPDFTheme.System"/>
@@ -72,6 +72,7 @@ public partial class EmbedPDF
7272
private string? _url;
7373
private EmbedPDFTheme _theme;
7474
private string? _language;
75+
private EmbedPDFScrollStrategy _strategy = EmbedPDFScrollStrategy.Vertical;
7576

7677
/// <summary>
7778
/// <inheritdoc/>
@@ -100,6 +101,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
100101
_url = Url;
101102
_language = Language;
102103
_theme = Theme;
104+
_strategy = ScrollStrategy;
103105
return;
104106
}
105107

@@ -118,6 +120,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
118120
_language = Language;
119121
await InvokeVoidAsync("setLocale", Id, _language);
120122
}
123+
if (_strategy != ScrollStrategy)
124+
{
125+
_strategy = ScrollStrategy;
126+
await InvokeVoidAsync("setScrollStrategy", Id, _strategy.ToDescriptionString());
127+
}
121128
}
122129

123130
/// <summary>
@@ -131,7 +138,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
131138
Src = Url,
132139
Lang = Language,
133140
CurrentPage,
134-
ScrollDirection = ScrollDirection.ToDescriptionString(),
141+
ScrollStrategy = ScrollStrategy.ToDescriptionString(),
135142
PageGap
136143
});
137144
}

src/components/BootstrapBlazor.EmbedPDF/EmbedPDF.razor.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import Data from '../BootstrapBlazor/modules/data.js'
22
import EventHandler from "../BootstrapBlazor/modules/event-handler.js"
3-
import { default as EmbedPDF, DocumentManagerPlugin } from './embedpdf.js'
3+
import EmbedPDF from './embedpdf.js'
44
import { getTheme, registerBootstrapBlazorModule } from '../BootstrapBlazor/modules/utility.js'
55

66
export async function init(id, invoke, options) {
@@ -10,7 +10,7 @@ export async function init(id, invoke, options) {
1010
}
1111

1212
const target = el.querySelector('.pdf-viewer');
13-
const { src, tabBar, theme, lang, currentPage, scrollDirection, pageGap } = options;
13+
const { src, tabBar, theme, lang, currentPage, scrollStrategy, pageGap } = options;
1414
const wasmUrl = `${location.origin}/_content/BootstrapBlazor.EmbedPDF/pdfium.wasm`;
1515

1616
let preference = theme;
@@ -38,7 +38,7 @@ export async function init(id, invoke, options) {
3838
fallbackLocale: 'en'
3939
},
4040
scroll: {
41-
defaultStrategy: scrollDirection,
41+
defaultStrategy: scrollStrategy,
4242
defaultPageGap: currentPageGap
4343
}
4444
});
@@ -97,6 +97,17 @@ export async function setLocale(id, locale) {
9797
}
9898
}
9999

100+
export async function setScrollStrategy(id, strategy) {
101+
const pdf = Data.get(id);
102+
const { viewer } = pdf;
103+
104+
if (viewer) {
105+
const registry = await viewer.registry;
106+
const scroll = registry.getPlugin('scroll').provides();
107+
scroll.setScrollStrategy(strategy);
108+
}
109+
}
110+
100111
export function dispose(id) {
101112
const pdf = Data.get(id);
102113
Data.remove(id);

src/components/BootstrapBlazor.EmbedPDF/EmbedPDFScrollDirection.cs renamed to src/components/BootstrapBlazor.EmbedPDF/EmbedPDFScrollStrategy.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace BootstrapBlazor.Components;
99
/// <summary>
1010
/// 滚动方向枚举
1111
/// </summary>
12-
public enum EmbedPDFScrollDirection
12+
public enum EmbedPDFScrollStrategy
1313
{
1414
/// <summary>
1515
/// 垂直方向
@@ -20,6 +20,6 @@ public enum EmbedPDFScrollDirection
2020
/// <summary>
2121
/// 水平方向
2222
/// </summary>
23-
[Description("Horizontal")]
23+
[Description("horizontal")]
2424
Horizontal
2525
}

0 commit comments

Comments
 (0)