-
-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from dsznajder/feature/with-limits-and-multipl…
…y-preserve-offset Add limit and preserveMultiplyOffset
- Loading branch information
Showing
5 changed files
with
292 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import * as React from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import Animated from "react-native-reanimated"; | ||
import { PanGestureHandler } from "react-native-gesture-handler"; | ||
import { limit } from "react-native-redash"; | ||
|
||
const { Value, event } = Animated; | ||
|
||
export default class App extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
this.X = new Value(0); | ||
this.Y = new Value(0); | ||
const dragX = new Value(0); | ||
const dragY = new Value(0); | ||
const panState = new Value(0); | ||
|
||
this.handlePan = event([ | ||
{ | ||
nativeEvent: { | ||
translationX: dragX, | ||
translationY: dragY, | ||
state: panState, | ||
}, | ||
}, | ||
]); | ||
|
||
this.X = limit(dragX, panState, -100, 100); | ||
this.Y = limit(dragY, panState, -100, 100); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<PanGestureHandler | ||
onGestureEvent={this.handlePan} | ||
onHandlerStateChange={this.handlePan} | ||
> | ||
<Animated.View | ||
style={[ | ||
styles.box, | ||
{ | ||
transform: [{ translateX: this.X }, { translateY: this.Y }], | ||
}, | ||
]} | ||
/> | ||
</PanGestureHandler> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
backgroundColor: "#ecf0f1", | ||
padding: 8, | ||
}, | ||
box: { | ||
height: 40, | ||
width: 40, | ||
backgroundColor: "red", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as React from "react"; | ||
import { View, StyleSheet } from "react-native"; | ||
import Animated from "react-native-reanimated"; | ||
import { PinchGestureHandler } from "react-native-gesture-handler"; | ||
import { preserveMultiplicativeOffset } from "react-native-redash"; | ||
|
||
const { Value, event } = Animated; | ||
|
||
export default class App extends React.Component { | ||
constructor(props) { | ||
super(props); | ||
|
||
const scale = new Value(1); | ||
const scaleState = new Value(0); | ||
|
||
this.handleZoom = event([ | ||
{ | ||
nativeEvent: { | ||
scale, | ||
state: scaleState, | ||
}, | ||
}, | ||
]); | ||
|
||
this.scale = preserveMultiplicativeOffset(scale, scaleState); | ||
} | ||
|
||
render() { | ||
return ( | ||
<View style={styles.container}> | ||
<PinchGestureHandler | ||
onGestureEvent={this.handleZoom} | ||
onHandlerStateChange={this.handleZoom} | ||
> | ||
<Animated.View | ||
style={[ | ||
styles.box, | ||
{ | ||
transform: [{ scale: this.scale }], | ||
}, | ||
]} | ||
/> | ||
</PinchGestureHandler> | ||
</View> | ||
); | ||
} | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
alignItems: "center", | ||
justifyContent: "center", | ||
backgroundColor: "#ecf0f1", | ||
padding: 8, | ||
}, | ||
box: { | ||
height: 40, | ||
width: 40, | ||
backgroundColor: "red", | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.