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

OnLayout in IOS may return a frame which width = 0 and height = 0 cases Swiper can't scroll to the correct page

Open ed1son67 opened this issue 4 years ago • 0 comments

Which OS ?

IOS

Version

Which versions are you using:

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

Expected behaviour

I have a prop named "redirectToTabIdx" to give Swiper an initial index, when redirectToTabIdx > 0,it will scrollTo the corresponding page.

Actual behaviour

SomeTimes on IOS, it can not scrollTo the correct page,it will stay in first page,looks good on Android.

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.

Steps to reproduce

  1. Set index over 1 on IOS 2.kill the app and reopen it. 3.It maybe reproduce.

How to fix it.

I deep in the code and found the onLayout method: image This method trust event.nativeEvent.layout will return the real height and width, but actually Ios maybe return an empty frame.

And I debug in RCTUIManage and found that sometimes it will callback an empty frame to RN.

image

In most time initial index is equal to 0 so it's not a problem.

I temporary add some code to the onLayout method to avoid this situation, it looks good and working. image

ed1son67 avatar Aug 21 '21 05:08 ed1son67