fix(menu): rtl support

This commit is contained in:
Manu Mtz.-Almeida
2017-04-24 01:02:20 +02:00
parent 51d507998c
commit 53113366e2
16 changed files with 129 additions and 138 deletions

View File

@ -7,7 +7,8 @@ import { Platform } from '../platform/platform';
* @hidden
*/
export class SlideEdgeGesture extends SlideGesture {
public edges: Array<string>;
public edges: string[];
public maxEdgeStart: any;
private _d: any;
@ -23,31 +24,42 @@ export class SlideEdgeGesture extends SlideGesture {
}
setEdges(edges: string) {
this.edges = edges.split(' ');
const isRTL = this.plt.isRTL;
this.edges = edges.split(' ').map((value) => {
switch (value) {
case 'start': return isRTL ? 'right' : 'left';
case 'end': return isRTL ? 'left' : 'right';
default: value;
}
});
}
canStart(ev: any): boolean {
let coord = pointerCoord(ev);
const coord = pointerCoord(ev);
this._d = this.getContainerDimensions();
return this.edges.every(edge => this._checkEdge(edge, coord));
}
getContainerDimensions() {
const plt = this.plt;
return {
left: 0,
top: 0,
width: this.plt.width(),
height: this.plt.height()
width: plt.width(),
height: plt.height()
};
}
_checkEdge(edge: string, pos: any) {
_checkEdge(edge: string, pos: any): boolean {
const data = this._d;
const maxEdgeStart = this.maxEdgeStart;
switch (edge) {
case 'left': return pos.x <= this._d.left + this.maxEdgeStart;
case 'right': return pos.x >= this._d.width - this.maxEdgeStart;
case 'top': return pos.y <= this._d.top + this.maxEdgeStart;
case 'bottom': return pos.y >= this._d.height - this.maxEdgeStart;
case 'left': return pos.x <= data.left + maxEdgeStart;
case 'right': return pos.x >= data.width - maxEdgeStart;
case 'top': return pos.y <= data.top + maxEdgeStart;
case 'bottom': return pos.y >= data.height - maxEdgeStart;
}
return false;
}
}