Skip to content
Open
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
13 changes: 7 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { PropTypes, Component } from 'react'
import { PanResponder, View, StyleSheet, Dimensions, InteractionManager } from 'react-native'

import tween from './tweener'
import { getRtlSide } from './rtl'

let deviceScreen = Dimensions.get('window')
const DOUBLE_TAP_INTERVAL = 500
Expand Down Expand Up @@ -235,7 +236,7 @@ export default class Drawer extends Component {
};

shouldOpenDrawer(dx) {
let hasActiveHeading = this._open ^ dx > 0 ^ this.props.side === 'right'
let hasActiveHeading = this._open ^ dx > 0 ^ this.props.side === getRtlSide('right')
if (!hasActiveHeading) return this._open
else return this._open ^ Math.abs(dx) > this.state.viewport.width * this.props.panThreshold
}
Expand Down Expand Up @@ -269,9 +270,9 @@ export default class Drawer extends Component {
if (!this.props.acceptPan) return false

//Do nothing if we are panning the wrong way
if (this._open ^ gestureState.dx < 0 ^ this.props.side === 'right') return false
if (this._open ^ gestureState.dx < 0 ^ this.props.side === getRtlSide('right')) return false

let dx = this.props.side === 'right' ? gestureState.dx * -1 : gestureState.dx
let dx = this.props.side === getRtlSide('right') ? gestureState.dx * -1 : gestureState.dx
let left = this._prevLeft + dx
left = Math.min(left, this.getOpenLeft())
left = Math.max(left, this.getClosedLeft())
Expand Down Expand Up @@ -311,7 +312,7 @@ export default class Drawer extends Component {
let swipeToLeft = (gestureState.dx < 0) ? true : false
let swipeToRight = (gestureState.dx > 0) ? true : false
let swipeUpDown = (Math.abs(gestureState.dy) >= Math.abs(gestureState.dx)) ? true : false
let swipeInCloseDirection = (this.props.side === 'left') ? swipeToLeft : swipeToRight
let swipeInCloseDirection = (this.props.side === getRtlSide('left')) ? swipeToLeft : swipeToRight
if (swipeUpDown || (this._open && !swipeInCloseDirection) || (!this._open && swipeInCloseDirection)) {
return false
}
Expand Down Expand Up @@ -354,8 +355,8 @@ export default class Drawer extends Component {
if (this._childDrawer && this._childDrawer._open) return false

let x0 = e.nativeEvent.pageX
let deltaOpen = this.props.side === 'left' ? this.state.viewport.width - x0 : x0
let deltaClose = this.props.side === 'left' ? x0 : this.state.viewport.width - x0
let deltaOpen = this.props.side === getRtlSide('left') ? this.state.viewport.width - x0 : x0
let deltaClose = this.props.side === getRtlSide('left') ? x0 : this.state.viewport.width - x0

if ( this._open && deltaOpen > this.getOpenMask() ) return false
if ( !this._open && deltaClose > this.getClosedMask() ) return false
Expand Down
11 changes: 11 additions & 0 deletions rtl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
I18nManager
} from 'react-native'

export function getRtlSide(side) {
if (I18nManager.isRTL) {
return side === 'left' ? 'right' : 'left'
}

return side
}