a swipe back named desire

This commit is contained in:
Adam Bradley
2015-05-20 16:52:02 -05:00
parent 841ed7363c
commit 108467dbec
13 changed files with 102 additions and 19 deletions

View File

@ -4,6 +4,8 @@
$z-index-content: 1 !default; $z-index-content: 1 !default;
$z-index-swipe-handle: 5 !default;
$z-index-button: 10 !default;
$z-index-toolbar-border: 20 !default; $z-index-toolbar-border: 20 !default;
$z-index-list-border: 50 !default; $z-index-list-border: 50 !default;
$z-index-aside-overlay: 80 !default; $z-index-aside-overlay: 80 !default;

View File

@ -32,6 +32,7 @@ $button-small-icon-size: 2.1rem !default;
flex-flow: row nowrap; flex-flow: row nowrap;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
z-index: $z-index-button;
margin: $button-margin; margin: $button-margin;
line-height: 1; line-height: 1;

View File

@ -2,23 +2,27 @@ import {Renderer, ElementRef} from 'angular2/angular2'
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {SwipeHandle} from './swipe-handle';
import {NavItem} from '../nav/nav-item';
@Component({ @Component({
selector: 'ion-content', selector: 'ion-content'
// hostProperties: {
// contentClass: 'class.content'
// }
}) })
@View({ @View({
template: ` template: `
<div class="scroll-content"> <div class="scroll-content">
<content></content> <content></content>
</div>` </div>
<swipe-handle [hidden]="hideSwipeHandle"></swipe-handle>`,
directives: [SwipeHandle]
}) })
export class Content { export class Content {
constructor(elementRef: ElementRef) { constructor(navItem: NavItem) {
this.domElement = elementRef.domElement; this.navItem = navItem;
//this.contentClass = true; }
console.log('Content!');
get hideSwipeHandle() {
return !this.navItem.enableBack;
} }
} }

View File

@ -3,8 +3,21 @@
// -------------------------------------------------- // --------------------------------------------------
$content-background-color: #fff !default; $content-background-color: #fff !default;
$swipe-handle-width: 20px !default;
.nav-item-container { .nav-item-container {
background-color: $content-background-color; background-color: $content-background-color;
} }
swipe-handle {
position: absolute;
top: 0;
left: 0;
display: block;
width: $swipe-handle-width;
height: 100%;
z-index: $z-index-swipe-handle;
background: red;
opacity: 0.5;
}

View File

@ -0,0 +1,45 @@
import {ElementRef} from 'angular2/angular2'
import {Ancestor} from 'angular2/src/core/annotations_impl/visibility';
import {Directive} from 'angular2/src/core/annotations_impl/annotations';
import {Gesture} from 'ionic/gestures/gesture';
import {NavItem} from '../nav/nav-item';
@Directive({
selector: 'swipe-handle'
})
export class SwipeHandle {
constructor(@Ancestor() navItem: NavItem, elementRef: ElementRef) {
let nav = navItem.nav;
let gesture = new Gesture(elementRef.domElement);
gesture.listen();
gesture.on('panend', onDragEnd);
gesture.on('panleft', onDragHorizontal);
gesture.on('panright', onDragHorizontal);
let navWidth = 0;
function onDragEnd(ev) {
let completeSwipeBack = (ev.gesture.center.x / navWidth) > 0.5;
nav.swipeBackEnd(completeSwipeBack);
navWidth = 0;
}
function onDragHorizontal(ev) {
if (navWidth === 0) {
navWidth = nav.width();
nav.swipeBackStart();
}
nav.swipeBackProgress( ev.gesture.center.x / navWidth );
}
}
}

View File

@ -222,4 +222,18 @@ export class NavBase {
util.array.remove(this.items, itemOrIndex); util.array.remove(this.items, itemOrIndex);
} }
swipeBackStart() {
console.log('swipeBackStart')
}
swipeBackEnd(completeSwipeBack) {
console.log('swipeBackEnd, completeSwipeBack:', completeSwipeBack)
}
swipeBackProgress(value) {
value = Math.min(1, Math.max(0, value));
console.log('swipeBackProgress', value)
}
} }

View File

@ -32,6 +32,10 @@ export class Nav extends NavBase {
super(loader, injector); super(loader, injector);
this.domElement = elementRef.domElement; this.domElement = elementRef.domElement;
} }
width() {
return this.domElement.offsetWidth;
}
} }

View File

@ -11,7 +11,7 @@
<p>First Page: {{ val }}</p> <p>First Page: {{ val }}</p>
<p> <p>
<button (click)="push()">Push (Go to 2nd)</button> <button class="button" (click)="push()">Push (Go to 2nd)</button>
</p> </p>
</ion-content> </ion-content>

View File

@ -1,14 +1,14 @@
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {NavController, HeaderTemplate, Toolbar} from 'ionic/ionic'; import {NavController, HeaderTemplate, Toolbar, Content} from 'ionic/ionic';
import {SecondPage} from './second-page'; import {SecondPage} from './second-page';
@Component({selector: 'ion-view'}) @Component({selector: 'ion-view'})
@View({ @View({
templateUrl: 'pages/first-page.html', templateUrl: 'pages/first-page.html',
directives: [HeaderTemplate, Toolbar] directives: [HeaderTemplate, Toolbar, Content]
}) })
export class FirstPage { export class FirstPage {
constructor( constructor(

View File

@ -9,11 +9,11 @@
<ion-content class="padding"> <ion-content class="padding">
<p> <p>
<button (click)="pop()">Pop (Go back to 1st)</button> <button class="button" (click)="pop()">Pop (Go back to 1st)</button>
</p> </p>
<p> <p>
<button (click)="push()">Push (Go to 3rd)</button> <button class="button" (click)="push()">Push (Go to 3rd)</button>
</p> </p>
</ion-content> </ion-content>

View File

@ -1,14 +1,14 @@
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {NavController, NavParams, HeaderTemplate, Toolbar} from 'ionic/ionic'; import {NavController, NavParams, HeaderTemplate, Toolbar, Content} from 'ionic/ionic';
import {ThirdPage} from './third-page'; import {ThirdPage} from './third-page';
@Component() @Component()
@View({ @View({
templateUrl: 'pages/second-page.html', templateUrl: 'pages/second-page.html',
directives: [HeaderTemplate, Toolbar] directives: [HeaderTemplate, Toolbar, Content]
}) })
export class SecondPage { export class SecondPage {
constructor( constructor(

View File

@ -9,7 +9,7 @@
<ion-content class="padding"> <ion-content class="padding">
<p> <p>
<button (click)="pop()">Pop (Go back to 2nd)</button> <button class="button" (click)="pop()">Pop (Go back to 2nd)</button>
</p> </p>
</ion-content> </ion-content>

View File

@ -1,13 +1,13 @@
import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations'; import {Component, Directive} from 'angular2/src/core/annotations_impl/annotations';
import {View} from 'angular2/src/core/annotations_impl/view'; import {View} from 'angular2/src/core/annotations_impl/view';
import {NavController, HeaderTemplate, Toolbar} from 'ionic/ionic'; import {NavController, HeaderTemplate, Toolbar, Content} from 'ionic/ionic';
@Component() @Component()
@View({ @View({
templateUrl: 'pages/third-page.html', templateUrl: 'pages/third-page.html',
directives: [HeaderTemplate, Toolbar] directives: [HeaderTemplate, Toolbar, Content]
}) })
export class ThirdPage { export class ThirdPage {
constructor( constructor(