diff --git a/packages/core/src/components/item-sliding/item-options.tsx b/packages/core/src/components/item-sliding/item-options.tsx index c3d3d33394..d85dae3e88 100644 --- a/packages/core/src/components/item-sliding/item-options.tsx +++ b/packages/core/src/components/item-sliding/item-options.tsx @@ -1,6 +1,6 @@ import { Component, h, Ionic, Prop } from '@stencil/core'; -import { isRightSide, Side } from '../../utils/util'; +import { isRightSide, Side } from '../../utils/helpers'; /** diff --git a/packages/core/src/components/item-sliding/item-sliding.tsx b/packages/core/src/components/item-sliding/item-sliding.tsx index 8e9aa3cf25..16b6302b9d 100644 --- a/packages/core/src/components/item-sliding/item-sliding.tsx +++ b/packages/core/src/components/item-sliding/item-sliding.tsx @@ -1,7 +1,7 @@ import { Component, h, Ionic, State } from '@stencil/core'; import { GestureDetail, HostElement } from '../../utils/interfaces'; -import { swipeShouldReset } from '../../utils/util'; +import { swipeShouldReset } from '../../utils/helpers'; // import { ItemOptions } from './item-options'; diff --git a/packages/core/src/utils/helpers.ts b/packages/core/src/utils/helpers.ts index a3548b1d7d..41ce9d3f3d 100644 --- a/packages/core/src/utils/helpers.ts +++ b/packages/core/src/utils/helpers.ts @@ -111,4 +111,45 @@ export function getToolbarHeight(toolbarTagName: string, pageChildren: HTMLEleme } return ''; +} + +/** @hidden */ +export type Side = 'left' | 'right' | 'start' | 'end'; + +/** + * @hidden + * Given a side, return if it should be on the right + * based on the value of dir + * @param side the side + * @param isRTL whether the application dir is rtl + * @param defaultRight whether the default side is right + */ +export function isRightSide(side: Side, isRTL: boolean, defaultRight: boolean = false): boolean { + switch (side) { + case 'right': return true; + case 'left': return false; + case 'end': return !isRTL; + case 'start': return isRTL; + default: return defaultRight ? !isRTL : isRTL; + } +} + +/** @hidden */ +export function swipeShouldReset(isResetDirection: boolean, isMovingFast: boolean, isOnResetZone: boolean): boolean { + // The logic required to know when the sliding item should close (openAmount=0) + // depends on three booleans (isCloseDirection, isMovingFast, isOnCloseZone) + // and it ended up being too complicated to be written manually without errors + // so the truth table is attached below: (0=false, 1=true) + // isCloseDirection | isMovingFast | isOnCloseZone || shouldClose + // 0 | 0 | 0 || 0 + // 0 | 0 | 1 || 1 + // 0 | 1 | 0 || 0 + // 0 | 1 | 1 || 0 + // 1 | 0 | 0 || 0 + // 1 | 0 | 1 || 1 + // 1 | 1 | 0 || 1 + // 1 | 1 | 1 || 1 + // The resulting expression was generated by resolving the K-map (Karnaugh map): + let shouldClose = (!isMovingFast && isOnResetZone) || (isResetDirection && isMovingFast); + return shouldClose; } \ No newline at end of file