Hi, i’ve build an expo app and want to extend it with some drag-and-drop features. My current approach is using the PanResponder. Can someone give me a hint or link to the documentation how I can integrate code like this with reagent? (Especially the useRef hook)
import React, { useRef } from "react";
import { Animated, View, StyleSheet, PanResponder, Text } from "react-native";
export default function App() {
const pan = useRef(new Animated.ValueXY()).current;
const panResponder = useRef(
PanResponder.create({
onMoveShouldSetPanResponder: () => true,
onPanResponderGrant: () => {
pan.setOffset({
x: pan.x._value,
y: pan.y._value
});
},
onPanResponderMove: Animated.event(
[
null,
{ dx: pan.x, dy: pan.y }
]
),
onPanResponderRelease: () => {
pan.flattenOffset();
}
})
).current;
return (
<View style={styles.container}>
<Text style={styles.titleText}>Drag this box!</Text>
<Animated.View
style={{
transform: [{ translateX: pan.x }, { translateY: pan.y }]
}}
{...panResponder.panHandlers}
>
<View style={styles.box} />
</Animated.View>
</View>
);
}
Thx in advanceI’ve solved this and a have working solution. If someone interested -> PM