fixt / react-native-page-swiper

91 stars 47 forks source link

Prevent swiping when first or last page #11

Open Mokto opened 8 years ago

Mokto commented 8 years ago

Hi,

It would be nice that we could prevent the user to swipe right on the last page and left on the first page.

Thanks.

skleest commented 8 years ago

+1 :)

ybonnetain commented 7 years ago

In componentWillMount it is possible to add those extra tests

if (relativeGestureDistance < -0.25 || (relativeGestureDistance < 0 && vx <= -0.25)) {
        if (this.state.index < this.props.children.length - 1) { // make sure it is not the last page before incrementing
          newIndex += 1;
        }
} else if (relativeGestureDistance > 0.25 || (relativeGestureDistance > 0 && vx >= 0.25)) {
      if (this.state.index > 0) { // make sure it is not the first page before decrementing
          newIndex -= 1;
      }
}