Skip to content
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

Fix scrollTo on FlashList #4384

Merged
merged 1 commit into from
Apr 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/reanimated2/hook/useAnimatedRef.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import {
registerShareableMapping,
} from '../shareables';

interface ComponentRef extends Component {
getScrollableNode?: () => ComponentRef;
}

function getShareableShadowNodeFromComponent(
component: Component
component: ComponentRef
): ShadowNodeWrapper {
return getShadowNodeWrapperFromHostInstance(component);
}
Expand All @@ -19,15 +23,19 @@ const getTagValueFunction = global._IS_FABRIC
? getShareableShadowNodeFromComponent
: getTag;

export function useAnimatedRef<T extends Component>(): RefObjectFunction<T> {
export function useAnimatedRef<T extends ComponentRef>(): RefObjectFunction<T> {
const tag = useSharedValue<number | ShadowNodeWrapper | null>(-1);
const ref = useRef<RefObjectFunction<T>>();

if (!ref.current) {
const fun: RefObjectFunction<T> = <RefObjectFunction<T>>((component) => {
// enters when ref is set by attaching to a component
if (component) {
tag.value = getTagValueFunction(component);
tag.value = getTagValueFunction(
component.getScrollableNode
? component.getScrollableNode()
: component
Comment on lines +35 to +37
Copy link
Member

Choose a reason for hiding this comment

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

Maybe, we could add some comment why we use .getScrollableNode() or just add information that it comes from FlashList?

Copy link
Member Author

Choose a reason for hiding this comment

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

Hopefully git blame should find this PR which links to the original issue but yeah you're right, adding a comment here would be nice 😄 Also, there's a similar place in createAnimatedComponent.tsx which does exactly the same thing and I'd like to move it to a new utils function, wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

The idea of a new function sound great ☺️

);
fun.current = component;
}
return tag.value;
Expand Down