leecade / leecade/react-native-swiper

Programatic scrollling getting stuck

Open
#1,134 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.5k
Forks
2.3k
PR merge metrics
No merged PRs in 30d

Description

Which OS ?

macos 10.14.6

Version

Which versions are you using:

  • react-native-swiper v1.5.14?
  • react-native v0.61.5.?
Expected behaviour

When controlling image swiping programatically using scrollBy, with scrollEnabled={false}, the component does not become unresponsive

Actual behaviour

scrolling feels stuck and unresponsive

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.

  • add at least 2 images to the swiper (children)
  • programaticaly scroll right on the last image
  • get stuck

I've made a patch for it, below, it's a simple fix:

diff --git a/node_modules/react-native-swiper/src/index.js b/node_modules/react-native-swiper/src/index.js
index d9deeb4..bac7954 100644
--- a/node_modules/react-native-swiper/src/index.js
+++ b/node_modules/react-native-swiper/src/index.js
@@ -455,14 +455,21 @@ export default class extends Component {
    */

   scrollBy = (index, animated = true) => {
-    if (this.internals.isScrolling || this.state.total < 2) return
+    if (this.internals.isScrolling || this.state.total < 2) {
+      return
+    }
     const state = this.state
     const diff = (this.props.loop ? 1 : 0) + index + this.state.index
     let x = 0
     let y = 0
     if (state.dir === 'x') x = diff * state.width
     if (state.dir === 'y') y = diff * state.height
-
+    // prevent diff from reflecting children that don't exist
+    // which will cause this.internals.isScrolling to get stuck in true
+    // and this method will bounce is the first if, causing the user to get stuck
+    if (diff > this.props.children.length -1 || diff < 0) {
+      return
+    }
     if (Platform.OS !== 'ios') {
       this.scrollView && this.scrollView[animated ? 'setPage' : 'setPageWithoutAnimation'](diff)
     } else {

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/index.js at the scrollBy method, then reproduce the issue using an example in the examples folder with at least two images, scrollEnabled={false}, and a programmatic scroll on the last image. Verify that scrolling remains responsive at the boundary and that the reported stuck state no longer occurs.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, react-native
Domain
mobile
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.