From 162cb83da72566f52bb041dadbe8725d584182ab Mon Sep 17 00:00:00 2001 From: stelselim Date: Wed, 25 Nov 2026 13:08:46 +0100 Subject: [PATCH] fix(gallery-native): enable pull to refresh when gallery is empty When the gallery had no items, only the empty placeholder was rendered in a plain View and FlashList (which owns the refresh control) was not mounted, so pull to refresh could not be triggered. Wrap the placeholder in a ScrollView with a RefreshControl for vertical galleries with a pull down action. Co-Authored-By: Claude Opus 5.5 --- .../gallery-native/CHANGELOG.md | 4 +++ .../gallery-native/src/components/Gallery.tsx | 32 ++++++++++++++++--- .../src/components/__tests__/Gallery.spec.tsx | 23 +++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) diff --git a/packages/pluggableWidgets/gallery-native/CHANGELOG.md b/packages/pluggableWidgets/gallery-native/CHANGELOG.md index 4f2b89615..227ec0b0b 100644 --- a/packages/pluggableWidgets/gallery-native/CHANGELOG.md +++ b/packages/pluggableWidgets/gallery-native/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +### Fixed + +- We've fixed an issue where pull to refresh did not work when the Gallery widget had no items and only showed the empty placeholder. + ### Changed - Migrated device metrics utility to shared package for better code reusability. diff --git a/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx b/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx index 08f15959b..7ba6d9eb8 100644 --- a/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx +++ b/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx @@ -6,6 +6,8 @@ import { View, ViewProps, Platform, + RefreshControl, + ScrollView, TouchableOpacity, useWindowDimensions } from "react-native"; @@ -155,10 +157,32 @@ export const Gallery = (props: GalleryProps): ReactElem props.loadMoreItems ]); - const renderEmptyPlaceholder = useMemo( - (): ReactElement => {props.emptyPlaceholder}, - [props.style.emptyPlaceholder, props.emptyPlaceholder] - ); + const renderEmptyPlaceholder = useMemo((): ReactElement => { + const placeholder = {props.emptyPlaceholder}; + // Without items FlashList is not rendered, so wrap the placeholder in a scroll container + // to keep pull-to-refresh available on an empty gallery. + if (isScrollDirectionVertical && props.pullDown) { + return ( + + } + > + {placeholder} + + ); + } + return placeholder; + }, [ + props.style.emptyPlaceholder, + props.emptyPlaceholder, + isScrollDirectionVertical, + props.pullDown, + props.pullDownIsExecuting, + name + ]); const onContentSizeChange = useCallback((_width: number, height: number): void => { if (height > 0) { diff --git a/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx b/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx index ea4615c1a..0e59e0282 100644 --- a/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx +++ b/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx @@ -167,6 +167,29 @@ describe("Gallery", () => { expect(pullDown).toHaveBeenCalledTimes(1); }); + it("triggers pull down action when list is empty", async () => { + const pullDown = jest.fn(); + const galleryComponent = render( + Empty list...} + pullDown={pullDown} + pullDownIsExecuting={false} + /> + ); + const emptyPlaceholder = galleryComponent.getByTestId("gallery-test-empty-placeholder"); + expect(galleryComponent.getByText("Empty list...")).toBeDefined(); + + const { refreshControl } = emptyPlaceholder.props; + await act(async () => { + refreshControl.props.onRefresh(); + }); + expect(pullDown).toHaveBeenCalledTimes(1); + }); + it("triggers load more items events on end reached", () => { const gallery = render(); const galleryList = gallery.getByTestId("gallery-test-list");