react-native-swiper icon indicating copy to clipboard operation
react-native-swiper copied to clipboard

onIndexChanged setState change shifts Swiper component until tapping resets to correct style

Open salp13 opened this issue 3 years ago • 5 comments

OS 14.4

Version

Which versions are you using:

  • react-native-swiper v1.6.0
  • react-native v0.62.13

Expected behaviour

When user swipes on component, it should move to next page. Currently I have onIndexChange triggering a change in state (for a variable that isn't the index -- it is something to change a tab header). setState should execute properly and the page change should animate properly with the left hand side of the page stopping at the beginning of the parent view

Actual behaviour

The setState changes properly, and the swipe to the next page animates properly; however, the page swiped to goes past the parent view's margins (about 40 pixels or so). It remains off the end until I click anywhere within the Swiper view and then it immediately goes back to how it should be (not shifted off the edge). I have tried specifying height, width, container style, and index value, but nothing has worked except simply not calling setState. I have also tried onMomentumScrollEnd or using a setTimeout with both trigger functions with the same results. Interesting to note that it does not happen to the first page, but all after the first one (going in either direction) even when the initial index specified isn't the first page.

How to reproduce it>

  • loop is false, showPagination is false, onIndexChanged triggers a setState for a toggle value not used anywhere within the Swiper children.

salp13 avatar Apr 01 '21 18:04 salp13

@salp13 any luck with this? Running into the same issue

i3i2uno avatar Apr 28 '21 02:04 i3i2uno

I was experiencing this issue as well ^

I was wrapping my <Swiper> with some padding in the parent above.

// Broken version

<View style={{ paddingHorizontal: 24 }}>
    <Swiper>
    ...
    </Swiper>
</View>

I was able to fix the issue by moving the padding component inside of the <Swiper> like so;

// Fixed version

<Swiper>
    <View style={{ paddingHorizontal: 24 }}>
    ...
    </View>
</Swiper>

ryan-exe avatar Apr 29 '21 05:04 ryan-exe

I think @ryan-exe 's solution is onto something. I ran into very similar situation. Did not dig into the code but my educated guess is that some calculation (maybe the scrolling offset or the transition distance for animation) is based on width of the screen, not the actual width of the component.

For my case, as long as I have any margin or padding on the parent container of the Swiper, setting state in onIndexChanged will cause the issue described above. The way I solved my problem is to let the Swiper take the entire width of the screen, and use its containerStyle prop for the spacing I needed.

derick-bai avatar Jan 29 '22 01:01 derick-bai

Have the same problem here. I don't have any padding and I can't let the swiper take the entire width of the screen as it acts as a popup/overlay inside my screen. Is it dead ?

dngconsulting avatar Feb 05 '22 17:02 dngconsulting

Facing the same issue here. I cant wrap my components inside the swiper module as I need them to be outside

grant-devon avatar May 22 '23 16:05 grant-devon