mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
RN: Inline setAndForwardRef into createAnimatedComponent.js
Summary: Inlines `setAndForwardRef` into `createAnimatedComponent.js`. I am planning to delete `setAndForwardRef` because it encourages a subtle bad practice with management of the referential equality of `ref` entities. I am doing this instead of refactoring `createAnimatedComponent` because this legacy implementation is planned to be replaced very soon. Changelog: [Internal] Reviewed By: sammy-SC Differential Revision: D41205066 fbshipit-source-id: dc481e73a6c4d6acbae530d4da48b3a032575179
This commit is contained in:
committed by
Facebook GitHub Bot
parent
666f56bff3
commit
f657d2906d
@@ -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<Props: {+[string]: mixed, ...}, Instance>(
|
||||
});
|
||||
}
|
||||
|
||||
function setAndForwardRef({
|
||||
getForwardedRef,
|
||||
setLocalRef,
|
||||
}: $ReadOnly<{|
|
||||
getForwardedRef: () => ?React.Ref<any>,
|
||||
setLocalRef: (ref: React.ElementRef<any>) => mixed,
|
||||
|}>): (ref: React.ElementRef<any>) => void {
|
||||
return function forwardRef(ref: React.ElementRef<any>) {
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user