diff --git a/packages/pluggableWidgets/gallery-native/CHANGELOG.md b/packages/pluggableWidgets/gallery-native/CHANGELOG.md index 7a052fcf5..d7b45c55e 100644 --- a/packages/pluggableWidgets/gallery-native/CHANGELOG.md +++ b/packages/pluggableWidgets/gallery-native/CHANGELOG.md @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## [Unreleased] +- We've fixed an issue where Gallery widget does not display data. + ## [2.2.1] - 2026-6-10 ### Changed diff --git a/packages/pluggableWidgets/gallery-native/package.json b/packages/pluggableWidgets/gallery-native/package.json index 191460789..6ab6f707d 100644 --- a/packages/pluggableWidgets/gallery-native/package.json +++ b/packages/pluggableWidgets/gallery-native/package.json @@ -1,7 +1,7 @@ { "name": "gallery-native", "widgetName": "Gallery", - "version": "2.2.1", + "version": "2.2.2", "description": "A flexible gallery widget that renders columns, rows and layouts.", "copyright": "© Mendix Technology BV 2022. All rights reserved.", "license": "Apache-2.0", diff --git a/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx b/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx index 99660d44f..2caa0486e 100644 --- a/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx +++ b/packages/pluggableWidgets/gallery-native/src/components/Gallery.tsx @@ -1,4 +1,4 @@ -import { ReactElement, ReactNode, useCallback, useMemo } from "react"; +import { ReactElement, ReactNode, useCallback, useMemo, useState } from "react"; import { Text, Pressable, View, ViewProps, Platform, TouchableOpacity, useWindowDimensions } from "react-native"; import { ObjectItem, DynamicValue } from "mendix"; import DeviceInfo from "react-native-device-info"; @@ -34,7 +34,10 @@ export const Gallery = (props: GalleryProps): ReactElem const firstItemId = props.items?.[0]?.id; const lastItemId = props.items?.[props.items.length - 1]?.id; const { name, style, itemRenderer } = props; - const { width } = useWindowDimensions(); + const { width, height: windowHeight } = useWindowDimensions(); + // FlashList is virtualized and only renders items that fit within its own height, so it needs a + // non-zero height. The list area is sized from FlashList's reported content height instead of flex. + const [contentHeight, setContentHeight] = useState(0); const onEndReached = (): void => { if (props.pagination === "virtualScrolling" && props.hasMoreItems) { @@ -136,29 +139,55 @@ export const Gallery = (props: GalleryProps): ReactElem [props.style.emptyPlaceholder, props.emptyPlaceholder] ); + const onContentSizeChange = useCallback((_width: number, height: number): void => { + if (height > 0) { + setContentHeight(height); + } + }, []); + + const hasItems = props.items && props.items.length > 0; + + // Shrink to the available space when the content is larger, so widgets below the gallery stay visible. + const containerStyle = + isScrollDirectionVertical && hasItems ? [{ flexShrink: 1 }, props.style.container] : props.style.container; + + // The list area is sized by its content, capped at the window height; beyond that FlashList scrolls + // internally. Starting at 1 lets FlashList render its first items and report their content size. + const listAreaStyle = isScrollDirectionVertical + ? { height: Math.min(Math.max(contentHeight, 1), windowHeight), flexShrink: 1 } + : undefined; + + const listStyle = isScrollDirectionVertical ? [{ flex: 1 }, props.style.list] : props.style.list; + return ( - + {props.filters ? {props.filters} : null} - item.id} - ListEmptyComponent={renderEmptyPlaceholder} - onEndReached={onEndReached} - onEndReachedThreshold={0.6} - scrollEventThrottle={50} - renderItem={renderItem} - style={props.style.list} - testID={`${name}-list`} - /> + {!hasItems && renderEmptyPlaceholder} + {hasItems ? ( + + item.id} + onEndReached={onEndReached} + onEndReachedThreshold={0.6} + scrollEventThrottle={50} + renderItem={renderItem} + style={listStyle} + nestedScrollEnabled + testID={`${name}-list`} + onContentSizeChange={isScrollDirectionVertical ? onContentSizeChange : undefined} + /> + + ) : null} ); }; 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 ebf9e2346..36eeb3574 100644 --- a/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx +++ b/packages/pluggableWidgets/gallery-native/src/components/__tests__/Gallery.spec.tsx @@ -140,8 +140,8 @@ describe("Gallery", () => { it("it shouldn't triggers the load more items event when item list empty", () => { const gallery = render(); - const galleryList = gallery.getByTestId("gallery-test-list"); - fireEvent(galleryList, "onEndReached"); + const galleryList = gallery.queryByTestId("gallery-test-list"); + expect(galleryList).toBeNull(); expect(defaultProps.loadMoreItems).not.toHaveBeenCalled(); }); diff --git a/packages/pluggableWidgets/gallery-native/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap b/packages/pluggableWidgets/gallery-native/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap index 70a4343a0..7fc711bf8 100644 --- a/packages/pluggableWidgets/gallery-native/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap +++ b/packages/pluggableWidgets/gallery-native/src/components/__tests__/__snapshots__/Gallery.spec.tsx.snap @@ -2,173 +2,199 @@ exports[`Gallery rendering rendering with load more button it shouldn't render the paging button if hasn't more item 1`] = ` - - + + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + @@ -178,220 +204,246 @@ exports[`Gallery rendering rendering with load more button it shouldn't render t exports[`Gallery rendering rendering with load more button renders correctly 1`] = ` - - + + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + - - - - Load more - + onBlur={[Function]} + onClick={[Function]} + onFocus={[Function]} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={{}} + testID="gallery-test-pagination-button" + > + + Load more + + @@ -399,220 +451,246 @@ exports[`Gallery rendering rendering with load more button renders correctly 1`] exports[`Gallery rendering rendering with load more button renders correctly with custom paging button title 1`] = ` - - + + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + - - - - Show more - + onBlur={[Function]} + onClick={[Function]} + onFocus={[Function]} + onResponderGrant={[Function]} + onResponderMove={[Function]} + onResponderRelease={[Function]} + onResponderTerminate={[Function]} + onResponderTerminationRequest={[Function]} + onStartShouldSetResponder={[Function]} + style={{}} + testID="gallery-test-pagination-button" + > + + Show more + + @@ -620,173 +698,199 @@ exports[`Gallery rendering rendering with load more button renders correctly wit exports[`Gallery rendering renders correctly 1`] = ` - - + + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + @@ -799,214 +903,217 @@ exports[`Gallery rendering renders correctly horizontal 1`] = ` style={{}} testID="gallery-test" > - - - + + } + horizontal={true} + keyExtractor={[Function]} + nestedScrollEnabled={true} + onEndReached={[Function]} + onEndReachedThreshold={0.6} + scrollEventThrottle={50} + testID="gallery-test-list" + > + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + @@ -1019,202 +1126,212 @@ exports[`Gallery rendering renders correctly with empty list and custom placehol style={{}} testID="gallery-test" > - - - - Empty list... - - + + + Empty list... + `; exports[`Gallery rendering renders correctly with filter 1`] = ` - - + + - 11 + + 11 + - - - + - 22 + + 22 + - - - + - 33 + + 33 + - - - + - 44 + + 44 + - - - + - 55 + + 55 + - - - + - 66 + + 66 + - - - + - 77 + + 77 + - - - + - 88 + + 88 + - - - + - 99 + + 99 + diff --git a/packages/pluggableWidgets/gallery-native/src/package.xml b/packages/pluggableWidgets/gallery-native/src/package.xml index 83840116c..812f72309 100644 --- a/packages/pluggableWidgets/gallery-native/src/package.xml +++ b/packages/pluggableWidgets/gallery-native/src/package.xml @@ -1,6 +1,6 @@ - +