From fc243c5be0517f5621839cd73cfffb67576c8be5 Mon Sep 17 00:00:00 2001 From: Santiago Cattaneo Date: Fri, 22 Apr 2022 19:28:57 -0300 Subject: [PATCH] * bug * code reorganized --- BlazorReorderList/Reorder.razor | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/BlazorReorderList/Reorder.razor b/BlazorReorderList/Reorder.razor index 4bf3341..55d30e9 100644 --- a/BlazorReorderList/Reorder.razor +++ b/BlazorReorderList/Reorder.razor @@ -14,12 +14,12 @@ } -@if (rs != null && rs.selected != null && itemElem != null) +@if (rs != null && itemElem != null) {
@foreach (var item in Items.Select((v, i) => (v, i))) { -
@ChildContent(item.v)
@@ -90,20 +90,16 @@ public async Task onPress(MouseEventArgs m, TItem item, int index) { - if (Disabled || DisableDrag) return; - if (itemElem == null || rs == null) return; - - shouldRender = false; // Because the method triggers re-render, the click propagation is canceled, if you have a link/or any click event inside it's going to stop working - var ghostElem = itemElem[index]; - elemWidth = await rs.getWidth(ghostElem); - elemPosition = await rs.getPosition(ghostElem); - clickPosition = await rs.getPoint(m.PageX, m.PageY, m.ClientX, m.ClientY); - TItem? clone = Copy != null ? Copy(item) : default(TItem); - rs.Set(Items, clone != null ? clone : item, index, clickPosition, clone != null); - await OnStart.InvokeAsync(rs.selected); + await initDrag(item, index, m.PageX, m.PageY, m.ClientX, m.ClientY); } public async Task onTouch(TouchEventArgs m, TItem item, int index) + { + var p = m.TargetTouches.First(); + await initDrag(item, index, p.PageX, p.PageY, p.ClientX, p.ClientY); + } + + private async Task initDrag(TItem item, int index, double pageX, double pageY, double clientX, double clientY) { if (Disabled || DisableDrag) return; if (itemElem == null || rs == null) return; @@ -112,8 +108,8 @@ var ghostElem = itemElem[index]; elemWidth = await rs.getWidth(ghostElem); elemPosition = await rs.getPosition(ghostElem); - var p = m.TargetTouches.First(); - clickPosition = await rs.getPoint(p.PageX, p.PageY, p.ClientX, p.ClientY); + + clickPosition = await rs.getPoint(pageX, pageY, clientX, clientY); TItem? clone = Copy != null ? Copy(item) : default(TItem); rs.Set(Items, clone != null ? clone : item, index, clickPosition, clone != null); await OnStart.InvokeAsync(rs.selected);