refactor(item): add helper functions for item sliding

This commit is contained in:
Brandy Carney
2017-07-17 11:07:46 -04:00
parent c383fd6a54
commit 1d656657e2
3 changed files with 43 additions and 2 deletions

View File

@ -1,6 +1,6 @@
import { Component, h, Ionic, Prop } from '@stencil/core'; import { Component, h, Ionic, Prop } from '@stencil/core';
import { isRightSide, Side } from '../../utils/util'; import { isRightSide, Side } from '../../utils/helpers';
/** /**

View File

@ -1,7 +1,7 @@
import { Component, h, Ionic, State } from '@stencil/core'; import { Component, h, Ionic, State } from '@stencil/core';
import { GestureDetail, HostElement } from '../../utils/interfaces'; import { GestureDetail, HostElement } from '../../utils/interfaces';
import { swipeShouldReset } from '../../utils/util'; import { swipeShouldReset } from '../../utils/helpers';
// import { ItemOptions } from './item-options'; // import { ItemOptions } from './item-options';

View File

@ -111,4 +111,45 @@ export function getToolbarHeight(toolbarTagName: string, pageChildren: HTMLEleme
} }
return ''; 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;
} }