-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix: Improve animated ref value type #8052
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -27,7 +27,7 @@ export default function GetViewPropExample() { | |||
const handlePress = async () => { | |||
// @ts-ignore this is fine | |||
const viewTag = animatedRef() as number; | |||
const result = await getViewProp(viewTag, 'opacity'); | |||
const result = await getViewProp(viewTag, 'opacity', animatedRef.current); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
__internalInstanceHandle?: AnyRecord; | ||
}; | ||
|
||
export type WrapperRef = (React.Component & InstanceMethods) | InstanceMethods; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't use just the InstanceMethods
type as the useAnimatedRef
by default returns a reference to the React.Component
type, which has no methods in common with the InstanceMethods
type. useAnimatedRef
must return the Component
type by default in order to make the ref assignable to any React Native's built-in component without requiring the specification of the template type:
const ref = useAnimatedRef(); // don't have to write: useAnimatedRef<View>()
<View ref={ref} />
getInternalInstanceHandleFromPublicInstance = (_ref: any) => | ||
_ref._internalInstanceHandle; | ||
} | ||
} | ||
|
||
// TODO: Clean this up since 0.74 is the minimum supported version now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if I should somehow address this TODO. I just refactored this code to the more concise and simpler implementation but didn't remove any logic which may be no longer necessary in latest versions of RN.
Summary
This PR improves types used for the animated ref value. The previous implementation required the value to be an instance of the
React.Component
, which worked in most cases. This broke inFlashList
v2 because theref
prop doesn't extend theReact.Component
type and instead it included just types of a few methods that can be used to obtain the view instance.