Skip to content

Commit d4a3cde

Browse files
committed
feat(gestures): add basic gesture demos
1 parent 9fd2408 commit d4a3cde

File tree

8 files changed

+65
-2
lines changed

8 files changed

+65
-2
lines changed

src/core/gestures/MdGestureConfig.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {Injectable} from 'angular2/core';
2+
import {HammerGestureConfig} from 'angular2/src/platform/browser_common';
3+
4+
/* Adjusts configuration of our gesture library, Hammer. */
5+
@Injectable()
6+
export class MdGestureConfig extends HammerGestureConfig {
7+
/* List of new event names to add to the gesture support list */
8+
events: string[] = ['drag', 'longpress'];
9+
10+
/*
11+
* Overrides default recognizer event names and thresholds.
12+
*
13+
* Our gesture names come from the Material Design gestures spec:
14+
* https://www.google.com/design/spec/patterns/gestures.html#gestures-touch-mechanics
15+
*
16+
* More information on default recognizers can be found in Hammer docs:
17+
* http://hammerjs.github.io/recognizer-pan/
18+
* http://hammerjs.github.io/recognizer-press/
19+
*
20+
* TODO: Confirm threshold numbers with Material Design UX Team
21+
* */
22+
overrides: {[key: string]: Object} = {
23+
'pan': {event: 'drag', threshold: 6},
24+
'press': {event: 'longpress', time: 500}
25+
};
26+
}

src/demo-app/demo-app.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ <h1>Angular Material2 Demos</h1>
1414
<li><a [routerLink]="['ListDemo']">List demo</a></li>
1515
<li><a [routerLink]="['LiveAnnouncerDemo']">Live Announcer demo</a></li>
1616
<li><a [routerLink]="['SidenavDemo']">Sidenav demo</a></li>
17+
<li><a [routerLink]="['GesturesDemo']">Gestures demo</a></li>
1718
</ul>
1819
<button md-raised-button (click)="root.dir = (root.dir == 'rtl' ? 'ltr' : 'rtl')">
1920
{{root.dir.toUpperCase()}}

src/demo-app/demo-app.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {OverlayDemo} from './overlay/overlay-demo';
1515
import {ListDemo} from './list/list-demo';
1616
import {InputDemo} from './input/input-demo';
1717
import {LiveAnnouncerDemo} from './live-announcer/live-announcer-demo';
18-
18+
import {GesturesDemo} from './gestures/gestures-demo';
1919

2020
@Component({
2121
selector: 'home',
@@ -45,6 +45,7 @@ export class Home {}
4545
new Route({path: '/input', name: 'InputDemo', component: InputDemo}),
4646
new Route({path: '/toolbar', name: 'ToolbarDemo', component: ToolbarDemo}),
4747
new Route({path: '/list', name: 'ListDemo', component: ListDemo}),
48-
new Route({path: '/live-announcer', name: 'LiveAnnouncerDemo', component: LiveAnnouncerDemo})
48+
new Route({path: '/live-announcer', name: 'LiveAnnouncerDemo', component: LiveAnnouncerDemo}),
49+
new Route({path: '/gestures', name: 'GesturesDemo', component: GesturesDemo})
4950
])
5051
export class DemoApp { }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<div class="demo-gestures">
2+
<div (longpress)="pressCount = pressCount + 1" (drag)="dragCount = dragCount + 1"
3+
(swipe)="swipeCount = swipeCount + 1">
4+
Drag or press me.
5+
</div>
6+
drag: {{dragCount}}
7+
swipe: {{swipeCount}}
8+
longpress: {{pressCount}}
9+
</div>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.demo-gestures div {
2+
height: 100px;
3+
width: 200px;
4+
background: gray;
5+
padding: 15px;
6+
color: #FFF;
7+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {Component} from 'angular2/core';
2+
3+
@Component({
4+
selector: 'gestures-demo',
5+
templateUrl: 'demo-app/gestures/gestures-demo.html',
6+
styleUrls: ['demo-app/gestures/gestures-demo.css'],
7+
directives: []
8+
})
9+
export class GesturesDemo {
10+
dragCount: number = 0;
11+
pressCount: number = 0;
12+
swipeCount: number = 0;
13+
}

src/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
<script src="vendor/angular2/bundles/angular2.dev.js"></script>
2121
<script src="vendor/angular2/bundles/http.dev.js"></script>
2222
<script src="vendor/angular2/bundles/router.dev.js"></script>
23+
24+
<!-- TODO: Replace with updated Hammer version in Google CDN -->
25+
<script src="https://cdnjs.cloudflare.com/ajax/libs/hammer.js/2.0.6/hammer.min.js"></script>
2326
<script>
2427
System.config({
2528
packages: {

src/main.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import {bootstrap} from 'angular2/platform/browser';
2+
import {HAMMER_GESTURE_CONFIG} from 'angular2/src/platform/browser_common';
23
import {DemoApp} from './demo-app/demo-app';
34
import {ROUTER_PROVIDERS} from 'angular2/router';
45
import {OVERLAY_CONTAINER_TOKEN} from './core/overlay/overlay';
56
import {MdLiveAnnouncer} from './core/live-announcer/live-announcer';
67
import {provide} from 'angular2/core';
78
import {createOverlayContainer} from './core/overlay/overlay-container';
9+
import {MdGestureConfig} from './core/gestures/MdGestureConfig';
810

911
bootstrap(DemoApp, [
1012
ROUTER_PROVIDERS,
1113
MdLiveAnnouncer,
1214
provide(OVERLAY_CONTAINER_TOKEN, {useValue: createOverlayContainer()}),
15+
provide(HAMMER_GESTURE_CONFIG, {useClass: MdGestureConfig})
1316
]);

0 commit comments

Comments
 (0)