react-native-gesture-handler icon indicating copy to clipboard operation
react-native-gesture-handler copied to clipboard

View jumps underneath on click before being draggable while using the absoluteY value to change its position vertically

Open nlimbu opened this issue 7 years ago • 0 comments

I am using PanGestureHandler along with react-native-reanimated library. The PanGestureHandler gesture event is hooked up to track the absoluteY position of a view. I am using the value retrieved to set the top position of the view. However, every-time i click on the view, it jumps underneath changing the absoluteY position before i can start scrolling the view up and down. Can someone help me understand this behaviour. I would like to start scrolling the view from the point of my initial click not some distance underneath its actual position.

import React from "react";
import { Text, SafeAreaView } from "react-native";
import Animated from "react-native-reanimated";
import { PanGestureHandler } from "react-native-gesture-handler";

const { Value, event } = Animated;

export default class Example extends React.Component {
    constructor(props) {
        super(props);
        this.absoluteY = new Value(100);
        this.gestureState = new Value(-1);
        this.onGestureEvent = event([
            {
                nativeEvent: {

                    state: this.gestureState,
                    absoluteY: this.absoluteY
                }
            }
        ]);
    }

    render() {
        return (
            <SafeAreaView>
                <PanGestureHandler
                    maxPointers={1}
                    onGestureEvent={this.onGestureEvent}
                    onHandlerStateChange={this.onGestureEvent}
                >
                    <Animated.View style={{ top: this.absoluteY }}>
                        <Text>hello</Text>
                    </Animated.View>
                </PanGestureHandler>
            </SafeAreaView>
        );
    }
}

Cp7HK

nlimbu avatar Aug 29 '19 22:08 nlimbu