Create animated refs dynamically
See original GitHub issueDescription
For using infinite lists (which not only add new rows on demand, but also delete old ones) it’s required to create animated refs dynamically. Now it’s only allowed to use useAnimatedRef
which can’t be created on-demand.
Let’s say I added one page (rows are grouped by pages). I wrap first and last rows of page into Animated.View
to measure it’s position inside onScroll
.
That way I can understand the height of view , and track it’s position.
If page is shown in viewport of ScrollView - I can add another page.
Caveats
Motivation
High-performance scrolling, including infinite and cycled lists.
Code Example
Animated.createAnimatedRef()
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:6 (5 by maintainers)
Top Results From Across the Web
How to create animated view dynamically and keep other ...
I want to create a Barrage component for live videos: render() { return ( <View> <Video /> <BarrageLayer ref={r => this.
Read more >Animate dynamically elements with React Hooks - GSAP
For what I understood, to use gsap to animate my elements, I need first to target them with ref and useRef(), I was...
Read more >How to use React createRef - LogRocket Blog
Learn how to use the React.createRef() method and useRef Hook in React to simplify creating refs and interact with the HTML DOM.
Read more >Animated - React Native
The core workflow for creating an animation is to create an Animated.Value , hook it up to one or more style attributes of...
Read more >Create Refs dynamically in React - Medium
Under the hood use-dynamic-refs uses a singleton instance of Javascript Map . This gives you a store of key-value pairs of your refs...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’m having the same issue. I need to define multiple animated “scrollviews” that are coming dynamically, but I need to have their refs in order to have access to their “scrollTo” method.
I tried something like this:
@jkadamczyk 👋🏻 Yes, you are right.
Yes. Not sure about reassignment (the original code is gone).
Yes.
Yes.
Ability to create animated refs dynamically (for example for every list element) Ability to create at any code (in callbacks or conditionally) without hooks restrictions. It can be implemented like
React.createRef()
, but not required.The original idea was
<View />
(for every list element or conditionally)<View />
into<Animated.View />
<Animated.View />
to track<View />
ref.measure()
and all worklet stuff on UI threadThis Feature Request helps Implement
<FlatList />
purely on UI thread using<View />
as base component. And managing adding / deleting row ourselves. ImplementviewabilityConfig
andonViewableItemsChanged
on UI thread https://reactnative.dev/docs/virtualizedlist#onviewableitemschanged.