Improve upload panel resizing performance
Refactored the upload panel resizing logic in `CreateEnvelopeWizardPopup` to reduce .NET interop calls and improve responsiveness. - Added a `@ref` attribute and `_bodyLayoutRef` field to reference the upload panel layout element. - Updated `startWizardUploadPanelResize` in `envelope-editor.js` to accept and use a `hostEl` parameter for direct DOM manipulation. - Removed `OnUploadPanelResizeMove` from `CreateEnvelopeWizardPopup.razor` as it is no longer needed. - Updated `OnUploadPanelResizeEnd` to handle the final width passed from JavaScript. - Modified `stopWizardUploadPanelResize` to include the final width when invoking the .NET method. - Cleaned up unused references and state properties in `envelope-editor.js`. These changes reduce latency during resizing and ensure the application state remains consistent.
This commit is contained in:
@@ -36,7 +36,8 @@
|
||||
tabindex="0"
|
||||
@onkeydown="OnWizardKeyDownAsync">
|
||||
<div class="sender-create-wizard__body-layout @(_isUploadPanelResizing ? "sender-create-wizard__body-layout--resizing" : string.Empty)"
|
||||
style="@($"--sender-upload-panel-width: {_uploadPanelWidthPx}px;")">
|
||||
style="@($"--sender-upload-panel-width: {_uploadPanelWidthPx}px;")"
|
||||
@ref="_bodyLayoutRef">
|
||||
<MudPaper Class="sender-create-wizard__stepper-shell" Elevation="0">
|
||||
<MudStepper Vertical="true"
|
||||
NonLinear="false"
|
||||
@@ -538,6 +539,7 @@
|
||||
private bool _isUploadPanelResizing;
|
||||
private double _uploadPanelResizeStartX;
|
||||
private double _uploadPanelResizeStartWidthPx;
|
||||
private ElementReference _bodyLayoutRef;
|
||||
private DotNetObjectReference<CreateEnvelopeWizardPopup>? _resizeDotNetRef;
|
||||
|
||||
private string? _validationMessage;
|
||||
@@ -796,24 +798,16 @@
|
||||
_uploadPanelResizeStartWidthPx,
|
||||
UploadPanelMinWidthPx,
|
||||
UploadPanelMaxWidthPx,
|
||||
_resizeDotNetRef);
|
||||
_resizeDotNetRef,
|
||||
_bodyLayoutRef);
|
||||
|
||||
await InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public Task OnUploadPanelResizeMove(double widthPx)
|
||||
public Task OnUploadPanelResizeEnd(double widthPx)
|
||||
{
|
||||
if (!_isUploadPanelResizing)
|
||||
return Task.CompletedTask;
|
||||
|
||||
_uploadPanelWidthPx = Math.Clamp(widthPx, UploadPanelMinWidthPx, UploadPanelMaxWidthPx);
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
[JSInvokable]
|
||||
public Task OnUploadPanelResizeEnd()
|
||||
{
|
||||
_isUploadPanelResizing = false;
|
||||
return InvokeAsync(StateHasChanged);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ window.envelopeEditor = {
|
||||
minWidth: 240,
|
||||
maxWidth: 1400,
|
||||
dotNetRef: null,
|
||||
hostEl: null,
|
||||
moveHandler: null,
|
||||
upHandler: null,
|
||||
rafId: 0,
|
||||
@@ -269,7 +270,7 @@ window.envelopeEditor = {
|
||||
}, { passive: true });
|
||||
},
|
||||
|
||||
startWizardUploadPanelResize: function (startX, startWidth, minWidth, maxWidth, dotNetRef) {
|
||||
startWizardUploadPanelResize: function (startX, startWidth, minWidth, maxWidth, dotNetRef, hostEl) {
|
||||
const state = window.envelopeEditor._wizardResize;
|
||||
window.envelopeEditor.stopWizardUploadPanelResize();
|
||||
|
||||
@@ -279,9 +280,10 @@ window.envelopeEditor = {
|
||||
state.minWidth = Number(minWidth) || 240;
|
||||
state.maxWidth = Number(maxWidth) || 1400;
|
||||
state.dotNetRef = dotNetRef || null;
|
||||
state.hostEl = hostEl || null;
|
||||
|
||||
state.moveHandler = function (event) {
|
||||
if (!state.active || !state.dotNetRef) {
|
||||
if (!state.active) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -290,19 +292,15 @@ window.envelopeEditor = {
|
||||
const nextWidth = Math.max(state.minWidth, Math.min(state.maxWidth, state.startWidth + delta));
|
||||
state.latestWidth = nextWidth;
|
||||
|
||||
if (state.rafId !== 0) {
|
||||
return;
|
||||
if (state.hostEl) {
|
||||
state.hostEl.style.setProperty('--sender-upload-panel-width', nextWidth + 'px');
|
||||
}
|
||||
|
||||
if (state.rafId !== 0)
|
||||
return;
|
||||
|
||||
state.rafId = window.requestAnimationFrame(function () {
|
||||
state.rafId = 0;
|
||||
if (!state.active || !state.dotNetRef || state.latestWidth == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
const widthToApply = state.latestWidth;
|
||||
state.latestWidth = null;
|
||||
state.dotNetRef.invokeMethodAsync('OnUploadPanelResizeMove', widthToApply);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -322,6 +320,7 @@ window.envelopeEditor = {
|
||||
}
|
||||
|
||||
const dotNetRef = state.dotNetRef;
|
||||
const latestWidth = state.latestWidth;
|
||||
|
||||
if (state.moveHandler) {
|
||||
window.removeEventListener('pointermove', state.moveHandler);
|
||||
@@ -342,9 +341,10 @@ window.envelopeEditor = {
|
||||
state.active = false;
|
||||
state.latestWidth = null;
|
||||
state.dotNetRef = null;
|
||||
state.hostEl = null;
|
||||
|
||||
if (dotNetRef) {
|
||||
dotNetRef.invokeMethodAsync('OnUploadPanelResizeEnd');
|
||||
dotNetRef.invokeMethodAsync('OnUploadPanelResizeEnd', latestWidth ?? state.startWidth);
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user