leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.4k stars 2.34k forks source link

Using PanResponder in a swipe view? #155

Open getnashty opened 8 years ago

getnashty commented 8 years ago

Is it possible to temporarily lock the swiper functionality while a panresponder is receiving touch events inside the swiper component?

d-krueger commented 8 years ago

+1 I also need this - e.g. by setting props on the swiper scrollEnabled: {true}

jpgarcia commented 7 years ago

Hey @d-krueger, @getnashty

The Swiper component bypasses the props to the ScrollView so you can set the scrollEnabled={false} whenever you want to.

quick and dirty sample:

class Sample extends Component {
  state = {
    disableScroll: false
  }

  render() {
    const itemStyle = { flex: 1, justifyContent: 'center', alignItems: 'center' }

    return (
      <Swiper scrollEnabled={!this.state.disableScroll}>
        <View style={[itemStyle, { backgroundColor: 'gray' } ]}>
          <Text>View 1</Text>
          <TouchableOpacity 
            style={{ backgroundColor: 'cyan' }}
            onPressIn={() => this.setState({ disableScroll : true })} 
            onPressOut={() => this.setState({ disableScroll : false })}
          >
            <Text>DO NOT SCROLL</Text>
          </TouchableOpacity>
         </View>

        <View style={[ itemStyle, { backgroundColor: 'yellow' } ]}>
          <Text>View 2</Text>
        </View>
      </Swiper>        
    )
  }
}