Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Recognize gesture to stop presenting
Browse files Browse the repository at this point in the history
  • Loading branch information
whs committed May 11, 2016
1 parent 45ba128 commit dee3aaf
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions components/Editor/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import React, {
StatusBar,
Platform,
Image,
Alert
Alert,
PixelRatio,
PanResponder
} from 'react-native';
import Orientation from 'react-native-orientation';
import BackStack from '../BackStack';
Expand All @@ -29,6 +31,39 @@ export default class Editor extends Component {
BackStack.addEventListener(this._onBack);
Realm.addListener('change', this._onRealmUpdate);
this.file = this.props.route.file;

this._panResponder = PanResponder.create({
onMoveShouldSetPanResponderCapture: (evt, gestureState) => {
if(!this.state.preview || evt.nativeEvent.touches.length !== 2){
return false;
}

this.distanceStart = Math.sqrt(
Math.pow(evt.nativeEvent.touches[0].pageX - evt.nativeEvent.touches[1].pageX, 2)
+ Math.pow(evt.nativeEvent.touches[0].pageY - evt.nativeEvent.touches[1].pageY, 2)
);

return true;
},
onPanResponderMove: (evt, gestureState) => {
if(!this.state.preview || evt.nativeEvent.touches.length !== 2){
return;
}

let distance = Math.sqrt(
Math.pow(evt.nativeEvent.touches[0].pageX - evt.nativeEvent.touches[1].pageX, 2)
+ Math.pow(evt.nativeEvent.touches[0].pageY - evt.nativeEvent.touches[1].pageY, 2)
);
let moved = distance - this.distanceStart;

if(moved < -this.distanceStart/4){
this.setState({
preview: false,
});
return true;
}
},
});
}
componentWillUnmount(){
Orientation.unlockAllOrientations();
Expand Down Expand Up @@ -67,7 +102,7 @@ export default class Editor extends Component {
toolbar = null;
}
return (
<View style={{flex: 1}}>
<View style={{flex: 1}} {...this._panResponder.panHandlers}>
{toolbar}
<StatusBar hidden={this.state.preview} animated={false} />
<SlideDeck slides={this.file.slides} presenting={this.state.preview} editable={!this.state.preview} onPageChange={(no) => this.setState({page: no})}
Expand Down

0 comments on commit dee3aaf

Please sign in to comment.