Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add avoid-super-tabs attribute #314

Merged
merged 1 commit into from
Jun 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ To see this in action, checkout the [example project here](https://github.com/zy
- [`super-tab` Component](#super-tab-component)
- [`SuperTabsController` Provider](#super-tabs-controller-provider)
- [Colors](#colors)
- [Avoid swipe event](#avoid-swipe-event)
- [Examples](#examples)
- [Project goals](#project-goals)

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

<br><br><br>

## Avoid swipe event
Set `avoid-super-tabs="true"` attribute in HTML element for avoid swipe event.<br/>
Example when using the horizontal scroll bar inner [`super-tab` Component](#super-tab-component)

<br><br><br>

# Examples

## Basic example
Expand Down
29 changes: 23 additions & 6 deletions src/super-tabs-pan-gesture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ export class SuperTabsPanGesture {

private listeners: Function[] = [];

constructor(private plt: Platform,
private el: HTMLElement,
private config: SuperTabsConfig,
private rnd: Renderer2) {
constructor(
private plt: Platform,
private el: HTMLElement,
private config: SuperTabsConfig,
private rnd: Renderer2
) {

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

private _onStart(ev: TouchEvent) {
// check avoid this element
var avoid = false;
var element: any = ev.target;
if (element) {
do {
if (element.getAttribute && element.getAttribute('avoid-super-tabs')) avoid = true;
element = element.parentElement;
} while (element && !avoid);
}
if (avoid) {
this.shouldCapture = false;
return;
}

const coords: PointerCoordinates = pointerCoord(ev),
vw = this.plt.width();

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

if (typeof this.shouldCapture !== 'boolean')
// we haven't decided yet if we want to capture this gesture
// we haven't decided yet if we want to capture this gesture
this.checkGesture(coords);


if (this.shouldCapture === true)
// gesture is good, let's capture all next onTouchMove events
// gesture is good, let's capture all next onTouchMove events
this.isDragging = true;
else
return;
Expand Down Expand Up @@ -127,6 +143,7 @@ export class SuperTabsPanGesture {
}

private checkGesture(newCoords: PointerCoordinates) {
if (!this.initialCoords) return;

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