diff --git a/Libraries/Animated/createAnimatedComponent.js b/Libraries/Animated/createAnimatedComponent.js index 15072c0c7cb..0690aeec241 100644 --- a/Libraries/Animated/createAnimatedComponent.js +++ b/Libraries/Animated/createAnimatedComponent.js @@ -11,7 +11,6 @@ 'use strict'; import View from '../Components/View/View'; -import setAndForwardRef from '../Utilities/setAndForwardRef'; import {AnimatedEvent} from './AnimatedEvent'; import * as createAnimatedComponentInjection from './createAnimatedComponentInjection'; import NativeAnimatedHelper from './NativeAnimatedHelper'; @@ -275,4 +274,27 @@ function createAnimatedComponent( }); } +function setAndForwardRef({ + getForwardedRef, + setLocalRef, +}: $ReadOnly<{| + getForwardedRef: () => ?React.Ref, + setLocalRef: (ref: React.ElementRef) => mixed, +|}>): (ref: React.ElementRef) => void { + return function forwardRef(ref: React.ElementRef) { + const forwardedRef = getForwardedRef(); + + setLocalRef(ref); + + // Forward to user ref prop (if one has been specified) + if (typeof forwardedRef === 'function') { + // Handle function-based refs. String-based refs are handled as functions. + forwardedRef(ref); + } else if (typeof forwardedRef === 'object' && forwardedRef != null) { + // Handle createRef-based refs + forwardedRef.current = ref; + } + }; +} + export default (createAnimatedComponent: typeof createAnimatedComponent);