import React, { Component } from 'react'; import { Animated, Dimensions, StyleSheet, Text, View } from 'react-native'; import { FlingGestureHandler, Directions, State, } from 'react-native-gesture-handler'; import { USE_NATIVE_DRIVER } from '../config'; const windowWidth = Dimensions.get('window').width; const circleRadius = 30; class Fling extends Component { constructor(props) { super(props); this._touchX = new Animated.Value(windowWidth / 2 - circleRadius); this._translateX = Animated.add( this._touchX, new Animated.Value(-circleRadius) ); this._translateY = new Animated.Value(0); } _onVerticalFlingHandlerStateChange = ({ nativeEvent }, offset) => { if (nativeEvent.oldState === State.ACTIVE) { Animated.spring(this._touchX, { toValue: this._touchX._value + offset, useNativeDriver: USE_NATIVE_DRIVER, }).start(); } }; _onHorizontalFlingHandlerStateChange = ({ nativeEvent }) => { if (nativeEvent.oldState === State.ACTIVE) { Animated.spring(this._translateY, { toValue: this._translateY._value + 10, useNativeDriver: USE_NATIVE_DRIVER, }).start(); } }; render() { return ( this._onVerticalFlingHandlerStateChange(ev, -10) }> ); } } export default class Example extends Component { render() { return ( Move up (with two fingers) or right/left (with one finger) and watch magic happens ); } } const styles = StyleSheet.create({ horizontalPan: { backgroundColor: '#f76f41', height: 300, justifyContent: 'center', marginVertical: 10, }, circle: { backgroundColor: '#42a5f5', borderRadius: circleRadius, height: circleRadius * 2, width: circleRadius * 2, }, });