mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +08:00
fix(sliding-item): swipe event
This commit is contained in:
2
core/src/components.d.ts
vendored
2
core/src/components.d.ts
vendored
@ -2030,7 +2030,7 @@ export namespace Components {
|
|||||||
/**
|
/**
|
||||||
* Emitted when the item has been fully swiped.
|
* Emitted when the item has been fully swiped.
|
||||||
*/
|
*/
|
||||||
'onIonSwipe'?: (event: CustomEvent<void>) => void;
|
'onIonSwipe'?: (event: CustomEvent<any>) => void;
|
||||||
/**
|
/**
|
||||||
* The side the option button should be on. Possible values: `"start"` and `"end"`. Defaults to `"end"`. If you have multiple `ion-item-options`, a side must be provided for each.
|
* The side the option button should be on. Possible values: `"start"` and `"end"`. Defaults to `"end"`. If you have multiple `ion-item-options`, a side must be provided for each.
|
||||||
*/
|
*/
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
--ion-color-base: #{ion-color(primary, base)};
|
--ion-color-base: #{ion-color(primary, base)};
|
||||||
--ion-color-contrast: #{ion-color(primary, contrast)};
|
--ion-color-contrast: #{ion-color(primary, contrast)};
|
||||||
|
|
||||||
|
background: #{current-color(base)};
|
||||||
color: #{current-color(contrast)};
|
color: #{current-color(contrast)};
|
||||||
|
|
||||||
font-family: $font-family-base;
|
font-family: $font-family-base;
|
||||||
@ -23,16 +24,12 @@
|
|||||||
|
|
||||||
outline: none;
|
outline: none;
|
||||||
|
|
||||||
background: #{current-color(base)};
|
background: transparent;
|
||||||
|
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
appearance: none;
|
appearance: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-option-native:hover {
|
|
||||||
opacity: 0.8;
|
|
||||||
}
|
|
||||||
|
|
||||||
.item-option-button-inner {
|
.item-option-button-inner {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
|
@ -24,11 +24,13 @@ export class ItemOptions {
|
|||||||
/**
|
/**
|
||||||
* Emitted when the item has been fully swiped.
|
* Emitted when the item has been fully swiped.
|
||||||
*/
|
*/
|
||||||
@Event() ionSwipe!: EventEmitter<void>;
|
@Event() ionSwipe!: EventEmitter<any>;
|
||||||
|
|
||||||
@Method()
|
@Method()
|
||||||
fireSwipeEvent() {
|
fireSwipeEvent() {
|
||||||
this.ionSwipe.emit();
|
this.ionSwipe.emit({
|
||||||
|
side: this.side
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
hostData() {
|
hostData() {
|
||||||
|
@ -108,14 +108,8 @@ export class ItemSliding {
|
|||||||
* the width of the options.
|
* the width of the options.
|
||||||
*/
|
*/
|
||||||
@Method()
|
@Method()
|
||||||
async getSlidingRatio(): Promise<number> {
|
getSlidingRatio(): Promise<number> {
|
||||||
if (this.openAmount > 0) {
|
return Promise.resolve(this.getSlidingRatioSync());
|
||||||
return this.openAmount / this.optsWidthRightSide;
|
|
||||||
} else if (this.openAmount < 0) {
|
|
||||||
return this.openAmount / this.optsWidthLeftSide;
|
|
||||||
} else {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -232,11 +226,12 @@ export class ItemSliding {
|
|||||||
restingPoint = 0;
|
restingPoint = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const state = this.state;
|
||||||
this.setOpenAmount(restingPoint, true);
|
this.setOpenAmount(restingPoint, true);
|
||||||
|
|
||||||
if ((this.state & SlidingState.SwipeEnd) !== 0 && this.rightOptions) {
|
if ((state & SlidingState.SwipeEnd) !== 0 && this.rightOptions) {
|
||||||
this.rightOptions.fireSwipeEvent();
|
this.rightOptions.fireSwipeEvent();
|
||||||
} else if ((this.state & SlidingState.SwipeStart) !== 0 && this.leftOptions) {
|
} else if ((state & SlidingState.SwipeStart) !== 0 && this.leftOptions) {
|
||||||
this.leftOptions.fireSwipeEvent();
|
this.leftOptions.fireSwipeEvent();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -290,14 +285,24 @@ export class ItemSliding {
|
|||||||
|
|
||||||
style.transform = `translate3d(${-openAmount}px,0,0)`;
|
style.transform = `translate3d(${-openAmount}px,0,0)`;
|
||||||
this.ionDrag.emit({
|
this.ionDrag.emit({
|
||||||
amount: openAmount
|
amount: openAmount,
|
||||||
|
ratio: this.getSlidingRatioSync()
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private getSlidingRatioSync(): number {
|
||||||
|
if (this.openAmount > 0) {
|
||||||
|
return this.openAmount / this.optsWidthRightSide;
|
||||||
|
} else if (this.openAmount < 0) {
|
||||||
|
return this.openAmount / this.optsWidthLeftSide;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
hostData() {
|
hostData() {
|
||||||
return {
|
return {
|
||||||
class: {
|
class: {
|
||||||
'item-sliding': true,
|
|
||||||
'item-sliding-active-slide': (this.state !== SlidingState.Disabled),
|
'item-sliding-active-slide': (this.state !== SlidingState.Disabled),
|
||||||
'item-sliding-active-options-end': (this.state & SlidingState.End) !== 0,
|
'item-sliding-active-options-end': (this.state & SlidingState.End) !== 0,
|
||||||
'item-sliding-active-options-start': (this.state & SlidingState.Start) !== 0,
|
'item-sliding-active-options-start': (this.state & SlidingState.Start) !== 0,
|
||||||
@ -308,7 +313,6 @@ export class ItemSliding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @hidden */
|
|
||||||
function swipeShouldReset(isResetDirection: boolean, isMovingFast: boolean, isOnResetZone: boolean): boolean {
|
function swipeShouldReset(isResetDirection: boolean, isMovingFast: boolean, isOnResetZone: boolean): boolean {
|
||||||
// The logic required to know when the sliding item should close (openAmount=0)
|
// The logic required to know when the sliding item should close (openAmount=0)
|
||||||
// depends on three booleans (isCloseDirection, isMovingFast, isOnCloseZone)
|
// depends on three booleans (isCloseDirection, isMovingFast, isOnCloseZone)
|
||||||
|
Reference in New Issue
Block a user