Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Cannot read property 'scrollTo' of undefined in ParallaxSwiper #50

Open
11AA8R4 opened this issue Jun 22, 2021 · 1 comment

Comments

@11AA8R4
Copy link

11AA8R4 commented Jun 22, 2021

Helloooo
Issue:
When using ParallaxSwiper inside a GestureHanddler component from react-native-gesture-handdler (softwarmansion, reanimated)
and updating any useState hook the following error occours:
TypeError: Cannot read property 'scrollTo' of undefined

Soution i found:

go to your ParallaxSwiper component page
How to: in windows: ctrl click in ParallaxSwiper on your imports section of your .js page

replace this line:
this.animatedScrollView = scrollView;

with this lines:
if(scrollView!==null){
this.animatedScrollView = scrollView;
}

and theses lines:
this.animatedScrollView._component.scrollTo({
x: vertical ? 0 : scrollOffset,
y: vertical ? scrollOffset : 0,
animated,
});

with theses lines:
if(this.animatedScrollView._component!==undefined){
this.animatedScrollView._component.scrollTo({
x: vertical ? 0 : scrollOffset,
y: vertical ? scrollOffset : 0,
animated,
});
}

why this solution:
if you crtl+F the word scrollTo you will notice the final problem points to a variable named _component, when the error occours this var is undefined, so wrapping theses guys with conditions solved the problem for me

@nickmccomb
Copy link

Remove this in ParallaxSwiper.js to get around this issue:

componentWillReceiveProps(nextProps) {
  this.scrollToIndex(nextProps.scrollToIndex);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants