Skip to content

Commit b7da642

Browse files
stionicihadeed
authored andcommitted
Add avoid-super-tabs attribute (#314)
1 parent 0adb2f2 commit b7da642

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ To see this in action, checkout the [example project here](https://github.com/zy
2424
- [`super-tab` Component](#super-tab-component)
2525
- [`SuperTabsController` Provider](#super-tabs-controller-provider)
2626
- [Colors](#colors)
27+
- [Avoid swipe event](#avoid-swipe-event)
2728
- [Examples](#examples)
2829
- [Project goals](#project-goals)
2930

@@ -270,6 +271,12 @@ All color inputs takes color names like any other Ionic 2 component. Your color
270271

271272
<br><br><br>
272273

274+
## Avoid swipe event
275+
Set `avoid-super-tabs="true"` attribute in HTML element for avoid swipe event.<br/>
276+
Example when using the horizontal scroll bar inner [`super-tab` Component](#super-tab-component)
277+
278+
<br><br><br>
279+
273280
# Examples
274281

275282
## Basic example

src/super-tabs-pan-gesture.ts

+23-6
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@ export class SuperTabsPanGesture {
2525

2626
private listeners: Function[] = [];
2727

28-
constructor(private plt: Platform,
29-
private el: HTMLElement,
30-
private config: SuperTabsConfig,
31-
private rnd: Renderer2) {
28+
constructor(
29+
private plt: Platform,
30+
private el: HTMLElement,
31+
private config: SuperTabsConfig,
32+
private rnd: Renderer2
33+
) {
3234

3335
this.listeners.push(
3436
rnd.listen(el, 'touchstart', this._onStart.bind(this)),
@@ -51,6 +53,20 @@ export class SuperTabsPanGesture {
5153
}
5254

5355
private _onStart(ev: TouchEvent) {
56+
// check avoid this element
57+
var avoid = false;
58+
var element: any = ev.target;
59+
if (element) {
60+
do {
61+
if (element.getAttribute && element.getAttribute('avoid-super-tabs')) avoid = true;
62+
element = element.parentElement;
63+
} while (element && !avoid);
64+
}
65+
if (avoid) {
66+
this.shouldCapture = false;
67+
return;
68+
}
69+
5470
const coords: PointerCoordinates = pointerCoord(ev),
5571
vw = this.plt.width();
5672

@@ -75,12 +91,12 @@ export class SuperTabsPanGesture {
7591
if (!this.isDragging) {
7692

7793
if (typeof this.shouldCapture !== 'boolean')
78-
// we haven't decided yet if we want to capture this gesture
94+
// we haven't decided yet if we want to capture this gesture
7995
this.checkGesture(coords);
8096

8197

8298
if (this.shouldCapture === true)
83-
// gesture is good, let's capture all next onTouchMove events
99+
// gesture is good, let's capture all next onTouchMove events
84100
this.isDragging = true;
85101
else
86102
return;
@@ -127,6 +143,7 @@ export class SuperTabsPanGesture {
127143
}
128144

129145
private checkGesture(newCoords: PointerCoordinates) {
146+
if (!this.initialCoords) return;
130147

131148
const radians = this.config.maxDragAngle * (Math.PI / 180),
132149
maxCosine = Math.cos(radians),

0 commit comments

Comments
 (0)