question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android paging block until going one page back

See original GitHub issue

I have a 4 page carousel. Sometimes, not always, on Android, when I try going forward, I get stuck after the 2nd page. only when I go back one step, and then forward again, I can go more step forward. Also I get weird inconsistent jumps with the animation.

Here’s how it looks: tutorialandroidbug

my code:

<Carousel
                    style={carouselStyle.carousel}
                    chosenBulletStyle={carouselStyle.chosenBullet}
                    bulletStyle={carouselStyle.bullet}
                    autoplay={false}
                    bullets={true}
                    pageInfo={false}
                    onAnimateNextPage={(p) => this.pageChange(p)}
                >
                    <FCarouselItem title={strings.tutorial.content[0].title} text={strings.tutorial.content[0].text} image={icons.logo_with_text}/>
                    <FCarouselItem style={{backgroundColor:FetchyColors.primaryColorAlpha}} title={strings.tutorial.content[1].title} text={strings.tutorial.content[1].text} image={icons.tutorial_fab_screen}/>
                    <FCarouselItem style={{backgroundColor:FetchyColors.primaryColorAlpha}} title={strings.tutorial.content[2].title} text={strings.tutorial.content[2].text} image={icons.delivery_add_screen}/>
                    <FCarouselItem style={{backgroundColor:FetchyColors.primaryColorAlpha}} title={strings.tutorial.content[3].title} text={strings.tutorial.content[3].text} image={icons.trip_add_screen}/>
                </Carousel>

this.pageChange(p) changes the bottom text with setState for the parent component, but even without this - the bug still occurs

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:14

github_iconTop GitHub Comments

8reactions
techrahcommented, Feb 8, 2017

After further investigation, it seems like this might be a core bug. I’m working exclusively with Android at the moment, so I’m guessing that this is in the ScrollView control on the Java side.

Let’s say we have 4 pages, page 0 to page 3 (last page). Two additional pages will be created, page 4 = page 0, and page 5 = page 1.

If your initial page is page 0, a non-animated scroll will move you to page 4, allowing you to swipe left (to last page) or right (to page 5 == page 1).

If you then swipe right, you will move to page 5 (==page 1), then after the scroll has completed, a non-animated scroll will move you to page 1, again allowing you to scroll left (to page 0) or right (to page 2).

If you then swipe left, you will move to page 0, then after the scroll has completed, a non-animated scroll will move you to page 4 (==page 0).

In the last two scenarios above, the _scrollTo function is called to do this non-animated scroll. If you perform an animated scroll just after the non-animated scroll, this “fixes” the issue.

  _scrollTo = (offset, animated) => {
    if (this.scrollView) {
      this.scrollView.scrollTo({ y: 0, x: offset, animated });
      this.scrollView.scrollTo({ y: 0, x: offset, animated: true });
    }
  }

It should be noted that this issue also occurs (albeit less frequently) when sliding left to page 0 (as described in the swipe left above). I will dig around on the Java side and see if I can find anything there.

2reactions
techrahcommented, Feb 18, 2017

@ammichael @DeDuckProject @Clowning I’ve not been able to determine yet if this is fixable on the Java side. I managed to track down this piece of code in node_modules/react-native/ReactAndroid/src/main/java/com/facebook/react/views/scroll/ReactScrollViewManager.java:

public void scrollTo(
    ReactScrollView scrollView,
    ReactScrollViewCommandHelper.ScrollToCommandData data) {
  if (data.mAnimated) {
    scrollView.smoothScrollTo(data.mDestX, data.mDestY);
  } else {
    scrollView.scrollTo(data.mDestX, data.mDestY);
  }
}

ReactScrollView is defined in ReactScrollView.java (same directory) and extends android.widget.ScrollView so I don’t know that there’s much, if anything, that can be done.

In any case, the workaround so far seems to be holding up well. I see anders-g-hansen adopted the change in a fork. I may be submitting a PR soon with some changes that includes this fix too.

Cheers!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Getting on the same page with Paging 3
The Paging library enables you to load large sets of data gradually and gracefully, reducing network usage and system resources. You told us ......
Read more >
how can I refresh the page number in paging 3 library
This means that it will attempt to load pageSize *3 items before it's happy. How many items are returned from Address().getTicketAPI(page).
Read more >
Android Paging Advanced codelab
In this codelab, you modify a sample app to incorporate the Paging Library, which reduces the app's memory footprint.
Read more >
Load and display paged data - Android Developers
The Paging library provides powerful capabilities for loading and displaying paged data from a larger dataset. This guide demonstrates how ...
Read more >
Page from network and database - Android Developers
As new data is required by the UI, the Pager calls the load() method from the PagingSource and returns a stream of PagingData...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found