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.

Pagination component does not render with a dotsLength < 2

See original GitHub issue

Is this a bug report, a feature request, or a question?

Bug report

Have you followed the required steps before opening a bug report?

Have you made sure that it wasn’t a React Native bug?

This is not a React Native bug and specific to this library.

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

The issue can be reproduced on both platforms for any version supported by the library.

Is the bug reproductible in a production environment (not a debug one)?

The bug is always reproducible.

Environment

Environment: React: 16.9.0 React native: 0.61.5 react-native-snap-carousel: 3.8.4 (also master)

Target Platform: Android (6.0) iOS (10.0)

Expected Behavior

I expect the pagination component to render itself if I pass a value of 1 or higher to the dotsLength prop.

Actual Behavior

I noticed that my pagination component suddenly wasn’t rendering after changing the number of items that I wanted the pagination component to show for. After checking the code for the pagination component on master I found out that it does not render if the dotsLength passed is falsey or less than 2 (https://github.com/archriss/react-native-snap-carousel/blob/master/src/pagination/Pagination.js#L145).

Reproducible Demo

<Pagination
              dotsLength={1}
              activeDotIndex={0}
              containerStyle={{ backgroundColor: 'rgba(0, 0, 0, 0.75)' }}
              dotStyle={{
                  width: 10,
                  height: 10,
                  borderRadius: 5,
                  marginHorizontal: 8,
                  backgroundColor: 'rgba(255, 255, 255, 0.92)'
              }}
              inactiveDotOpacity={0.4}
              inactiveDotScale={0.6}
/>

Steps to Reproduce

  1. Install the library.
  2. Take the pagination example code (https://github.com/archriss/react-native-snap-carousel/blob/master/doc/PAGINATION.md)
  3. Change the dotsLength to 1 as above.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:5

github_iconTop GitHub Comments

1reaction
RemyLivewallcommented, May 8, 2019

As I mentioned in the issue I found this behavior in the code. I understand that pagination does nothing with a single page, but that doesn’t mean I don’t want to have the option to show it for a single page.

0reactions
luchozamoracommented, Jun 24, 2022

Here’s a quick workaround

<Pagination
   ...
   dotsLength={data.length > 1 ? data.length : 3}
   activeDotIndex={data.length > 1 ? activeDot : 1}
   inactiveDotOpacity={data.length > 1 ? 0.5 : 0}
/>

You basically render three dots, set the middle one as active, and set the opacity of the rest to 0. Hope this helps

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pagination component does not render with a dotsLength < 2
The bug is always reproducible. Environment. Environment: React: 16.9.0. React native: 0.61.5 react-native-snap-carousel: 3.8.4 (also master).
Read more >
Pagination Component not rendered on UI - React
Your issue is a misplaced if statement in the constructor . So this: class Pagination extends React.Component{ constructor(props){ ...
Read more >
react-native-snap-carousel
1, # `<Pagination />` component. 2. 3, Starting with version `2.4.0`, a customizable ... The prop has no effect if `tappableDots` hasn't been...
Read more >
How to Build a Custom Pagination Component in React
We do not render a Pagination component if there are fewer than two pages (and then we return null ) . We render...
Read more >
How to Create a Custom Image Gallery in React Native
I prefer to use react-native-snap-carousel because it does not ... To render the image, the Image component from React Native is used.
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