我的元素不会相应地移动到onPanResponderMove

时间:2018-05-17 08:28:34

标签: reactjs react-native mobile imagebackground

我成功地使用了panResponder并在图像中移动元素,但它没有相应地移动到鼠标,它太快而且不会停留在图像边框中。

**状态x和状态y是数组的长度。 我添加了一个按钮,每次点击它都会打开另一个inputText并将其推送到数组

DragTextView.js:

 this.panResponder = PanResponder.create({
            onStartShouldSetPanResponder: (evt, gestureState) => true,
            onStartShouldSetPanResponderCapture: (evt, gestureState) => true,
            onMoveShouldSetPanResponder: (evt, gestureState) => true,
            onMoveShouldSetPanResponderCapture: (evt, gestureState) => true,
            onPanResponderGrant: (evt, gestureState) => {
                // then start dragging
            },
            onPanResponderMove: (evt, gestureState) => {
                // then dragging
                console.log("evt = ", evt.target);
                console.log("gestureState = ", gestureState);
                this.setState({
                    x: this.state.x + gestureState.dy,
                    y: this.state.y + gestureState.dx,
                });
            },
            onPanResponderTerminationRequest: (evt, gestureState) => true,
            onPanResponderRelease: (evt, gestureState) => {
                // then finish dragging
            },
            onPanResponderTerminate: (evt, gestureState) => {
            },
            onShouldBlockNativeResponder: (evt, gestureState) => {
                return true;
            },
        });    

0 个答案:

没有答案