1- import { ReactElement , ReactNode , useCallback } from "react" ;
2- import { Text , FlatList , Pressable , View , ViewProps , Platform , TouchableOpacity } from "react-native" ;
1+ import { ReactElement , ReactNode , useCallback , useMemo } from "react" ;
2+ import { Text , Pressable , View , ViewProps , Platform , TouchableOpacity , useWindowDimensions } from "react-native" ;
33import { ObjectItem , DynamicValue } from "mendix" ;
44import DeviceInfo from "react-native-device-info" ;
55import { GalleryStyle } from "../ui/Styles" ;
66import { PaginationEnum , ScrollDirectionEnum } from "../../typings/GalleryProps" ;
77import { isAvailable } from "@mendix/piw-utils-internal" ;
88import { extractStyles } from "@mendix/pluggable-widgets-tools" ;
9+ import { FlashList } from "@shopify/flash-list" ;
910
1011const DEFAULT_RIPPLE_COLOR = "rgba(0, 0, 0, 0.2)" ;
1112
@@ -33,6 +34,7 @@ export const Gallery = <T extends ObjectItem>(props: GalleryProps<T>): ReactElem
3334 const firstItemId = props . items ?. [ 0 ] ?. id ;
3435 const lastItemId = props . items ?. [ props . items . length - 1 ] ?. id ;
3536 const { name, style, itemRenderer } = props ;
37+ const { width } = useWindowDimensions ( ) ;
3638
3739 const onEndReached = ( ) : void => {
3840 if ( props . pagination === "virtualScrolling" && props . hasMoreItems ) {
@@ -43,8 +45,9 @@ export const Gallery = <T extends ObjectItem>(props: GalleryProps<T>): ReactElem
4345 const renderItem = useCallback (
4446 ( item : { item : T } ) : ReactElement =>
4547 itemRenderer ( ( children , onPress ) => {
48+ const itemStyle = isScrollDirectionVertical ? undefined : { width } ;
4649 const listItemWrapperProps : ViewProps = {
47- style : isScrollDirectionVertical && { width : ` ${ 100 / numColumns } %` } ,
50+ style : itemStyle ,
4851 testID : `${ name } -list-item-${ item . item . id } `
4952 } ;
5053 const renderListItemContent = (
@@ -67,9 +70,9 @@ export const Gallery = <T extends ObjectItem>(props: GalleryProps<T>): ReactElem
6770 ) ;
6871 } , item . item ) ,
6972 [
70- isScrollDirectionVertical ,
71- numColumns ,
7273 itemRenderer ,
74+ isScrollDirectionVertical ,
75+ width ,
7376 name ,
7477 style . listItem ,
7578 style . firstItem ,
@@ -79,7 +82,7 @@ export const Gallery = <T extends ObjectItem>(props: GalleryProps<T>): ReactElem
7982 ]
8083 ) ;
8184
82- const loadMoreButton = ( ) : ReactElement | null => {
85+ const loadMoreButton = useMemo ( ( ) : ReactElement | null => {
8386 const renderButton = (
8487 < Text style = { props . style . loadMoreButtonCaption } >
8588 { props . loadMoreButtonCaption && isAvailable ( props . loadMoreButtonCaption )
@@ -118,16 +121,26 @@ export const Gallery = <T extends ObjectItem>(props: GalleryProps<T>): ReactElem
118121 < TouchableOpacity { ...buttonProps } > { renderButton } </ TouchableOpacity >
119122 )
120123 ) : null ;
121- } ;
124+ // eslint-disable-next-line react-hooks/exhaustive-deps
125+ } , [
126+ props . style . loadMoreButtonCaption ,
127+ props . loadMoreButtonCaption ,
128+ props . style . loadMoreButtonPressableContainer ,
129+ name ,
130+ props . pagination ,
131+ props . hasMoreItems ,
132+ props . loadMoreItems
133+ ] ) ;
122134
123- const renderEmptyPlaceholder = ( ) : ReactElement => (
124- < View style = { props . style . emptyPlaceholder } > { props . emptyPlaceholder } </ View >
135+ const renderEmptyPlaceholder = useMemo (
136+ ( ) : ReactElement => < View style = { props . style . emptyPlaceholder } > { props . emptyPlaceholder } </ View > ,
137+ [ props . style . emptyPlaceholder , props . emptyPlaceholder ]
125138 ) ;
126139
127140 return (
128141 < View testID = { `${ name } ` } style = { props . style . container } >
129142 { props . filters ? < View > { props . filters } </ View > : null }
130- < FlatList
143+ < FlashList
131144 { ...( isScrollDirectionVertical && props . pullDown ? { onRefresh : props . pullDown } : { } ) }
132145 { ...( isScrollDirectionVertical ? { numColumns } : { } ) }
133146 ListFooterComponent = { loadMoreButton }
0 commit comments