mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 11:41:20 +08:00
refactor(item): add helper functions for item sliding
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import { Component, h, Ionic, Prop } from '@stencil/core';
|
||||
|
||||
import { isRightSide, Side } from '../../utils/util';
|
||||
import { isRightSide, Side } from '../../utils/helpers';
|
||||
|
||||
|
||||
/**
|
||||
|
@ -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';
|
||||
|
||||
|
@ -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;
|
||||
}
|
Reference in New Issue
Block a user