Skip to content

Conversation

hashirshah678
Copy link

Refactor ScrollView reference handling to use React.createRef() instead of a string reference.

Problem
The ParallaxScrollView component was using the legacy string refs pattern (ref="ScrollView"), which has been deprecated since React 16.3 and completely removed in React 18+. This caused a runtime error:
"TypeError: Cannot create property 'current' on string 'ScrollView'"

Solution
Migrated all string refs to use React.createRef() for class component compatibility with modern React Native and Expo SDK.

Changes Made

✅ Replaced string ref SCROLLVIEW_REF = 'ScrollView' with this.scrollViewRef = React.createRef()
✅ Replaced footer callback ref with React.createRef() pattern
✅ Updated all ref access patterns (this.refs[SCROLLVIEW_REF] → this.scrollViewRef.current)
✅ Added optional chaining for safer ref access in public methods

Testing Checklist

Component renders without errors
Parallax scrolling effect works correctly
Sticky header behavior is intact
Background/foreground fade animations work
Public API methods (scrollTo, getScrollResponder, etc.) function properly
No console warnings related to refs
Tested on both iOS and Android (via Expo Go)

Breaking Changes
None - This is a drop-in replacement that maintains the exact same public API.
Dependencies
No new dependencies required. Compatible with:

React 18+
React Native 0.70+
Expo SDK 47+

Related Issues
Fixes #[issue-number] - TypeError on ParallaxScrollView initialization

Type: Bug Fix
Priority: High (blocking component usage)
Reviewer: @jaysoo @dmfrancisco @AndrewJack @alaycock

Refactor ScrollView reference handling to use React.createRef() instead of a string reference.
@alaycock
Copy link
Contributor

alaycock commented Oct 2, 2025

Please don't tag random contributors as reviewers, it's annoying.

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.

2 participants