Skip to content

Commit

Permalink
Update pannable example with Animated
Browse files Browse the repository at this point in the history
  • Loading branch information
rclai committed Jan 6, 2016
1 parent 082cb0b commit 0d0da77
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Do an `npm i react-native-gesture-recognizers` and then try out one of the examp

## Basic panning example
```javascript
import React, { Component, Text, View } from 'react-native';
import React, { Component, Text, View, Animated } from 'react-native';
import { pannable } from 'react-native-gesture-recognizers';

@pannable({
Expand All @@ -20,7 +20,7 @@ class PanMe {

render() {
return (
<View style={{width:100, height: 100}}>
<View style={{width:100, height: 100, backgroundColor: 'red'}}>
<Text>Pan me!</Text>
</View>
);
Expand All @@ -32,16 +32,14 @@ class TransformOnPan extends Component {
constructor(props, context) {
super(props, context);
this.state = {
transform: [],
transform: new Animated.ValueXY(),
}
}

onPan = ({ absoluteChangeX, absoluteChangeY }) => {
this.setState({
transform: [
{translateX: absoluteChangeX},
{translateY: absoluteChangeY}
]
this.state.transform.setValue({
x: absoluteChangeX,
y: absoluteChangeY,
});
}

Expand All @@ -54,7 +52,7 @@ class TransformOnPan extends Component {
// due to the wrapping view staying in place and receiving touches
<PanMe
onPan={this.onPan}
panDecoratorStyle={{transform}} />
panDecoratorStyle={{transform: transform.getTranslateTransform()}} />
);
}
}
Expand Down

0 comments on commit 0d0da77

Please sign in to comment.