fix: resolve "measureLayout must be called with a ref to a native component" warning#620
Open
RyadPasha wants to merge 1 commit into
Open
Conversation
…e handles Calling ref.measureLayout() directly on composite (JS) component refs triggers a React Native warning: "ref.measureLayout must be called with a ref to a native component." This happens because containerRef and viewRef point to wrapped/Animated components, not host views. Fix both call sites to use UIManager.measureLayout() with findNodeHandle() to first resolve refs to their underlying native node handles before measuring. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
NestableDraggableFlatListinside aNestableScrollContainer, React Native logs the following warning on every layout:Warning: ref.measureLayout must be called with a ref to a native component.This fires from two places:
NestableDraggableFlatList.tsx..containerRef.current.measureLayout(...)CellRendererComponent.tsx..viewNode.measureLayout(...)Both call
.measureLayout()directly on composite (JS/Animated) component refs, not on host (native) views. React Native requires the caller ref to be a native component.Fix
Replace both call sites with
UIManager.measureLayout(), which accepts native node handles (numbers) resolved viafindNodeHandle(). This is the correct low-level API for measuring across arbitrary component trees.Note:
UIManager.measureLayouthas a different argument order thanref.measureLayout—(node, relativeToNode, onFail, onSuccess).Tested on