Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Reanimated Layout Transitions with TanStack Query #1759

Unanswered
thecoorum asked this question in Q&A
Discussion options

Hey everybody!

So, if I understood correctly the main purpose of the prepareForLayoutAnimationRender is to disable the recycling for the next render? I was wondering how and when I can call this method if I'm using the TanStack Query (infinite query if to be precise) for fetching and caching the data. Any suggestions are welcome and appreciated!

Also, is this the correct CellRendererComponent definition if I want to support Layout Transitions on inserts and removals?

const CellRenderer = (props: any) => (
 <Animated.View
 {...props}
 entering={SpringFadeIn}
 exiting={SpringFadeOut}
 layout={Layout}
 />
);
You must be logged in to vote

Replies: 1 comment 1 reply

Comment options

Hey, did you figure out how to do this?

You must be logged in to vote
1 reply
Comment options

@lsarni hey, yeah, but not sure if this is the most correct approach. Basically, I'm just calling prepareForLayoutAnimationRender on infinite query data change in useMemo. Here is how it's implemented in my code

export const useSortedQueryData = (
 query: InfiniteQueryResult,
 ref: AnimatedRef<FlashListRef<ListInterface>>
) => {
 return useMemo(() => {
 ref.current?.prepareForLayoutAnimationRender();
 const data = transformInfiniteData(query);
 return data.sort((a, b) => {
 if ("__type" in a && "__type" in b) {
 return 0;
 }
 if ("__type" in a) {
 return 1;
 }
 if ("__type" in b) {
 return -1;
 }
 return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
 });
 }, [query]);
};

Hope that will help you 🙂

P.S. transformInfiniteData here is just for flattening the infinite query and inserting skeleton items if the query is loading
P.P.S. The sorting is of course also optional 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants

AltStyle によって変換されたページ (->オリジナル) /