flash-list: ListEmptyComponent can't use full height of view

Current behavior

I need to render a ListEmptyComponent which uses the full height of the current view. To make this work with react natives FlatList I can apply a contentContainerStyle with flex: 1. Sadly this won’t work with the FlashList as it doesn’t allow flex in a contentContainerStyle.

  • Why is flex not allowed for for contentContainerStyle?
  • Is there another way, to make it work with FlashList, without the usage of contentContainerStyle?

Expected behavior

There should be the possibility to render ListEmptyComponent with flex: 1 / height: "100%"

To Reproduce

Use any ListFooterComponent and try to fill the whole view with it.

Platform:

  • iOS
  • Android

Environment

"@shopify/flash-list": "1.4.3"
"react-native": "0.71.7",

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 84
  • Comments: 38

Most upvoted comments

Please refrain from “+1” comments. We all get notified. Just gives a thumbs up to the issue itself if you are affected.

Hi, we’re facing exactly the same issue. Snack: https://snack.expo.dev/@picnic-harry/flashlist-listemptycomponent-flex-repro

There are existing props for ListHeaderComponentStyle and ListFooterComponentStyle. If you don’t plan on supporting arbitrary contentContainerStyle, then a corresponding ListEmptyComponentStyle prop would fix this problem.

Folks, we’ve resolved this in FlashList v2. It does require new arch. We expect faster iterations on v2 because we don’t depend on recyclerlistview anymore.

still waiting for a solution in 2025 😕

need this please.

Similar problem here. I need to center the ListEmptyComponent. Before migrating to FlashList contentContainerStyle={{ flexGrow: 1 }} fixed the issue.

Same Issue Work around for now. Used scrollview to mimic list empty component with pull to refresh (Refresh Control).

 if (data.length === 0) {
    return (
      <EmptyView
        isFetching={isFetching}
        isLoading={isLoading}
        refetch={refetch}
      />
    );
  }
else{
return <FlashList/>

EmptyView.tsx


const EmptyView = (emptyProps: IEmptyViewProps) => {
  const { isLoading, isFetching, refetch } = emptyProps;
  return (
    <ScrollView
      contentContainerStyle={{flexGrow: 1}}
      style={styles.scrollView}
      refreshControl={
        <RefreshControl
          refreshing={isLoading || isFetching}
          onRefresh={refetch}
        />
      }>
      <View style={styles.loader}>
        <Text>
          Empty View Message
        </Text>
      </View>
    </ScrollView>
  );
};



This works perfectly! I can’t imagine why it skipped my mind. Thanks 👍

Kind of crazy that one of the most basic / requested feature if still not implement without any activity from the shopify team whatsoever.

@rKatex any plans for 2025?

Same Issue Work around for now. Used scrollview to mimic list empty component with pull to refresh (Refresh Control).

 if (data.length === 0) {
    return (
      <EmptyView
        isFetching={isFetching}
        isLoading={isLoading}
        refetch={refetch}
      />
    );
  }
else{
return <FlashList/>

EmptyView.tsx


const EmptyView = (emptyProps: IEmptyViewProps) => {
  const { isLoading, isFetching, refetch } = emptyProps;
  return (
    <ScrollView
      contentContainerStyle={{flexGrow: 1}}
      style={styles.scrollView}
      refreshControl={
        <RefreshControl
          refreshing={isLoading || isFetching}
          onRefresh={refetch}
        />
      }>
      <View style={styles.loader}>
        <Text>
          Empty View Message
        </Text>
      </View>
    </ScrollView>
  );
};



Same problem here. 😕

have you tried checking if you list data is empty then displaying the empty component manually?

Maybe it can help someone, as I workaround I did this:

<View style={{ flex: 1 }}>
    <View
      style={{
        position: "absolute",
        top: 0,
        left: 0,
        right: 0,
        bottom: 0,
        alignItems: "center",
        justifyContent: "center",
      }}
    >
      <Text>No results</Text>
    </View>
    <FlashList
      data={data}
      style={style}
      contentContainerStyle={contentContainerStyle}
      refreshControl={
        <RefreshControl
          refreshing={isFetching}
          onRefresh={refetch}
          tintColor={theme.colors.highlightDark}
        />
      }
      ItemSeparatorComponent={() => <Separator />}
      renderItem={({ item }) => (
        <Text>Hello {item}</Text>
      )}
    />
</View>

I have given up on 'em. Hopefully, Legend list reaches v1 soon.

I’m still very grateful for the library though

Then you will loose pull to refresh when list is empty 😦.

The only way i managed to solve this is by using on layout. I created a hook:

import * as React from "react";
import type { LayoutChangeEvent } from "react-native";

export  function useLayout() {
  const [layout, setLayout] = React.useState<{
    x: number;
    y: number;
    height: number;
    width: number;
    measured: boolean;
  }>({ x: 0, y: 0, height: 0, width: 0, measured: false });

  const onLayout = React.useCallback(
    (e: LayoutChangeEvent) => {
      const { height, width, x, y } = e.nativeEvent.layout;

      if (height === layout.height && width === layout.width) {
        return;
      }

      setLayout({
        x,
        y,
        height,
        width,
        measured: true,
      });
    },
    [layout.height, layout.width],
  );

  return [layout, onLayout] as const;
}

Then in the component where i use the list:

const [{ height, measured }, onLayout] = useLayout();

const renderEmptyListComponent = useMemo(() => {
  if (!measured) return null;
  return (
    <View style={{ justifyContent: "center", backgroundColor: "red", height: height }}>
      <EmptyList message="Nothing found" />
    </View>
  );
}, [measured, height]);

  <View style={styles.root}>
    <FlashList
      {...restOfProps}
      onLayout={(e) => {
        if (!measured) {
          onLayout(e);
        }
      }}
      ListEmptyComponent={renderEmptyListComponent}
    />
  </View>

So this is a workaround, the re renders caused by onLayout are minimal, cause of the useLayout hook and this measured property.

Same problem here. 😕

have you tried checking if you list data is empty then displaying the empty component manually?

It is a common use-case to allow the empty content to be centered I guess. Currently I’m re-using the estimatedListSize but it’s not alway’s perfectly centered of course.