import React, { FunctionComponent } from 'react'; import { StyleSheet } from 'react-native'; import { PanGestureHandlerEventPayload, Gesture, GestureDetector, PanGesture, TapGesture, } from 'react-native-gesture-handler'; import Animated, { useAnimatedStyle } from 'react-native-reanimated'; type AnimatedPostion = { x: Animated.SharedValue; y: Animated.SharedValue; }; interface DraggableProps { id: string; onLongPress: (id: string) => void; onPositionUpdate: (e: PanGestureHandlerEventPayload) => void; enabled: boolean; isActive: boolean; translation: AnimatedPostion; position: { x: number; y: number }; dragGesture: PanGesture; tapEndGesture: TapGesture; tileSize: number; rowGap: number; columnGap: number; } const Draggable: FunctionComponent = ({ id, children, onLongPress, isActive, translation, dragGesture, tapEndGesture, columnGap, rowGap, position, }) => { const tapGesture = Gesture.LongPress() .minDuration(300) .onStart(() => onLongPress(id)) .simultaneousWithExternalGesture(dragGesture) .simultaneousWithExternalGesture(tapEndGesture); const translateStyle = useAnimatedStyle(() => { return { transform: [ { translateX: isActive ? translation.x.value : 0, }, { translateY: isActive ? translation.y.value : 0, }, ], }; }); return ( {children} ); }; const styles = StyleSheet.create({ absolute: { position: 'absolute', zIndex: 10, }, }); export default Draggable;