Skip to content

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MatiPl01
Copy link
Member

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 in FlashList v2 because the ref prop doesn't extend the React.Component type and instead it included just types of a few methods that can be used to obtain the view instance.

@MatiPl01 MatiPl01 self-assigned this Aug 11, 2025
@@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

viewTag is ignored on Fabric. It seems to have been used on Paper, whilst Fabric requires the component instance to be passed instead of just the viewTag.

cc @tomekzaw (Paper support was removed in #7103 and the viewTag prop was left unused)

__internalInstanceHandle?: AnyRecord;
};

export type WrapperRef = (React.Component & InstanceMethods) | InstanceMethods;
Copy link
Member Author

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.
Copy link
Member Author

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.

@MatiPl01 MatiPl01 marked this pull request as ready for review August 11, 2025 21:56
@MatiPl01 MatiPl01 requested review from tjzel and tomekzaw August 11, 2025 21:56
@MatiPl01 MatiPl01 changed the title chore: Improve animated ref value type fix: Improve animated ref value type Aug 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant