diff --git a/packages/core/src/components/item-sliding/item-sliding.tsx b/packages/core/src/components/item-sliding/item-sliding.tsx index ecfe9a198e..9ceb183bf5 100644 --- a/packages/core/src/components/item-sliding/item-sliding.tsx +++ b/packages/core/src/components/item-sliding/item-sliding.tsx @@ -137,6 +137,7 @@ const enum SlidingState { export class ItemSliding { $el: HTMLElement; item: HostElement; + list: HostElement; openAmount: number = 0; startX: number = 0; @@ -209,6 +210,9 @@ export class ItemSliding { this.sides = sides; this.item = this.$el.querySelector('ion-item') as HostElement; + + // Get the parent list to close open containers + this.list = this.$el.closest('ion-list') as HostElement; } canStart(gesture: GestureDetail): boolean { @@ -219,7 +223,7 @@ export class ItemSliding { let container = this; // Close open container if it is not the selected one. - if (container !== this.openContainer) { + if (this.list && container !== this.list.$instance.openContainer) { this.closeOpened(); } @@ -231,7 +235,7 @@ export class ItemSliding { } onDragStart(gesture: GestureDetail) { - this.selectedContainer = this.openContainer = this.preSelectedContainer; + this.selectedContainer = this.list.$instance.openContainer = this.preSelectedContainer; this.selectedContainer.startSliding(gesture.currentX); } @@ -251,9 +255,8 @@ export class ItemSliding { closeOpened(): boolean { this.selectedContainer = null; - if (this.openContainer) { - this.openContainer.close(); - this.openContainer = null; + if (this.list.$instance.openContainer) { + this.list.$instance.closeSlidingItems(); return true; } return false; @@ -410,10 +413,9 @@ export class ItemSliding { } } if (openAmount === 0) { - this.setState(SlidingState.Disabled); this.tmr = setTimeout(() => { - this.tmr = null; this.setState(SlidingState.Disabled); + this.tmr = null; }, 600); this.item.style.transform = ''; return; diff --git a/packages/core/src/components/item-sliding/test/basic.html b/packages/core/src/components/item-sliding/test/basic.html index 1d27e86e20..b036c905b8 100644 --- a/packages/core/src/components/item-sliding/test/basic.html +++ b/packages/core/src/components/item-sliding/test/basic.html @@ -29,264 +29,265 @@ +
+ + + +

No Options

+

Should not error or swipe without options

+
+
+
- - + + + + One Line, dynamic option and text + + + + + + + + + + + + + + + + + + Two options, one dynamic option and text + + + + + + + + + + + + + + + + + + + + + + +

HubStruck Notifications

+

A new message from a repo in your network

+

Oceanic Next has joined your network

+
+ + 10:45 AM + +
+ + + + No close + + + + + + + + + + + +
+ + + + +

RIGHT side - no icons

+

Hey do you want to go to the game tonight?

+
+
+ + Archive + Delete + +
+ + + + +

LEFT side - no icons

+

I think I figured out how to get more Mountain Dew

+
+
+ + Archive + Delete + +
+ + + + + +

RIGHT/LEFT side - icons

+

I think I figured out how to get more Mountain Dew

+
+
+ + + Unread + + + + + + Archive + + + Delete + + +
+ + + + +

RIGHT/LEFT side - icons (slot="start")

+

I think I figured out how to get more Mountain Dew

+
+
+ + + Unread + + + + + + Archive + + + Delete + + +
+ + + + + + + One Line w/ Icon, div only text + + + + + Archive + + + + + + + + + + + + One Line w/ Avatar, div only text + + + + + More + + + Archive + + + Delete + + + + + + + + + One Line, dynamic icon-start option + + + + + + + + + + + + + + + + + + + + +

DOWNLOAD

+

Paragraph text.

+
+
+ + + Archive + + + +
Download
+ + +
Loading...
+
+
+
+ + + + + + + +

ion-item-sliding without options (no sliding)

+

Paragraph text.

+
+
+
+ + -

No Options

-

Should not error or swipe without options

+

Normal ion-item (no sliding)

+

Paragraph text.

-
- - + - One Line, dynamic option and text - - - - - - - - - - - - - - - - - - Two options, one dynamic option and text - - - - - - - - - - - - - - - - - - - - - - -

HubStruck Notifications

-

A new message from a repo in your network

-

Oceanic Next has joined your network

-
- - 10:45 AM - -
- - - - No close - - - - - - - - - - - -
- - - - -

RIGHT side - no icons

+

Normal button (no sliding)

Hey do you want to go to the game tonight?

- - Archive - Delete - -
- - - - -

LEFT side - no icons

-

I think I figured out how to get more Mountain Dew

-
-
- - Archive - Delete - -
- - - - - -

RIGHT/LEFT side - icons

-

I think I figured out how to get more Mountain Dew

-
-
- - - Unread - - - - - - Archive - - - Delete - - -
- - - - -

RIGHT/LEFT side - icons (slot="start")

-

I think I figured out how to get more Mountain Dew

-
-
- - - Unread - - - - - - Archive - - - Delete - - -
- - - - - - - One Line w/ Icon, div only text - - - - - Archive - - - - - - - - - - - - One Line w/ Avatar, div only text - - - - - More - - - Archive - - - Delete - - - - - - - - - One Line, dynamic icon-start option - - - - - - - - - - - - - - - - - - - - -

DOWNLOAD

-

Paragraph text.

-
-
- - - Archive - - - -
Download
- - -
Loading...
-
-
-
- - - - - - - -

ion-item-sliding without options (no sliding)

-

Paragraph text.

-
-
-
- - - -

Normal ion-item (no sliding)

-

Paragraph text.

-
-
- - - -

Normal button (no sliding)

-

Hey do you want to go to the game tonight?

-
-
+
diff --git a/packages/core/src/components/list/list.tsx b/packages/core/src/components/list/list.tsx index 507ee2ec70..2eda6baf8e 100644 --- a/packages/core/src/components/list/list.tsx +++ b/packages/core/src/components/list/list.tsx @@ -1,4 +1,6 @@ -import { Component, h, Method } from '@stencil/core'; +import { Component, h, Method, State } from '@stencil/core'; + +import { ItemSliding } from '../item-sliding/item-sliding'; @Component({ tag: 'ion-list', @@ -12,6 +14,8 @@ import { Component, h, Method } from '@stencil/core'; } }) export class List { + @State() openContainer: ItemSliding; + render() { return ; } @@ -21,8 +25,7 @@ export class List { */ @Method() closeSlidingItems() { - // TODO implement this - console.log('in list method closeSlidingItems'); - // this._slidingGesture && this._slidingGesture.closeOpened(); + this.openContainer.close(); + this.openContainer = null; } }