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
Original file line number Diff line number Diff line change
Expand Up @@ -855,7 +855,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender is false) return;
if (Responsive is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.End, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.End, Dir is BitDir.Rtl, BitSwipeOrientation.Horizontal, _dotnetObj);
}

protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out TValue result, [NotNullWhen(false)] out string? parsingErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ protected override async Task OnAfterRenderAsync(bool firstRender)

if (firstRender is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, BitSwipeOrientation.Vertical, _dotnetObj);

_pointerUpAbortControllerId = await _js.BitCircularTimePickerRegisterPointerUp(_dotnetObj, nameof(_HandlePointerUp));
_pointerMoveAbortControllerId = await _js.BitCircularTimePickerRegisterPointerMove(_dotnetObj, nameof(_HandlePointerMove));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender is false) return;
if (Responsive is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, BitSwipeOrientation.Vertical, _dotnetObj);
}

protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out DateTimeOffset? result, [NotNullWhen(false)] out string? validationErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender is false) return;
if (Responsive is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, BitSwipeOrientation.Vertical, _dotnetObj);
}

protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out BitDateRangePickerValue? result, [NotNullWhen(false)] out string? validationErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender is false) return;
if (Responsive is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.Top, Dir is BitDir.Rtl, BitSwipeOrientation.Vertical, _dotnetObj);
}

protected override bool TryParseValueFromString(string? value, [MaybeNullWhen(false)] out TimeSpan? result, [NotNullWhen(false)] out string? validationErrorMessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender is false) return;
if (Responsive is false) return;

await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.End, Dir is BitDir.Rtl, _dotnetObj);
await _js.BitSwipesSetup(_calloutId, 0.25m, BitPanelPosition.End, Dir is BitDir.Rtl, BitSwipeOrientation.Horizontal, _dotnetObj);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ protected override async Task OnAfterRenderAsync(bool firstRender)
if (firstRender)
{
var dotnetObj = DotNetObjectReference.Create(this);
await _js.BitSwipesSetup(_containerId, SwipeTrigger ?? 0.25m, Position ?? BitPanelPosition.End, Dir == BitDir.Rtl, dotnetObj, false);
var position = Position ?? BitPanelPosition.End;
var orientationLock = position == BitPanelPosition.Start || position == BitPanelPosition.End
? BitSwipeOrientation.Horizontal
: BitSwipeOrientation.Vertical;
await _js.BitSwipesSetup(_containerId, SwipeTrigger ?? 0.25m, position, Dir == BitDir.Rtl, orientationLock, dotnetObj, false);
}

if (_internalIsOpen == IsOpen) return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
diffX = 0;
}
} else if (orientationLock === BitSwipeOrientation.Vertical) {
if (orientation === BitSwipeOrientation.Vertical && absY > threshold) {
if (orientation === BitSwipeOrientation.Vertical) {
cancel();
diffX = 0;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@ namespace Bit.BlazorUI;

internal static class SwipesJsRuntimeExtensions
{
internal static ValueTask BitSwipesSetup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(this IJSRuntime js,
string id,
decimal trigger,
BitPanelPosition position,
bool isRtl,
DotNetObjectReference<T>? dotnetObj,
bool isResponsive = true) where T : class
internal static ValueTask BitSwipesSetup<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(
this IJSRuntime js,
string id,
decimal trigger,
BitPanelPosition position,
bool isRtl,
BitSwipeOrientation orientationLock,
DotNetObjectReference<T>? dotnetObj,
bool isResponsive = true) where T : class
{
return js.InvokeVoid("BitBlazorUI.Swipes.setup", id, trigger, position, isRtl, dotnetObj, isResponsive);
return js.InvokeVoid("BitBlazorUI.Swipes.setup", id, trigger, position, isRtl, orientationLock, dotnetObj, isResponsive);
}

internal static ValueTask BitSwipesDispose(this IJSRuntime jsRuntime, string id)
Expand Down
50 changes: 47 additions & 3 deletions src/BlazorUI/Bit.BlazorUI/Scripts/Swipes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
trigger: number,
position: BitSwipePosition,
isRtl: boolean,
orientationLock: BitSwipeOrientation,
dotnetObj: DotNetObject,
isResponsive: boolean) {
if (isResponsive) {
Expand All @@ -22,6 +23,7 @@
let startX = -1;
let startY = -1;
let originalTransform: string;
let orientation = BitSwipeOrientation.None;
const bcr = element.getBoundingClientRect();
const isTouchDevice = Utils.isTouchDevice();

Expand All @@ -44,9 +46,36 @@
diffX = getX(e) - startX;
diffY = getY(e) - startY;

if (e.cancelable) {
e.preventDefault();
e.stopPropagation();
const absX = Math.abs(diffX);
const absY = Math.abs(diffY);
const thresX = absX > 5;
const thresY = absY > 5;


if (orientation === BitSwipeOrientation.None) {
if (thresX && !thresY) {
orientation = BitSwipeOrientation.Horizontal;
} else if (!thresX && thresY) {
orientation = BitSwipeOrientation.Vertical;
}
}

if (orientationLock === BitSwipeOrientation.Horizontal) {
if (orientation === BitSwipeOrientation.Horizontal) {
cancel();
diffY = 0;
} else {
diffX = 0;
}
} else if (orientationLock === BitSwipeOrientation.Vertical) {
if (orientation === BitSwipeOrientation.Vertical) {
cancel();
diffX = 0;
} else {
diffY = 0;
}
} else if ((thresX || thresY)) {
cancel();
}

if ((!isRtl && position === BitSwipePosition.Start) || (isRtl && position === BitSwipePosition.End)) {
Expand Down Expand Up @@ -82,6 +111,13 @@
}

await dotnetObj.invokeMethodAsync('OnMove', diffX, diffY);

function cancel() {
if (e.cancelable) {
e.preventDefault();
e.stopPropagation();
}
}
};

const onEnd = async (e: TouchEvent | PointerEvent): Promise<void> => {
Expand Down Expand Up @@ -117,6 +153,7 @@
} finally {
await dotnetObj.invokeMethodAsync('OnEnd', diffX, diffY);
diffX = diffY = 0;
orientation = BitSwipeOrientation.None;
}
};

Expand All @@ -125,6 +162,7 @@

startX = startY = -1;
diffX = diffY = 0;
orientation = BitSwipeOrientation.None;
element.style.transitionDuration = '';
element.style.transform = originalTransform;
}
Expand Down Expand Up @@ -194,4 +232,10 @@
Top = 2,
Bottom = 3,
}

enum BitSwipeOrientation {
None,
Horizontal,
Vertical
}
}
Loading