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

Implement getNativeScrollRef #776

Merged
merged 4 commits into from
Jun 17, 2024

Conversation

j-piasecki
Copy link
Contributor

This PR adds implementation for getNativeScrollRef. It's required for compatibility with react-native-reanimated on the new architecture: https://github.com/software-mansion/react-native-reanimated/blob/720fefba7cd53471e98d52282c783701233861a7/src/reanimated2/hook/useAnimatedRef.ts#L26-L33

@@ -25,4 +25,9 @@ export default abstract class BaseScrollComponent extends React.Component<Scroll
public getScrollableNode(): number | null {
return null;
}

//Override and return ref to your custom scrollview. Useful if you need to use Animated Events on the new architecture.
public getNativeScrollRef(): unknown | null {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really remember why I made it this way. Updated to match the type of FlatList.

naqvitalha
naqvitalha previously approved these changes Jun 10, 2024
@ananyachandra14
Copy link
Collaborator

Getting Typescript errors, can you check? @j-piasecki

@j-piasecki
Copy link
Contributor Author

Now I remember why it was unknown 😅 in the first place:

  • ScrollViewComponent didn't exist yet in React Native 0.49 and this is the version of @types/react-native used and React.ElementRef doesn't seem to exist in React 16
  • I didn't want to import anything from React Native in web-specific section of the code

I solved it by:

  • using ScrollView as a return type which, from admittedly short testing, seems to be forward-compatible
  • declaring ScrollView type to be unknown for web

@ananyachandra14 ananyachandra14 merged commit f802191 into Flipkart:master Jun 17, 2024
1 check passed
@ananyachandra14
Copy link
Collaborator

Thanks @j-piasecki!

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

Successfully merging this pull request may close these issues.

3 participants