From 6493e6f7eac371be1a5432b000aa7a3276dd640f Mon Sep 17 00:00:00 2001 From: fwcd Date: Fri, 27 Sep 2024 05:24:29 +0200 Subject: [PATCH] Disable animations in grid if there are too many displays For performance reasons --- src/screens/home/displays/DisplayGrid.tsx | 55 ++++++++++++++--------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/src/screens/home/displays/DisplayGrid.tsx b/src/screens/home/displays/DisplayGrid.tsx index f8f0c1a..8109d4a 100644 --- a/src/screens/home/displays/DisplayGrid.tsx +++ b/src/screens/home/displays/DisplayGrid.tsx @@ -17,29 +17,42 @@ export function DisplayGrid({ searchQuery, displayWidth, }: DisplayGridProps) { + // Filter the models case-insensitively by the search query + const filteredModels = [...userModels.entries()] + .filter(([username]) => + username.toLowerCase().includes(searchQuery.toLowerCase()) + ) + .sort(([u1], [u2]) => u1.localeCompare(u2)); + + // Disable animations automatically if there are too many displays for + // performance reasons. Unfortunately we can't seem to change the layoutId + // after the component has mounted, so even if a user filters down the view + // the displays might not animate: https://github.com/framer/motion/issues/2075 + const animationsEnabled = filteredModels.length <= 512; + return (
- {[...userModels.entries()] - .filter(([username]) => - username.toLowerCase().includes(searchQuery.toLowerCase()) - ) - .sort(([u1], [u2]) => u1.localeCompare(u2)) - .map(([username, userModel]) => ( - - - {({ inView, ref }) => ( - - - - )} - - - ))} + {filteredModels.map(([username, userModel]) => ( + + + {({ inView, ref }) => ( + + + + )} + + + ))}
); }