Skip to content
Open
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: 12 additions & 2 deletions src/components/Search/FilterDropdowns/FilterPopupButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ function FilterPopupButton({viewportOffsetTop, popoverWidth, wrapperStyle, popov
const triggerRef = useRef<View | null>(null);
const anchorRef = useRef<View | null>(null);
const [isOverlayVisible, setIsOverlayVisible] = useState(false);
// Defer mounting the (potentially heavy) popover content until the dropdown is first opened, then keep it
// mounted so the close animation and reopening stay instant. The content is otherwise mounted eagerly on
// screen focus even while hidden, which runs each filter selector's expensive option-building on page load.
const [hasEverExpanded, setHasEverExpanded] = useState(false);
const [customPopoverWidth, setCustomPopoverWidth] = useState<number | undefined>(undefined);
const {calculatePopoverPosition} = usePopoverPosition();

Expand All @@ -90,6 +94,11 @@ function FilterPopupButton({viewportOffsetTop, popoverWidth, wrapperStyle, popov
const calculatePopoverPositionAndToggleOverlay = () => {
calculatePopoverPosition(anchorRef, popoverAnchorAlignment).then((position) => {
setPopoverTriggerPosition({...position, vertical: position.vertical});
// Latch in the same batch as the open (and only when it will actually open, mirroring toggleOverlay's
// alert-modal guard) so the deferred subtree mounts together with the popover becoming visible.
if (!isOverlayVisible && !willAlertModalBecomeVisible) {
setHasEverExpanded(true);
}
toggleOverlay();
Comment thread
TMisiukiewicz marked this conversation as resolved.
});
};
Expand All @@ -107,8 +116,9 @@ function FilterPopupButton({viewportOffsetTop, popoverWidth, wrapperStyle, popov
{/* Dropdown Trigger */}
{renderButton({ref: triggerRef, onPress: calculatePopoverPositionAndToggleOverlay, isExpanded: isOverlayVisible})}

{/* Dropdown overlay */}
{isFocused && (
{/* Dropdown overlay. Gated on hasEverExpanded so the (potentially heavy) content subtree isn't mounted
until the dropdown is first opened — PopoverWithMeasuredContentBase mounts children even while hidden. */}
{isFocused && hasEverExpanded && (
<PopoverWithMeasuredContent
anchorRef={triggerRef}
avoidKeyboard
Expand Down
Loading