From 5b75d4478fed693eba67b5aed6e824c6a1f56efb Mon Sep 17 00:00:00 2001 From: "Tom (plebeius.eth)" Date: Thu, 13 Mar 2025 22:29:39 +0100 Subject: [PATCH] fix(search bar): use gpu acceleration for popup animation --- .../search-bar/search-bar.module.css | 44 ++--- src/components/search-bar/search-bar.tsx | 9 +- src/components/sidebar/sidebar.tsx | 174 ++++++++++-------- 3 files changed, 123 insertions(+), 104 deletions(-) diff --git a/src/components/search-bar/search-bar.module.css b/src/components/search-bar/search-bar.module.css index b622850d..b4d3a1bf 100644 --- a/src/components/search-bar/search-bar.module.css +++ b/src/components/search-bar/search-bar.module.css @@ -44,14 +44,6 @@ cursor: pointer; } -.searchBarVisible { - visibility: visible; -} - -.searchBarHidden { - visibility: hidden; -} - .infobar { position: relative; width: 278px; @@ -62,28 +54,24 @@ border-style: solid; border-width: 1px; font-size: small; - padding: 0 10px; - height: 0; + padding: 10px; + height: 22px; overflow: hidden; - transition: height 0.3s linear, - visibility 0.3s linear, - padding-top 0.3s linear, - margin-top 0.3s linear, - padding-bottom 0.3s linear, - margin-bottom 0.3s linear; z-index: 1; - margin-bottom: 10px; + margin-top: 5px; + margin-bottom: 12px; + will-change: transform; + transition: transform 0.3s linear, visibility 0.3s linear; + transform-origin: top; } .slideDown { - height: 22px; - padding-top: 10px; - padding-bottom: 10px; - margin-top: 5px; - margin-bottom: 12px; + transform: scaleY(1); + visibility: visible; } .slideUp { + transform: scaleY(0); visibility: hidden; } @@ -95,4 +83,16 @@ .infobar input[type="checkbox"] { margin: 2px .5em 0 0; +} + +.searchBarWrapper { + position: relative; + will-change: transform; + transition: transform 0.3s linear; +} + +.contentWrapper { + position: relative; + will-change: transform; + transition: transform 0.3s linear; } \ No newline at end of file diff --git a/src/components/search-bar/search-bar.tsx b/src/components/search-bar/search-bar.tsx index a6aa456c..53c2f233 100644 --- a/src/components/search-bar/search-bar.tsx +++ b/src/components/search-bar/search-bar.tsx @@ -6,9 +6,10 @@ import { isHomeAboutView, isSubplebbitAboutView } from '../../lib/utils/view-uti interface SearchBarProps { isFocused?: boolean; + onExpandoChange?: (expanded: boolean) => void; } -const SearchBar = ({ isFocused = false }: SearchBarProps) => { +const SearchBar = ({ isFocused = false, onExpandoChange }: SearchBarProps) => { const searchBarRef = useRef(null); const searchInputRef = useRef(null); const wrapperRef = useRef(null); @@ -60,8 +61,12 @@ const SearchBar = ({ isFocused = false }: SearchBarProps) => { } }; + useEffect(() => { + onExpandoChange?.(showExpando); + }, [showExpando, onExpandoChange]); + return ( -
+
{ + setShowExpando(expanded); + }; return (
- - {isInPostPageView && } - - {/* TODO: add .largeButtonDisabled and disabledButtonDescription classnames for subs that don't accept posts */} -
- {t('submit_post')} -
-
- - {!isInHomeView && !isInHomeAboutView && !isInAllView && !isInModView && !isInPendingPostView && !isInSubplebbitsView && !isInHomeAboutView && ( -
- - {subplebbit?.address} - -
- - - - {t('members_count', { count: allActiveUserCount })} + +
+ {isInPostPageView && } + +
+ {t('submit_post')} +
-
- - {isSubCreatedButNotYetPublished ? subCreatedButNotYetPublishedStatus : onlineStatus} - {moderatorRole && ( -
- {moderatorRole === 'moderator' ? t('you_are_moderator') : moderatorRole === 'admin' ? t('you_are_admin') : t('you_are_owner')} -
- )} -
- {description && description.length > 0 && ( -
- {title && title.length > 0 && ( -
- {title} + + {!isInHomeView && !isInHomeAboutView && !isInAllView && !isInModView && !isInPendingPostView && !isInSubplebbitsView && !isInHomeAboutView && ( +
+ + {subplebbit?.address} + +
+ + + + {t('members_count', { count: allActiveUserCount })} +
+
+ + {isSubCreatedButNotYetPublished ? subCreatedButNotYetPublishedStatus : onlineStatus} + {moderatorRole && ( +
+ {moderatorRole === 'moderator' ? t('you_are_moderator') : moderatorRole === 'admin' ? t('you_are_admin') : t('you_are_owner')}
)} -
- +
+ {description && description.length > 0 && ( +
+ {title && title.length > 0 && ( +
+ {title} +
+ )} +
+ +
+
+ )} + {rules && rules.length > 0 && } +
+ {t('created_by', { creatorAddress: '' })} + {`u/${creatorAddress}`} + {createdAt && {t('community_for', { date: getFormattedTimeDuration(createdAt) })}} +
+ {showBlockConfirm ? ( + + {t('are_you_sure')}{' '} + + {t('yes')} + + {' / '} + + {t('no')} + + + ) : ( + + {blocked ? t('unblock_community') : t('block_community')} + + )}
- )} - {rules && rules.length > 0 && } -
- {t('created_by', { creatorAddress: '' })} - {`u/${creatorAddress}`} - {createdAt && {t('community_for', { date: getFormattedTimeDuration(createdAt) })}} -
- {showBlockConfirm ? ( - - {t('are_you_sure')}{' '} - - {t('yes')} - - {' / '} - - {t('no')} - - - ) : ( - - {blocked ? t('unblock_community') : t('block_community')} - - )} +
+ )} + {(moderatorRole || isOwner) && } +
+ {t('create_your_community')} +
+
+ {roles && Object.keys(roles).length > 0 && } + {address && !(moderatorRole || isOwner) && ( +
+ {t('read_only_community_settings')} +
+ )} + {isInSubplebbitsView && ( + +
+
+ {t('submit_community')}
-
-
- )} - {(moderatorRole || isOwner) && } -
- {t('create_your_community')} -
+ + )} + {(!(isMobile && isHomeAboutView) || isInSubplebbitAboutView) &&
}
- {roles && Object.keys(roles).length > 0 && } - {address && !(moderatorRole || isOwner) && ( -
- {t('read_only_community_settings')} -
- )} - {isInSubplebbitsView && ( - -
-
- {t('submit_community')} -
-
- )} - {(!(isMobile && isHomeAboutView) || isInSubplebbitAboutView) &&
); };