首页 > 解决方案 > react native gesture touch point capture issue

问题描述

I want to get touch points for gestures. When I do it on the same page (touch the screen on a location and move my finger to another location) the below function perfectly works. ( I can get the starting touchpoint and the ending touchpoint) log output for touch on the same screen

  panResponder = PanResponder.create({
    onStartShouldSetResponder: () => true,
    onMoveShouldSetPanResponder: () => true,
    onPanResponderGrant: (evt, gestureState) => {
      console.log(evt.nativeEvent, '........', gestureState);
    },
    onPanResponderRelease: (evt, gestureState) => {
      console.log(evt.nativeEvent, '........................', gestureState);
    },
  });

render() {
    return (
      <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
        <Swiper loop={false} showsPagination={false} index={1}>
          <View style={styles.textInput}>
            <Button
              title="Type"
              onPress={() => this.props.navigation.navigate('Keystroke')}
            />
          </View>
          <Swiper
            {...this.panResponder.panHandlers}
            horizontal={false}
            loop={false}
            showsPagination={false}
            index={1}>
            <View style={styles.textInput}>
              <Text>Swipe left to select typing</Text>
              <Text>Swipe right to select gestures</Text>
            </View>
          </Swiper>

        </Swiper>
      </View>
    );
  }

But, I need to get the starting(onPanResponderGrant) and ending(onPanResponderRelease) coordinates when swiping the screen.

I am using

Import Swiper from 'react-native-swiper';

Here, the starting touchpoint captures. But the ending touchpoint does not capture. log output when swiping the screen

Can someone help me to figure out this issue? Thank you

标签: react-nativemobilegesture

解决方案


使用 onPanResponderEnd 而不是 onPanResponderRelease


推荐阅读