leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.43k stars 2.34k forks source link

scrollBy to location 0 not working as expected #1324

Open shay-te opened 2 years ago

shay-te commented 2 years ago

Which OS?

ANDROID

Version

1.6.0

Expected behavior

When using scrollBy with value 0 to go to the first panel. The transition should be done smoothly

Actual behavior

On Android, the photo flickers when moving back to 0

Aditional info.

on IOS the transition is smooth.

HOWEVER, When passing the second parameter animated as true IOS + ANDROID: Will does not scroll to location 0at all

How to reproduce it>

var [photos, setPhotos] = useState([]);

useEffect(function() {
   var photos = [];
    for(var i = 0 ; i < props.profile.photos.length ; i++) {
        photos.push(
            <Pressable onPress={onPhotoClick.bind(this, i)} style={styles.slide} key={props.profile.photos[i]} onStartShouldSetResponder={() => true}>
                <ImageLoading style={styles.photo} resizeMode='contain' source={{uri: props.profile.photos[i]}}>{renderProgress()}</ImageLoading>
            </Pressable>
        );
    }

    setPhotos(photos);
}, [props.profile]);

setPhotos(photos);

function onPhotoClick(i) {
    if (swiperRef.current) {
        swiperRef.current.scrollBy(i < photos.length ? i+1 : 0);
    }
}
....
<Swiper ref={swiperRef}
        showsPagination={true} 
        horizontal={false} 
        showsButtons={false} 
        onIndexChanged={onPhotoVisited} 
        dotColor={constants.COLOR_GREY_30} 
        activeDotColor={isCompleted ? constants.COLOR_GOLD : constants.COLOR_WHITE}>
    {photos}
</Swiper>

-

Steps to reproduce

Run this code and click the photo