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.

active dot does not update on swipe when children have changed

See original GitHub issue

Which OS ?

IOS and android

Version

Which versions are you using:

  • react-native-swiper 1.5.14?
  • react-native v0.57.8

Expected behaviour

the active dot changes when i swipe

Actual behaviour

the first dot is always highlighted

How to reproduce it>

 <Swiper>
          {items.map(item => (
            <View key={item._id}><Text>{item.label}</Text></View>
          ))}
</Swiper>

Steps to reproduce

  1. make sure that items is empty first []
  2. on a later render. fill items with some objects
  3. active dot is now broken

Workaround:

 <Swiper key={items.length}>
          {items.map(item => (
            <View key={item._id}><Text>{item.label}</Text></View>
          ))}
</Swiper>

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:4
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

26reactions
dannam83commented, Apr 30, 2020

a year later it’s still not resolved. but this will make it work: set the key to the length of your items.

<Swiper key={items.length} style={styles.swiper}> {items} </Swiper>

2reactions
legion-zvercommented, Apr 17, 2019

@macrozone use patch-package and my patch file:

diff --git a/node_modules/react-native-swiper/src/index.js b/node_modules/react-native-swiper/src/index.js
index d9deeb4..d22bcf8 100644
--- a/node_modules/react-native-swiper/src/index.js
+++ b/node_modules/react-native-swiper/src/index.js
@@ -396,8 +396,9 @@ export default class extends Component {
     let index = state.index
     if (!this.internals.offset)   // Android not setting this onLayout first? https://github.com/leecade/react-native-swiper/issues/582
       this.internals.offset = {}
-    const diff = offset[dir] - this.internals.offset[dir]
-    const step = dir === 'x' ? state.width : state.height
+
+    const diff = (offset[dir] || 0) - (this.internals.offset[dir] || 0)
+    const step = (dir === 'x' ? state.width : state.height) || 0
     let loopJump = false
 
     // Do nothing if offset no change.
Read more comments on GitHub >

github_iconTop Results From Across the Web

swiper.update() slider wrong amount of pagination dots
I take an invisible div, and append children inside the container and run swiper.update() . The code looks like this: // Mobile image...
Read more >
Create swipe views with tabs using ViewPager2
Swipe views allow you to navigate between sibling screens, such as tabs, with a horizontal finger gesture, or swipe. This navigation pattern is...
Read more >
Use AssistiveTouch on iPhone - Apple Support
AssistiveTouch helps you use iPhone if you have difficulty touching the screen or pressing the buttons.
Read more >
Material Top Tabs Navigator | React Navigation
A material-design themed tab bar on the top of the screen that lets you switch between different routes by tapping the tabs or...
Read more >
Affordable Care Act (ACA) And Your Coverage - Veterans Affairs
Does the ACA change my VA health benefits? No. The health care law doesn't change your VA health benefits or your out-of-pocket costs....
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