Skip to content

Commit 1fbdf4b

Browse files
committed
feat(menu): drag right side
1 parent b14956d commit 1fbdf4b

3 files changed

Lines changed: 24 additions & 21 deletions

File tree

ionic/components/menu/menu-gestures.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import {Menu} from './menu';
22
import {SlideEdgeGesture} from 'ionic/gestures/slide-edge-gesture';
33

44

5-
class MenuGenericGestureHandler extends SlideEdgeGesture {
6-
constructor(menu: Menu, targetElement, threshold) {
7-
super(targetElement, {
5+
class MenuContentGesture extends SlideEdgeGesture {
6+
constructor(menu: Menu) {
7+
8+
super(menu.getContentElement(), {
89
direction: (menu.side === 'left' || menu.side === 'right') ? 'x' : 'y',
910
edge: menu.side,
10-
threshold: threshold
11+
threshold: 75
1112
});
1213

1314
this.menu = menu;
1415
this.listen();
1516
}
1617

18+
canStart(ev) {
19+
return this.menu.isOpen ? true : super.canStart(ev);
20+
}
21+
1722
// Set CSS, then wait one frame for it to apply before sliding starts
1823
onSlideBeforeStart(slide, ev) {
1924
this.menu.setProgressStart();
@@ -40,29 +45,25 @@ class MenuGenericGestureHandler extends SlideEdgeGesture {
4045
}
4146
}
4247

43-
44-
export class MenuContentGesture extends MenuGenericGestureHandler {
45-
constructor(menu: Menu) {
46-
super(menu, menu.getContentElement(), 75);
47-
}
48-
canStart(ev) {
49-
return this.menu.isOpen ? true : super.canStart(ev);
50-
}
51-
}
52-
5348
export class LeftMenuGesture extends MenuContentGesture {
5449
constructor(menu: Menu) {
5550
super(menu);
5651
}
5752
}
5853

59-
export class RightMenuGesture extends LeftMenuGesture {
54+
export class RightMenuGesture extends MenuContentGesture {
6055
constructor(menu: Menu) {
6156
super(menu);
6257
}
58+
59+
onSlide(slide, ev) {
60+
this.menu.setProgess(slide.distance / slide.min);
61+
}
62+
6363
getElementStartPos(slide, ev) {
6464
return this.menu.isOpen ? slide.min : slide.max;
6565
}
66+
6667
getSlideBoundaries() {
6768
return {
6869
min: -this.menu.width(),

ionic/gestures/slide-edge-gesture.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export class SlideEdgeGesture extends SlideGesture {
1616
}
1717

1818
canStart(ev) {
19-
this._containerRect = this.getContainerDimensions();
19+
this._d = this.getContainerDimensions();
2020
return this.edges.every(edge => this._checkEdge(edge, ev.center));
2121
}
2222

@@ -30,11 +30,11 @@ export class SlideEdgeGesture extends SlideGesture {
3030
}
3131

3232
_checkEdge(edge, pos) {
33-
switch(edge) {
34-
case 'left': return pos.x <= this._containerRect.left + this.threshold;
35-
case 'right': return pos.x >= this._containerRect.width - this.threshold;
36-
case 'top': return pos.y <= this._containerRect.top + this.threshold;
37-
case 'bottom': return pos.y >= this._containerRect.height - this.threshold;
33+
switch (edge) {
34+
case 'left': return pos.x <= this._d.left + this.threshold;
35+
case 'right': return pos.x >= this._d.width - this.threshold;
36+
case 'top': return pos.y <= this._d.top + this.threshold;
37+
case 'bottom': return pos.y >= this._d.height - this.threshold;
3838
}
3939
}
4040

ionic/gestures/slide-gesture.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export class SlideGesture extends DragGesture {
4747
this.slide = null;
4848
});
4949
}
50+
5051
onDrag(ev) {
5152
if (!this.slide || !this.slide.started) return;
5253
this.slide.pos = ev.center[this.direction];
@@ -58,6 +59,7 @@ export class SlideGesture extends DragGesture {
5859
this.slide.delta = this.slide.pos - this.slide.pointerStartPos;
5960
this.onSlide(this.slide, ev);
6061
}
62+
6163
onDragEnd(ev) {
6264
if (!this.slide || !this.slide.started) return;
6365
this.onSlideEnd(this.slide, ev);

0 commit comments

Comments
 (0)