Skip to content

Commit

Permalink
Merge pull request #406 from ifsnow/fixed-incorrect-snap
Browse files Browse the repository at this point in the history
Fixed incorrect snap issue after scrollEnabled was changed.
  • Loading branch information
Benoît Delmaire authored Oct 5, 2018
2 parents 20a874a + ac68f65 commit 27783a5
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/carousel/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ export default class Carousel extends Component {
}

_canLockScroll () {
const { enableMomentum, lockScrollWhileSnapping } = this.props;
return !enableMomentum && lockScrollWhileSnapping;
const { scrollEnabled, enableMomentum, lockScrollWhileSnapping } = this.props;
return scrollEnabled && !enableMomentum && lockScrollWhileSnapping;
}

_enableLoop () {
Expand Down Expand Up @@ -468,19 +468,17 @@ export default class Carousel extends Component {
return this._scrollEnabled;
}

_setScrollEnabled (value = true) {
const { scrollEnabled } = this.props;
_setScrollEnabled (scrollEnabled = true) {
const wrappedRef = this._getWrappedRef();

if (!wrappedRef || !wrappedRef.setNativeProps) {
return;
}

value = value && scrollEnabled
// 'setNativeProps()' is used instead of 'setState()' because the latter
// really takes a toll on Android behavior when momentum is disabled
wrappedRef.setNativeProps({ scrollEnabled: value });
this._scrollEnabled = value;
wrappedRef.setNativeProps({ scrollEnabled });
this._scrollEnabled = scrollEnabled;
}

_getKeyExtractor (item, index) {
Expand Down

0 comments on commit 27783a5

Please sign in to comment.